diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2021-09-29 16:41:50 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-10-27 16:36:49 +0000 |
commit | 6debf9108bcf32d951d9dc8d9bb00ef1c24d7da0 (patch) | |
tree | 8f380486a69308a51fc5a726440272e420e77358 /build_scripts | |
parent | 41d23386cbf50f1c8718ab8a0af787c109670bba (diff) |
setup.py: Allow specifying Qt without adding it to PATH
Fix setup.py to allow specifying Qt either via --qtpaths or --qmake
options.
Previously if only one of the options were provided, the build would
fail saying that the other option was not provided.
Instead, only fail if neither options were provided.
Reconstruct the path to the missing tool based on the path of the one
that was provided.
Prefer qtpaths, because the qmake option is deprecated.
Even if both --qtpaths and --qmake options were provided to setup.py,
the build would still fail when running _get_cmake_mkspecs_variables
because it couldn't find a Qt package.
The CMake project that is configured in that function depended on
PATH being set to Qt's prefix, which CMake's find_package would then
pick up.
Explicitly pass the Qt prefix via CMAKE_PREFIX_PATH when configuring
the project.
Change-Id: Ibd0cb35f8902e3d795c308c9c755a342118b0848
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
(cherry picked from commit 3b4764fefbb349eafb831b5da90f565b34c77a52)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'build_scripts')
-rw-r--r-- | build_scripts/options.py | 46 | ||||
-rw-r--r-- | build_scripts/qtinfo.py | 3 |
2 files changed, 38 insertions, 11 deletions
diff --git a/build_scripts/options.py b/build_scripts/options.py index 58673c1ea..46db56ddc 100644 --- a/build_scripts/options.py +++ b/build_scripts/options.py @@ -42,6 +42,7 @@ from distutils.spawn import find_executable import sys import os import warnings +from pathlib import Path from .qtinfo import QtInfo @@ -298,12 +299,16 @@ class DistUtilsCommandMixin(object): OPTION['SHORTER_PATHS'] = self.shorter_paths OPTION['DOC_BUILD_ONLINE'] = self.doc_build_online - qtpaths_abs_path = os.path.abspath(self.qtpaths) - OPTION['QTPATHS'] = qtpaths_abs_path + qtpaths_abs_path = '' + if self.qtpaths: + qtpaths_abs_path = os.path.abspath(self.qtpaths) + OPTION['QTPATHS'] = qtpaths_abs_path # FIXME PYSIDE7: Remove qmake handling # make qtinfo.py independent of relative paths. - qmake_abs_path = os.path.abspath(self.qmake) - OPTION['QMAKE'] = qmake_abs_path + qmake_abs_path = '' + if self.qmake: + qmake_abs_path = os.path.abspath(self.qmake) + OPTION['QMAKE'] = qmake_abs_path OPTION['HAS_QMAKE_OPTION'] = self.has_qmake_option OPTION['QT_VERSION'] = self.qt QtInfo().setup(qtpaths_abs_path, self.cmake, qmake_abs_path, @@ -337,23 +342,42 @@ class DistUtilsCommandMixin(object): if not self.qtpaths: self.qtpaths = find_executable("qtpaths") if not self.qtpaths: - log.error("qtpaths could not be found.") - return False - if not os.path.exists(self.qtpaths): - log.error(f"'{self.qtpaths}' does not exist.") - return False + self.qtpaths = find_executable("qtpaths6") if self.qmake: self.has_qmake_option = True else: self.qmake = find_executable("qmake") if not self.qmake: + self.qmake = find_executable("qmake6") + if not self.qmake: self.qmake = find_executable("qmake-qt5") + + if not self.qtpaths and not self.qmake: + log.error("No value provided to --qtpaths option. Please provide one to find Qt.") + return False + + # Derive tool path from the option that is not empty. if not self.qmake: - log.error("qmake could not be found.") + base_dir = Path(self.qtpaths).parent + self.qmake = os.fspath(base_dir / "qmake") + if not os.path.exists(self.qmake): + self.qmake = os.fspath(base_dir / "qmake6") + if not os.path.exists(self.qmake): + self.qmake = os.fspath(base_dir / "qmake-qt5") + + if not self.qtpaths: + base_dir = Path(self.qmake).parent + self.qtpaths = os.fspath(base_dir / "qtpaths") + if not os.path.exists(self.qtpaths): + self.qtpaths = os.fspath(base_dir / "qtpaths6") + + if not os.path.exists(self.qtpaths): + log.error(f"Provided '{self.qtpaths}' path does not exist.") return False + if not os.path.exists(self.qmake): - log.error(f"'{self.qmake}' does not exist.") + log.error(f"Provided '{self.qmake}' path does not exist.") return False if not self.make_spec: diff --git a/build_scripts/qtinfo.py b/build_scripts/qtinfo.py index 4fdc77d7f..843310f6b 100644 --- a/build_scripts/qtinfo.py +++ b/build_scripts/qtinfo.py @@ -254,6 +254,9 @@ class QtInfo(object): cmake_list_file = Path(tempdir) / 'CMakeLists.txt' cmake_list_file.write_text(_CMAKE_LISTS) cmd = [self._cmake_command, '-G', 'Ninja', '.'] + qt_prefix = self.prefix_dir + cmd.extend([f'-DCMAKE_PREFIX_PATH={qt_prefix}']) + # FIXME Python 3.7: Use subprocess.run() proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=False, cwd=tempdir, universal_newlines=True) |