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

Fix/replace requires multiple #17326

Merged
merged 3 commits into from
Nov 20, 2024
Merged
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
10 changes: 7 additions & 3 deletions conans/model/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,16 @@ 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.pop(new_req, None)
if existing is not None:
if node.replaced_requires:
for old_req, new_req in node.replaced_requires.items():
# Two different replaced_requires can point to the same real requirement
existing = d[new_req]
added_req = new_req.copy_requirement()
added_req.ref = RecipeReference.loads(old_req)
d[added_req] = existing
# Now remove the replaced from dependencies dict
for new_req in node.replaced_requires.values():
d.pop(new_req, None)
return ConanFileDependencies(d)

def filter(self, require_filter, remove_system=True):
Expand Down
36 changes: 36 additions & 0 deletions test/integration/graph/test_replace_requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,39 @@ def package_info(self):
assert "target_link_libraries(... ZLIB::ZLIB)" in c.out
assert "zlib in deps?: True" in c.out
assert "zlib-ng in deps?: False" in c.out


def test_replace_requires_multiple():
conanfile = textwrap.dedent("""
from conan import ConanFile

class EpoxyConan(ConanFile):
name = "libepoxy"
version = "0.1"

def requirements(self):
self.requires("opengl/system")
self.requires("egl/system")

def generate(self):
for r, d in self.dependencies.items():
self.output.info(f"DEP: {r.ref.name}: {d.ref.name}")

def package_info(self):
self.cpp_info.requires.append("opengl::opengl")
self.cpp_info.requires.append("egl::egl")
""")
profile = textwrap.dedent("""
[replace_requires]
opengl/system: libgl/1.0
egl/system: libgl/1.0
""")
c = TestClient()
c.save({"dep/conanfile.py": GenConanfile(),
"app/conanfile.py": conanfile,
"profile": profile})
c.run("create dep --name=libgl --version=1.0")
c.run("create app -pr=profile")
# There are actually 2 dependencies, pointing to the same node
assert "libepoxy/0.1: DEP: opengl: libgl" in c.out
assert "libepoxy/0.1: DEP: egl: libgl" in c.out