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

feature: Improve dependency-cycle error to show the cycle #11519

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion conans/model/build_info.py
Expand Up @@ -608,8 +608,15 @@ def _get_sorted_components(self):
del components[comp_name]
break
else:
dset = set()
for comp_name, comp in components.items():
for dep_name, dep in components.items():
for require in self._filter_component_requires(dep.requires):
if require == comp_name:
dset.add(" {} requires {}".format(dep_name, comp_name))
dep_mesg = "\n".join(dset)
raise ConanException("There is a dependency loop in "
"'self.cpp_info.components' requires")
"'self.cpp_info.components' requires:\n{}".format(dep_mesg))
self._sorted_components = ordered
else: # If components do not have requirements, keep them in the same order
self._sorted_components = self._cpp_info.components
Expand Down
25 changes: 25 additions & 0 deletions conans/test/integration/test_components.py
@@ -0,0 +1,25 @@
import textwrap

from conans.test.utils.tools import TestClient


def test_components_cycles():
c = TestClient()
conanfile = textwrap.dedent("""
from conan import ConanFile

class TestcycleConan(ConanFile):
name = "testcycle"
version = "1.0"

def package_info(self):
self.cpp_info.components["c"].requires = ["b"]
self.cpp_info.components["b"].requires = ["a"]
self.cpp_info.components["a"].requires = ["c"] # cycle!
""")
c.save({"conanfile.py": conanfile})
c.run("create .", assert_error=True)
assert "ERROR: There is a dependency loop in 'self.cpp_info.components' requires:" in c.out
assert "a requires c"
assert "b requires a"
assert "c rquires b"