From d5b9bb1a6ca78359c250923ca6d91ede45336661 Mon Sep 17 00:00:00 2001 From: memsharded Date: Sat, 1 Sep 2018 18:34:46 +0200 Subject: [PATCH 1/2] resolve alias earlier so they are not overridden --- conans/client/graph/graph_builder.py | 11 ++++++++--- conans/test/integration/alias_test.py | 25 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/conans/client/graph/graph_builder.py b/conans/client/graph/graph_builder.py index 1b2f169c8b7..30bfdf475d8 100644 --- a/conans/client/graph/graph_builder.py +++ b/conans/client/graph/graph_builder.py @@ -76,7 +76,7 @@ def _load_deps(self, node, down_reqs, dep_graph, public_deps, down_ref, down_opt param down_ref: ConanFileReference of who is depending on current node for this expansion """ # basic node configuration - new_reqs, new_options = self._config_node(node, down_reqs, down_ref, down_options) + new_reqs, new_options = self._config_node(node, down_reqs, down_ref, down_options, aliased) self._resolve_deps(node, aliased, update, remote_name) @@ -139,7 +139,7 @@ def _recurse(self, closure, new_reqs, new_options): return True return False - def _config_node(self, node, down_reqs, down_ref, down_options): + def _config_node(self, node, down_reqs, down_ref, down_options, aliased): """ update settings and option in the current ConanFile, computing actual requirement values, cause they can be overridden by downstream requires param settings: dict of settings values => {"os": "windows"} @@ -186,7 +186,12 @@ def _config_node(self, node, down_reqs, down_ref, down_options): conanfile.requirements() new_options = conanfile.options.deps_package_values - new_down_reqs = conanfile.requires.update(down_reqs, self._output, conanref, down_ref) + if aliased: + for req in conanfile.requires.values(): + req.conan_reference = aliased.get(req.conan_reference, + req.conan_reference) + new_down_reqs = conanfile.requires.update(down_reqs, self._output, + conanref, down_ref) except ConanExceptionInUserConanfileMethod: raise except ConanException as e: diff --git a/conans/test/integration/alias_test.py b/conans/test/integration/alias_test.py index 0f28faf3ec9..8cf03412d34 100644 --- a/conans/test/integration/alias_test.py +++ b/conans/test/integration/alias_test.py @@ -8,6 +8,31 @@ class ConanAliasTest(unittest.TestCase): + def alias_overriden_test(self): + # https://github.com/conan-io/conan/issues/3353 + client = TestClient() + conanfile = """from conans import ConanFile +class Pkg(ConanFile): + pass +""" + client.save({"conanfile.py": conanfile}) + client.run("export . PkgA/0.1@user/testing") + client.run("alias PkgA/latest@user/testing PkgA/0.1@user/testing") + conanfile = """from conans import ConanFile +class Pkg(ConanFile): + requires = "PkgA/latest@user/testing" +""" + client.save({"conanfile.py": conanfile}) + client.run("export . PkgB/0.1@user/testing") + client.run("alias PkgB/latest@user/testing PkgB/0.1@user/testing") + conanfile = """from conans import ConanFile +class Pkg(ConanFile): + requires = "PkgA/latest@user/testing", "PkgB/latest@user/testing" +""" + client.save({"conanfile.py": conanfile}) + client.run("info .") + self.assertNotIn("overridden", client.out) + def test_alias_different_name(self): client = TestClient() error = client.run("alias myalias/1.0@user/channel lib/1.0@user/channel", From dcad11ecff07b840ea6fd091e7667fc98411882e Mon Sep 17 00:00:00 2001 From: memsharded Date: Sat, 1 Sep 2018 18:36:19 +0200 Subject: [PATCH 2/2] minor style --- conans/client/graph/graph_builder.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/conans/client/graph/graph_builder.py b/conans/client/graph/graph_builder.py index 30bfdf475d8..409458a0ce3 100644 --- a/conans/client/graph/graph_builder.py +++ b/conans/client/graph/graph_builder.py @@ -3,7 +3,8 @@ from conans.model.conan_file import get_env_context_manager from conans.model.requires import Requirements from conans.model.ref import ConanFileReference -from conans.errors import ConanException, conanfile_exception_formatter, ConanExceptionInUserConanfileMethod +from conans.errors import (ConanException, conanfile_exception_formatter, + ConanExceptionInUserConanfileMethod) from conans.client.output import ScopedOutput from conans.util.log import logger from conans.client.graph.graph import DepsGraph, Node, RECIPE_WORKSPACE @@ -33,7 +34,8 @@ def load_graph(self, conanfile, check_updates, update, remote_name, processed_pr t1 = time.time() loop_ancestors = [] self._load_deps(root_node, Requirements(), dep_graph, public_deps, None, None, - loop_ancestors, aliased, check_updates, update, remote_name, processed_profile) + loop_ancestors, aliased, check_updates, update, remote_name, + processed_profile) logger.debug("Deps-builder: Time to load deps %s" % (time.time() - t1)) t1 = time.time() dep_graph.compute_package_ids() @@ -216,8 +218,8 @@ def _create_new_node(self, current_node, dep_graph, requirement, public_deps, na check_updates, update, remote_name, self._recorder) except ConanException as e: base_ref = str(current_node.conan_ref or "PROJECT") - self._output.error("Failed requirement '%s' from '%s'" % (requirement.conan_reference, - base_ref)) + self._output.error("Failed requirement '%s' from '%s'" + % (requirement.conan_reference, base_ref)) raise e conanfile_path, recipe_status, remote, _ = result