From 9afacb4bbbf8679cdf422794bbdfebf573f69e70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Rinc=C3=B3n=20Blanco?= Date: Fri, 15 Dec 2023 11:32:21 +0100 Subject: [PATCH] Add different ref tracking syntax for `` (#15274) * Use light=True where possible in build_requires tests * Sketch for allowing tracking of different ref * Add remote input to build-map command * Update conans/client/graph/graph_builder.py Co-authored-by: James * Update conans/client/graph/graph_builder.py Co-authored-by: James * Update conans/client/graph/graph_builder.py Co-authored-by: James * Fix tests --------- Co-authored-by: James --- conans/client/graph/graph_builder.py | 14 +++++++++--- .../build_requires/build_requires_test.py | 22 +++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/conans/client/graph/graph_builder.py b/conans/client/graph/graph_builder.py index 27d8449d82c..f4c0693e16a 100644 --- a/conans/client/graph/graph_builder.py +++ b/conans/client/graph/graph_builder.py @@ -1,5 +1,6 @@ import copy import os +import re from collections import deque from conans.client.conanfile.configure import run_configure_method @@ -13,6 +14,7 @@ from conans.errors import ConanException from conans.model.conan_file import ConanFile from conans.model.options import Options +from conans.model.package_ref import PkgReference from conans.model.recipe_ref import RecipeReference, ref_matches from conans.model.requires import Requirement @@ -270,14 +272,20 @@ def _resolve_replace_requires(self, node, require, profile_build, profile_host, break # First match executes the alternative and finishes checking others def _create_new_node(self, node, require, graph, profile_host, profile_build, graph_lock): - if require.ref.version == "": + require_version = str(require.ref.version) + if require_version.startswith(""): if not require.build or require.visible: raise ConanException(f"{node.ref} require '{require.ref}': 'host_version' can only " "be used for non-visible tool_requires") - req = Requirement(require.ref, headers=True, libs=True, visible=True) + tracking_ref = require_version.split(':', 1) + ref = require.ref + if len(tracking_ref) > 1: + ref = RecipeReference.loads(str(node.ref)) + ref.name = tracking_ref[1][:-1] # Remove the trailing > + req = Requirement(ref, headers=True, libs=True, visible=True) transitive = node.transitive_deps.get(req) if transitive is None: - raise ConanException(f"{node.ref} require '{require.ref}': didn't find a matching " + raise ConanException(f"{node.ref} require '{ref}': didn't find a matching " "host dependency") require.ref.version = transitive.require.ref.version diff --git a/conans/test/integration/build_requires/build_requires_test.py b/conans/test/integration/build_requires/build_requires_test.py index 2f09809a6fe..229fd7a5806 100644 --- a/conans/test/integration/build_requires/build_requires_test.py +++ b/conans/test/integration/build_requires/build_requires_test.py @@ -512,6 +512,28 @@ def test_overriden_host_version_transitive_deps(self): c.run("install app --lockfile=app/conan.lock") c.assert_listed_require({"protobuf/1.1": "Cache"}, build=True) + @pytest.mark.parametrize("host_version, assert_error, assert_msg", [ + ("libgettext>", False, "gettext/0.2#d9f9eaeac9b6e403b271f04e04149df2"), + # Error cases, just checking that we fail gracefully - no tracebacks + ("libgettext", True, "Package 'gettext/", True, "app/1.0 require ':/1.0': didn't find a matching host dependency"), + (">", True, "app/1.0 require '/1.0': didn't find a matching host dependency"), + (":", True, " Package 'gettext/0.1]") + .with_tool_requirement(f"gettext/