diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2021-10-01 16:49:32 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2021-12-09 13:26:02 +0100 |
commit | d5829552b960b856bc26b6a31e102719b6539212 (patch) | |
tree | 376d7717eef803fa3f52b6c7bdc79b209165fa6d /build_scripts | |
parent | 1567f5bb52c1cb56dbe36f6865325b78a8512ed4 (diff) |
setup.py: CMake: Remove host python dependency for version parsing
When cross-compiling, the python interpreter found by CMake is the
device one (or at least it's supposed to be), which means we can't use
it to execute python scripts on the host machine to extract shiboken
and pyside version information.
Instead of keeping the version numbers in python files, place them
into new .cmake.conf files that CMake can include in CMake projects
directly. This aligns with storing version information like Qt6 does.
setup.py and coin_build_instructions need version info as well, so
they will now parse the set() assignments in pyside6/.cmake.conf.
Ideally we would have called cmake with a minimal project that outputs
those values, but we don't have access to the CMake executable path
within coin_build_instructions.py, so we rely on parsing instead.
Qt Conan integration does the same, so we should be good, the
.cmake.conf file format is unlikely to change and cause breakages.
We also modify shiboken_version.py and pyside_version.py to use the
new variables when calling configure_file(), because we still ship
those files in the wheels.
Amends b57c557c8cd1012851f8a245075591dc33be425b
Change-Id: Icc830069cd459c214ec253840ba6754ece50854e
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
(cherry picked from commit 9eb3e39486e95bce008fee9ae48df230273fa433)
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'build_scripts')
-rw-r--r-- | build_scripts/utils.py | 19 | ||||
-rw-r--r-- | build_scripts/wheel_utils.py | 17 |
2 files changed, 29 insertions, 7 deletions
diff --git a/build_scripts/utils.py b/build_scripts/utils.py index 4b91bd493..d5cfd8d67 100644 --- a/build_scripts/utils.py +++ b/build_scripts/utils.py @@ -1228,3 +1228,22 @@ def get_ci_qmake_path(ci_install_dir, ci_host_os): return f"{qmake_path}\\bin\\qmake.exe" else: return f"{qmake_path}/bin/qmake" + + +def parse_cmake_conf_assignments_by_key(source_dir): + """ + Parses a .cmake.conf file that contains set(foo "bar") assignments + and returns a dict with those assignments transformed to keys and + values. + """ + + d = {} + contents = (Path(source_dir) / ".cmake.conf").read_text() + matches = re.findall(r'set\((.+?) "(.*?)"\)', contents) + for m in matches: + key = m[0] + value = m[1] + if key and value: + d[key] = value + return d + diff --git a/build_scripts/wheel_utils.py b/build_scripts/wheel_utils.py index 4cea2a83f..bfff47f04 100644 --- a/build_scripts/wheel_utils.py +++ b/build_scripts/wheel_utils.py @@ -46,7 +46,7 @@ from packaging.version import parse as parse_version from .options import OPTION from .qtinfo import QtInfo -from .utils import memoize, get_python_dict +from .utils import memoize, parse_cmake_conf_assignments_by_key from .versions import PYSIDE @@ -78,12 +78,15 @@ def get_qt_version(): def get_package_version(): """ Returns the version string for the PySide6 package. """ setup_script_dir = os.getcwd() - pyside_version_py = os.path.join( - setup_script_dir, "sources", PYSIDE, "pyside_version.py") - d = get_python_dict(pyside_version_py) - final_version = f"{d['major_version']}.{d['minor_version']}.{d['patch_version']}" - release_version_type = d['release_version_type'] - pre_release_version = d['pre_release_version'] + pyside_project_dir = os.path.join(setup_script_dir, "sources", PYSIDE) + d = parse_cmake_conf_assignments_by_key(pyside_project_dir) + major_version = d['pyside_MAJOR_VERSION'] + minor_version = d['pyside_MINOR_VERSION'] + patch_version = d['pyside_MICRO_VERSION'] + + final_version = f"{major_version}.{minor_version}.{patch_version}" + release_version_type = d['pyside_PRE_RELEASE_VERSION_TYPE'] + pre_release_version = d['pyside_PRE_RELEASE_VERSION'] if pre_release_version and release_version_type: final_version = f"{final_version}{release_version_type}{pre_release_version}" |