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 provide error for self-tool-requires #15575

Merged
merged 1 commit into from
Feb 1, 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
9 changes: 7 additions & 2 deletions conans/client/graph/provides.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,25 @@ def check_graph_provides(dep_graph):
for node in dep_graph.nodes:
provides = {}
current_provides = node.conanfile.provides
if isinstance(current_provides, str): # Just in case it is defined in configure() as str
current_provides = [current_provides]
for dep in node.transitive_deps.values():
dep_node = dep.node
dep_require = dep.require
if node.ref is not None and dep_node.ref.name == node.ref.name:
continue # avoid dependency to self (as tool-requires for cross-build)

dep_provides = dep_node.conanfile.provides
if dep_provides is None:
continue
if isinstance(dep_provides, str):
dep_provides = [dep_provides]
for provide in dep_provides:
# First check if collides with current node
if current_provides is not None and provide in current_provides:
raise GraphProvidesError(node, dep_node)

# Then, check if collides with other requirements
new_req = dep_require.copy_requirement()
new_req = dep.require.copy_requirement()
new_req.ref = RecipeReference(provide, new_req.ref.version, new_req.ref.user,
new_req.ref.channel)
existing = node.transitive_deps.get(new_req)
Expand Down
24 changes: 24 additions & 0 deletions conans/test/integration/graph/core/test_provides.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,27 @@ def package_info(self):
t.run("install app.py --name=app --version=version")
t.run("install app.py --name=app --version=version -o app/*:conflict=True", assert_error=True)
assert "ERROR: Provide Conflict: Both 'app/version' and 'req/v1' provide 'libjpeg'" in t.out


def test_self_build_require():
c = TestClient()
conanfile = textwrap.dedent("""\
from conan import ConanFile
from conan.tools.build import cross_building

class Pkg(ConanFile):
name = "grpc"
version = "0.1"
settings = "os"
provides = "grpc-impl"
def build_requirements(self):
if cross_building(self):
self.tool_requires("grpc/0.1")
""")
c.save({'conanfile.py': conanfile})
c.run("create . -s os=Windows -s:b os=Windows")
c.assert_listed_binary({"grpc/0.1": ("ebec3dc6d7f6b907b3ada0c3d3cdc83613a2b715", "Build")})
c.run("create . -s os=Linux -s:b os=Windows --build=missing")
c.assert_listed_binary({"grpc/0.1": ("9a4eb3c8701508aa9458b1a73d0633783ecc2270", "Build")})
c.assert_listed_binary({"grpc/0.1": ("ebec3dc6d7f6b907b3ada0c3d3cdc83613a2b715", "Cache")},
build=True)