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

[develop2]fix aggregation of test trait in diamonds #12080

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions conans/model/requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ def aggregate(self, other):
self.run = self.run or other.run
self.visible |= other.visible
self.force |= other.force
if not other.test:
self.test = False # it it was previously a test, but also required by non-test
# TODO: self.package_id_mode => Choose more restrictive?

def transform_downstream(self, pkg_type, require, dep_pkg_type):
Expand Down
48 changes: 40 additions & 8 deletions conans/test/integration/graph/core/test_build_requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
def _check_transitive(node, transitive_deps):
values = list(node.transitive_deps.values())

assert len(values) == len(transitive_deps)
assert len(values) == len(transitive_deps), f"{node}:{len(values)} != {len(transitive_deps)}"

for v1, v2 in zip(values, transitive_deps):
assert v1.node is v2[0]
assert v1.require.headers is v2[1]
assert v1.require.libs is v2[2]
assert v1.require.build is v2[3]
assert v1.require.run is v2[4]
# asserts were difficult to debug
if v1.node is not v2[0]: raise Exception(f"{v1.node}!={v2[0]}")
if v1.require.headers is not v2[1]: raise Exception(f"{v1.node}!={v2[0]} headers")
if v1.require.libs is not v2[2]: raise Exception(f"{v1.node}!={v2[0]} libs")
if v1.require.build is not v2[3]: raise Exception(f"{v1.node}!={v2[0]} build")
if v1.require.run is not v2[4]: raise Exception(f"{v1.node}!={v2[0]} run")
if len(v2) >= 6:
if v1.require.test is not v2[5]: raise Exception(f"{v1.node}!={v2[0]} test")


class BuildRequiresGraphTest(GraphManagerTest):
Expand Down Expand Up @@ -365,8 +368,8 @@ def test_basic(self):
self._check_node(app, "app/0.1@", deps=[gtest], dependents=[])
self._check_node(gtest, "gtest/0.1#123", deps=[], dependents=[app])

# node, include, link, build, run
_check_transitive(app, [(gtest, True, True, False, False)])
# node, include, link, build, run, test
_check_transitive(app, [(gtest, True, True, False, False, True)])

def test_lib_build_require(self):
# app -> lib -(tr)-> gtest
Expand Down Expand Up @@ -452,6 +455,35 @@ def test_test_require_transitive(self, gtestlib_type):
_check_transitive(lib, [(gtest, True, True, False, False),
(gtestlib, True, True, False, False)])

def test_trait_aggregated(self):
# app -> lib -(tr)-> gtest -> zlib
# \-------------------/
# If zlib is in the host context, a dependency for host, better test=False trait
self._cache_recipe("zlib/0.1", GenConanfile())
self._cache_recipe("gtest/0.1", GenConanfile().with_requires("zlib/0.1"))
self._cache_recipe("lib/0.1", GenConanfile().with_test_requires("gtest/0.1")
.with_requires("zlib/0.1"))
deps_graph = self.build_graph(GenConanfile("app", "0.1").with_require("lib/0.1"))

self.assertEqual(4, len(deps_graph.nodes))
app = deps_graph.root
lib = app.dependencies[0].dst
gtest = lib.dependencies[1].dst
zlib = gtest.dependencies[0].dst
zlib2 = lib.dependencies[0].dst
assert zlib is zlib2

self._check_node(app, "app/0.1@", deps=[lib], dependents=[])
self._check_node(lib, "lib/0.1#123", deps=[zlib, gtest], dependents=[app])
self._check_node(gtest, "gtest/0.1#123", deps=[zlib], dependents=[lib])
self._check_node(zlib, "zlib/0.1#123", deps=[], dependents=[gtest, lib])

# node, include, link, build, run
_check_transitive(app, [(lib, True, True, False, False),
(zlib, True, True, False, False, False)])
_check_transitive(lib, [(gtest, True, True, False, False),
(zlib, True, True, False, False, False)])


class BuildRequiresPackageIDTest(GraphManagerTest):

Expand Down