From 6522f3abcaa4d0f58c07c6efad225795a958be73 Mon Sep 17 00:00:00 2001 From: Ivan Komissarov Date: Fri, 7 Jun 2024 11:45:58 +0300 Subject: [PATCH 1/2] qbs: add explicit resolve method Most tools have a separate configuration step and Qbs is no different. It's strange that the API doesn't provide a separate method for this. Add it now so that users can understand better what went wrong during which stage. --- conan/internal/api/new/qbs_lib.py | 2 ++ conan/tools/qbs/qbs.py | 31 ++++++++++++++++++---- test/functional/toolchains/qbs/test_qbs.py | 3 +++ 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/conan/internal/api/new/qbs_lib.py b/conan/internal/api/new/qbs_lib.py index 7af4b071dd5..a933b5435c4 100644 --- a/conan/internal/api/new/qbs_lib.py +++ b/conan/internal/api/new/qbs_lib.py @@ -21,6 +21,7 @@ def build(self): qbs = Qbs(self) qbs_config = {"products.{{name}}.isShared": "true" if self.options.shared else "false"} qbs.add_configuration("default", qbs_config) + qbs.resolve() qbs.build() def package(self): @@ -67,6 +68,7 @@ def requirements(self): def build(self): qbs = Qbs(self) + qbs.resolve() qbs.build() qbs.install() diff --git a/conan/tools/qbs/qbs.py b/conan/tools/qbs/qbs.py index be3f8ebac53..cca62c9cea9 100644 --- a/conan/tools/qbs/qbs.py +++ b/conan/tools/qbs/qbs.py @@ -25,6 +25,7 @@ def __init__(self, conanfile, project_file=None): self._set_project_file(project_file) self.jobs = build_jobs(conanfile) self._configuration = dict() + self._resolved = False def _set_project_file(self, project_file): if not project_file: @@ -44,7 +45,31 @@ def _get_common_arguments(self): '--file', self._project_file, ] + def resolve(self, parallel=True): + args = self._get_common_arguments() + + if parallel: + args.extend(['--jobs', '%s' % self.jobs]) + else: + args.extend(['--jobs', '1']) + + if self.profile: + args.append('profile:%s' % self.profile) + + for name in self._configuration: + config = self._configuration[name] + args.extend(_configuration_dict_to_commandlist(name, config)) + + cmd = 'qbs resolve %s' % cmd_args_to_string(args) + self._conanfile.run(cmd) + + self._resolved = True + def _build(self, products, all_products): + # for backward compatibility when there was only build() + if not self._resolved: + self.resolve() + args = self._get_common_arguments() args.append('--no-install') @@ -55,12 +80,8 @@ def _build(self, products, all_products): args.extend(['--jobs', '%s' % self.jobs]) - if self.profile: - args.append('profile:%s' % self.profile) - for name in self._configuration: - config = self._configuration[name] - args.extend(_configuration_dict_to_commandlist(name, config)) + args.append('config:%s' % name) cmd = 'qbs build %s' % cmd_args_to_string(args) self._conanfile.run(cmd) diff --git a/test/functional/toolchains/qbs/test_qbs.py b/test/functional/toolchains/qbs/test_qbs.py index 3bb0ea338ae..52ea8063579 100644 --- a/test/functional/toolchains/qbs/test_qbs.py +++ b/test/functional/toolchains/qbs/test_qbs.py @@ -50,6 +50,7 @@ class Recipe(ConanFile): def build(self): qbs = Qbs(self) + qbs.resolve() qbs.build_all() ''') @@ -89,6 +90,7 @@ class Recipe(ConanFile): def build(self): qbs = Qbs(self) + qbs.resolve() qbs.build(products=["hello", "hello"]) ''') @@ -130,6 +132,7 @@ def build(self): qbs = Qbs(self) qbs.add_configuration("release", {"qbs.debugInformation": False}) qbs.add_configuration("debug", {"qbs.debugInformation": True}) + qbs.resolve() qbs.build() ''') From 73296ff0605ddcfe9d19bc623f14059981cac451 Mon Sep 17 00:00:00 2001 From: Ivan Komissarov Date: Wed, 12 Jun 2024 12:56:05 +0300 Subject: [PATCH 2/2] remove fallback --- conan/tools/qbs/qbs.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/conan/tools/qbs/qbs.py b/conan/tools/qbs/qbs.py index cca62c9cea9..b6159e2bc7a 100644 --- a/conan/tools/qbs/qbs.py +++ b/conan/tools/qbs/qbs.py @@ -25,7 +25,6 @@ def __init__(self, conanfile, project_file=None): self._set_project_file(project_file) self.jobs = build_jobs(conanfile) self._configuration = dict() - self._resolved = False def _set_project_file(self, project_file): if not project_file: @@ -63,12 +62,7 @@ def resolve(self, parallel=True): cmd = 'qbs resolve %s' % cmd_args_to_string(args) self._conanfile.run(cmd) - self._resolved = True - def _build(self, products, all_products): - # for backward compatibility when there was only build() - if not self._resolved: - self.resolve() args = self._get_common_arguments() args.append('--no-install')