From 72530f8958ea91fe25c47f5797e90c60e8a61bfc Mon Sep 17 00:00:00 2001 From: Chris Reed Date: Mon, 21 Feb 2022 17:26:31 -0600 Subject: [PATCH 1/3] setup.py: switch to out of tree builds. libusb 1.0.25 added support for out of tree builds. Removed no longer needed run of 'make clean' for posix builds. Updated readme. --- README.md | 6 +++--- setup.py | 11 ++++------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 3147ec0..1c6b1a3 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,8 @@ if available. You can also install from a clone of the git repository by running `pip install .` from the repository root directory. Editable installs are supported. Please note that running `setup.py` directly is no longer supported for PEP 517 -compliant packages. When building from the repo, because libusb 1.0.24 does not support out of tree builds, the build is -done in-place in the `src/libusb` directory. `make clean` is run before compiling to ensure a clean build. +compliant packages. Building libusb is done out of tree in an automatically created build directory for libusb 1.0.25 +and later. ## APIs @@ -42,7 +42,7 @@ There are four public functions exported by `libusb_package`. - `find(*args, **kwargs)`: Wrapper around pyusb's `usb.core.find()` that sets the `backend` parameter to a libusb1 backend created from the libusb library included in `libusb_package`. - All other parameters are passed unmodified + All other parameters are passed unmodified. - `get_libusb1_backend()`: Returns a `pyusb` backend object for the libusb version contained in `libusb_package`. diff --git a/setup.py b/setup.py index ee55db3..95bd474 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Chris Reed +# Copyright (c) 2021-2022 Chris Reed # Copyright (c) 2022 Mitchell Kline # # SPDX-License-Identifier: Apache-2.0 @@ -97,12 +97,10 @@ def run(self): build_lib = ROOT_DIR / Path(build_py.get_package_dir(PACKAGE_NAME)).parent else: build_lib = Path(os.path.abspath(self.build_lib)) -# build_temp = Path(os.path.abspath(self.build_temp)) - # Build in-tree for the time being. libusb commit 1001cb5 adds support for out of tree builds, but - # this is not yet supported in an existing release. Once libusb version 1.0.25 is released, we can - # build out of tree. - build_temp = LIBUSB_DIR + # Build out of tree. Requires libusb commit 1001cb5 which adds support for out of tree builds, present + # in libusb 1.0.25 and later. + build_temp = Path(os.path.abspath(self.build_temp)) print(f"build_temp = {build_temp}") print(f"build_lib = {build_lib}") @@ -156,7 +154,6 @@ def run(self): self.spawn(['env']) # Dump environment for debugging purposes. self.spawn(['bash', str(BOOTSTRAP_SCRIPT)]) self.spawn(['bash', str(CONFIGURE_SCRIPT), *extra_configure_args]) - self.spawn(['make', 'clean']) self.spawn(['make', f'-j{os.cpu_count() or 4}', 'all']) except Exception as err: # Exception is caught here and reraised as our specific Exception class because the actual From 1692df8ce18ceaba32bd64ebffbf39508ec94a5f Mon Sep 17 00:00:00 2001 From: Chris Reed Date: Tue, 1 Mar 2022 09:39:56 -0600 Subject: [PATCH 2/3] scripts: vsenv.bat: move comment about source after echo off. --- scripts/vsenv.bat | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/vsenv.bat b/scripts/vsenv.bat index 74e32ea..6c5d0ec 100644 --- a/scripts/vsenv.bat +++ b/scripts/vsenv.bat @@ -1,7 +1,7 @@ -rem From: https://renenyffenegger.ch/notes/development/tools/scripts/personal/vsenv_bat - @echo off +rem From: https://renenyffenegger.ch/notes/development/tools/scripts/personal/vsenv_bat + rem rem Uncomment setting VSCMD_DEBUG to enable debugging to output rem From 84c03cf4c46169a5fd3f95219372ee32b2cf6801 Mon Sep 17 00:00:00 2001 From: Chris Reed Date: Wed, 2 Mar 2022 13:59:38 -0600 Subject: [PATCH 3/3] setup.py: fix out of tree builds on Windows [wip] --- setup.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 95bd474..c3108ac 100644 --- a/setup.py +++ b/setup.py @@ -175,10 +175,20 @@ def run(self): else: platform = "x64" if IS_64_BIT else "x86" config = "Release" + properties = { + "Configuration": config, + "Platform": platform, + "IntermediateOutputPath": str(build_temp / platform / "obj") + "\\", # Must end with trailing slash. + "OutDir": str(build_temp / platform / config) + "\\", + #IntermediateOutputPath + #OutputPath + } + + property_values = ';'.join(f'{k}={v}' for k, v in properties.items()) + msbuild_cmd = f'msbuild -p:{property_values} {VS_PROJ}' try: - self.spawn(['cmd.exe', '/c', f'{VSENV_SCRIPT} && ' - f'msbuild -p:Configuration={config} -p:Platform={platform} {VS_PROJ}']) + self.spawn(['cmd.exe', '/c', f'{VSENV_SCRIPT} && {msbuild_cmd}']) except Exception as err: # See comment above for notes about this exception handler. raise LibusbBuildError(str(err)) from err