From 3800ec1cc41789debee91a5a7889b5bb00190b17 Mon Sep 17 00:00:00 2001 From: Iikka Eklund Date: Tue, 21 Jun 2022 12:13:34 +0300 Subject: [PATCH] Conan: Do not force 'qt_host_path' usage in cross-build context If the user does not pass: -o qtbase:qt_host_path=/foo then log a warning but allow to continue. For example Boot2Qt integration resolves the 'QT_HOST_PATH' by other means thus making it a mandatory option to be passed by the user should not be needed. Change-Id: I4c1d8b5253e33466ccdf463f89473966e90c0e0c Reviewed-by: Alexandru Croitor Reviewed-by: Toni Saario (cherry picked from commit 5271f5082cd5413c618fc464fbeea6529626838b) Reviewed-by: Qt Cherry-pick Bot --- conanfile.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/conanfile.py b/conanfile.py index 1b05a9628c4..bbabf0e8933 100644 --- a/conanfile.py +++ b/conanfile.py @@ -33,7 +33,7 @@ import re import shutil from functools import lru_cache from pathlib import Path -from typing import Dict +from typing import Dict, Union class QtConanError(Exception): @@ -153,13 +153,22 @@ class QtBase(ConanFile): print("Setting 3rd party package requirement: {0}".format(requirement)) self.requires(requirement) - def _resolve_qt_host_path(self) -> str: - # When cross-building the user needs to pass 'qt_host_path' which is transformed to - # QT_HOST_PATH later on. Resolve the exact path. - qt_host_path = self.options.get_safe("qt_host_path") - if not qt_host_path: - raise QtConanError("Expected 'qt_host_path' option in cross-build context") - return str(Path(os.path.expandvars(str(qt_host_path))).expanduser().resolve(strict=True)) + def _resolve_qt_host_path(self) -> Union[str, None]: + """ + Attempt to resolve QT_HOST_PATH. + + When cross-building the user needs to pass 'qt_host_path' which is transformed to + QT_HOST_PATH later on. Resolve the exact path if possible. + + Returns: + string: The resolved QT_HOST_PATH or None if unable to determine it. + """ + _host_p = self.options.get_safe("qt_host_path") + if _host_p: + return str(Path(os.path.expandvars(str(_host_p))).expanduser().resolve(strict=True)) + else: + print("Warning: 'qt_host_path' option was not given in cross-build context") + return None def configure(self): if self.settings.compiler == "gcc" and tools.Version(self.settings.compiler.version) < "8": @@ -274,7 +283,9 @@ class QtBase(ConanFile): def package_info(self): self._shared.package_info(self) if tools.cross_building(conanfile=self): - self.env_info.QT_HOST_PATH.append(self._resolve_qt_host_path()) + qt_host_path = self._resolve_qt_host_path() + if qt_host_path: + self.env_info.QT_HOST_PATH.append(qt_host_path) def package_id(self): # https://docs.conan.io/en/latest/creating_packages/define_abi_compatibility.html