Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

explore replace_requires references adjustements #16443

Draft
wants to merge 1 commit into
base: develop2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions conans/client/graph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def __init__(self, ref, conanfile, context, recipe=None, path=None, test=False):
self.should_build = False # If the --build or policy wants to build this binary
self.build_allowed = False
self.is_conf = False
self.replaced_requires = {} # To track the replaced requires for self.dependencies[old-ref]

def __lt__(self, other):
"""
Expand Down
1 change: 1 addition & 0 deletions conans/client/graph/graph_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ def _resolve_replace_requires(self, node, require, profile_build, profile_host,
node.conanfile.requires.reindex(require, alternative_ref.name)
require.ref.name = alternative_ref.name
graph.replaced_requires[original_require] = repr(require.ref)
node.replaced_requires[original_require] = require
break # First match executes the alternative and finishes checking others

def _create_new_node(self, node, require, graph, profile_host, profile_build, graph_lock):
Expand Down
6 changes: 6 additions & 0 deletions conans/model/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ class ConanFileDependencies(UserRequirementsDict):
def from_node(node):
d = OrderedDict((require, ConanFileInterface(transitive.node.conanfile))
for require, transitive in node.transitive_deps.items())
for old_req, new_req in node.replaced_requires.items():
existing = d.get(new_req)
if existing is not None:
added_req = new_req.copy_requirement()
added_req.ref = RecipeReference.loads(old_req)
d[added_req] = existing
return ConanFileDependencies(d)

def filter(self, require_filter, remove_system=True):
Expand Down
34 changes: 34 additions & 0 deletions test/integration/graph/test_replace_requires.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import textwrap

import pytest

Expand Down Expand Up @@ -147,3 +148,36 @@ def test_replace_requires_json_format():
assert "pkg/0.1: pkg/0.2" in c.out # The replacement happens
graph = json.loads(c.stdout)
assert graph["graph"]["replaced_requires"] == {"pkg/0.1": "pkg/0.2"}


def test_replace_requires_consumer_references():
c = TestClient(light=True)
conanfile = textwrap.dedent("""
from conan import ConanFile
class App(ConanFile):
name = "app"
version = "0.1"
requires = "zlib/0.1"
def generate(self):
assert self.dependencies["zlib"] is self.dependencies["zlib-ng"]
self.output.info(f"DEP ZLIB generate: {self.dependencies['zlib'].ref.name}!")
def build(self):
assert self.dependencies["zlib"] is self.dependencies["zlib-ng"]
self.output.info(f"DEP ZLIB build: {self.dependencies['zlib'].ref.name}!")
def package_info(self):
assert self.dependencies["zlib"] is self.dependencies["zlib-ng"]
# self.cpp_info.requires = ["zlib::zlib"]
""")
c.save({"zlibng/conanfile.py": GenConanfile("zlib-ng", "0.1"),
"app/conanfile.py": conanfile,
"profile": "[replace_requires]\nzlib/0.1: zlib-ng/0.1"})
c.run("create zlibng")
c.run("build app -pr=profile")
assert "zlib/0.1: zlib-ng/0.1" in c.out
assert "conanfile.py (app/0.1): DEP ZLIB generate: zlib-ng!" in c.out
assert "conanfile.py (app/0.1): DEP ZLIB build: zlib-ng!" in c.out
c.run("create app -pr=profile")
assert "zlib/0.1: zlib-ng/0.1" in c.out
assert "conanfile.py (app/0.1): DEP ZLIB generate: zlib-ng!" in c.out
assert "conanfile.py (app/0.1): DEP ZLIB build: zlib-ng!" in c.out
# FIXME: The self.cpp_info.requires is still broken