aboutsummaryrefslogtreecommitdiffstats
path: root/build_scripts
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2021-09-30 17:25:36 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2021-10-27 16:22:34 +0200
commit234349d124ccfa399921e2b9fc09addcff0b0a94 (patch)
tree21580e62a1518ae4ff5769a75da51314d0e1a78d /build_scripts
parent6b0a8254f589495bf153773271669737408a53af (diff)
setup.py: Move all build dirs into a common 'build' subdirectory
When building the project using setup.py, it would pollute the source directory with a lot of virtual environment build directories Move all of those into a common 'build' subdirectory. This eases cleanup of all build directories because they can all be removed with a single rm command. It also places all the various stages of build -> install -> package folders into a common subdirectory so it's easier to find and navigate between them. Example of the new build directory structure build/py3venv/py3.7-qt6.2.0-64bit-release/build/shiboken6 build/py3venv/py3.7-qt6.2.0-64bit-release/build/pyside6 build/py3venv/py3.7-qt6.2.0-64bit-release/install/bin/shiboken6 build/py3venv/py3.7-qt6.2.0-64bit-release/package-lib.macosx-10.14-x86_64-3.7 The last 'package-xyz' subfolder will have its name shortened if the SHORTER_PATHS option is enabled, to avoid path limits on Windows. If no virtualenv is used, change the dir prefix from the previous 'pyside' one to 'qfp' because it's shorter and it's also less confusing that there are both shiboken and pyside subfolders inside 'qfp'. Move the code that always removed the ./build directory on each setup.py invocation into prepare_packages() instead. This way it only removes the files from the 'package' subfolder which is the common packaging location between all the sub-projects. This removal is needed to ensure shiboken files don't end up packaged in the PySide6 wheel. TODO: One more improvement would be to move the bdist_dir and bdist_wheel dirs into the same common subdirectory. This is a bit more complicated to do because it requires computation of the common subfolder and its dependencies in finalize_options of both the 'build' and 'bdist' stages. [ChangeLog][setup.py] Build directories are now created inside the root ./build directory, rather than directly under the root of the project. Pick-to: 6.2 Change-Id: Ie8c0dc27e5067acc9809b9cefaef6be66c76f9dd Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'build_scripts')
-rw-r--r--build_scripts/main.py76
1 files changed, 55 insertions, 21 deletions
diff --git a/build_scripts/main.py b/build_scripts/main.py
index 887e8e293..142423355 100644
--- a/build_scripts/main.py
+++ b/build_scripts/main.py
@@ -260,7 +260,7 @@ def prefix():
if virtual_env_name is not None:
name = os.path.basename(virtual_env_name)
else:
- name = "pyside"
+ name = "qfp"
name += str(sys.version_info[0])
if OPTION["DEBUG"]:
name += "d"
@@ -309,17 +309,6 @@ def prepare_sub_modules():
def prepare_build():
- # Clean up temp build folder.
- for n in ["build"]:
- d = os.path.join(setup_script_dir, n)
- if os.path.isdir(d):
- log.info(f"Removing {d}")
- try:
- rmtree(d)
- except Exception as e:
- log.warn(f'***** problem removing "{d}"')
- log.warn(f'ignored error: {e}')
-
# locate Qt sources for the documentation
if OPTION["QT_SRC"] is None:
install_prefix = QtInfo().prefix_dir
@@ -413,8 +402,9 @@ class PysideInstallLib(_install_lib):
def install(self):
"""
- Installs files from build/xxx directory into final
- site-packages/PySide6 directory.
+ Installs files from self.build_dir directory into final
+ site-packages/PySide6 directory when the command is 'install
+ or into build/wheel when command is 'bdist_wheel'.
"""
if os.path.isdir(self.build_dir):
@@ -537,8 +527,39 @@ class PysideBuild(_build, DistUtilsCommandMixin):
script_dir = setup_script_dir
sources_dir = os.path.join(script_dir, "sources")
- build_dir = os.path.join(script_dir, f"{prefix()}_build", f"{build_name}")
- install_dir = os.path.join(script_dir, f"{prefix()}_install", f"{build_name}")
+ build_base = self.build_base
+ venv_prefix = prefix()
+ build_dir = os.path.join(script_dir, build_base, venv_prefix, build_name, "build")
+ install_dir = os.path.join(script_dir, build_base, venv_prefix, build_name, "install")
+ setup_tools_build_lib_dir = self.build_lib
+
+ # If setuptools' build_lib was not specified manually (so its
+ # value was auto-computed which we check by the equality in the
+ # condition), change its location to the same directory where
+ # the cmake build and install dirs are so there's
+ # a common subdirectory for all build-related directories.
+ # Example:
+ # Replaces
+ # build/lib.macosx-10.14-x86_64-3.7' with
+ # build/py3_mac_qt6_2_03/package-lib.macosx-10.14-x86_64-3.7'
+ # TODO: Do the same for bdist_dir / bdist_wheel. This will
+ # require moving the options to be computed in finalize_options.
+ if self.build_lib == self.build_platlib:
+ if OPTION["SHORTER_PATHS"]:
+ # Keep it shorter without the build_platlib suffix.
+ setup_tools_build_lib_dir = os.path.join(build_base,
+ venv_prefix,
+ build_name,
+ "package")
+ else:
+ build_platlib = self.build_platlib
+ if build_platlib.startswith(build_base):
+ build_platlib = os.path.basename(build_platlib)
+ setup_tools_build_lib_dir = os.path.join(build_base,
+ venv_prefix,
+ build_name,
+ f"package-{build_platlib}")
+ self.build_lib = setup_tools_build_lib_dir
self.make_path = make_path
self.make_generator = make_generator
@@ -627,14 +648,14 @@ class PysideBuild(_build, DistUtilsCommandMixin):
log.info(dedent(f"""
Building {config.package_name()} will create and touch directories
in the following order:
- make build directory (py*_build/*/*) ->
- make install directory (py*_install/*/*) ->
- setuptools build directory (build/*/*) ->
+ make build directory ->
+ make install directory ->
+ setuptools build directory ->
setuptools install directory
(usually path-installed-python/lib/python*/site-packages/*)
"""))
- log.info(f"make build directory: {self.build_dir}")
- log.info(f"make install directory: {self.install_dir}")
+ log.info(f"make build directory: {self.build_dir}")
+ log.info(f"make install directory: {self.install_dir}")
log.info(f"setuptools build directory: {self.st_build_dir}")
log.info(f"setuptools install directory: {setuptools_install_prefix}")
log.info(dedent(f"""
@@ -981,6 +1002,19 @@ class PysideBuild(_build, DistUtilsCommandMixin):
os.chdir(self.script_dir)
+ # Clean up the previous st_build_dir before files are copied
+ # into it again. That's the because the same dir is used
+ # when copying the files for each of the sub-projects and
+ # we don't want to accidentally install shiboken files
+ # as part of pyside-tools package.
+ if os.path.isdir(self.st_build_dir):
+ log.info(f"Removing {self.st_build_dir}")
+ try:
+ rmtree(self.st_build_dir)
+ except Exception as e:
+ log.warn(f'***** problem removing "{self.st_build_dir}"')
+ log.warn(f'ignored error: {e}')
+
if sys.platform == "win32":
vars['dbg_postfix'] = OPTION["DEBUG"] and "_d" or ""
return prepare_packages_win32(self, vars)