From 9cc5931648c2d4f52cdfafbe227012bafc646687 Mon Sep 17 00:00:00 2001 From: memsharded Date: Wed, 20 Nov 2024 23:34:14 +0100 Subject: [PATCH 1/2] solve is_test bug --- conans/model/requires.py | 2 - test/integration/graph/test_test_requires.py | 44 ++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/conans/model/requires.py b/conans/model/requires.py index cb819d74e46..d9a9dbc7646 100644 --- a/conans/model/requires.py +++ b/conans/model/requires.py @@ -254,7 +254,6 @@ def aggregate(self, other): self.transitive_libs = self.transitive_libs or other.transitive_libs if not other.test: self.test = False # it it was previously a test, but also required by non-test - self.is_test = self.is_test or other.is_test # package_id_mode is not being propagated downstream. So it is enough to check if the # current require already defined it or not if self.package_id_mode is None: @@ -345,7 +344,6 @@ def transform_downstream(self, pkg_type, require, dep_pkg_type): if self.test: downstream_require.test = True - downstream_require.is_test = require.is_test # If the current one is resolving conflicts, the downstream one will be too downstream_require.force = require.force diff --git a/test/integration/graph/test_test_requires.py b/test/integration/graph/test_test_requires.py index 5342bc3ad3b..d74bec93a6c 100644 --- a/test/integration/graph/test_test_requires.py +++ b/test/integration/graph/test_test_requires.py @@ -203,6 +203,8 @@ def test_requires_transitive_diamond_components_order(): like the above, but in different order libc --(test-requires)---> liba |-----> libb -----------/ + libc->liba => test=False, direct=True, is_test=True + direct_dependencies (components check) => False https://github.com/conan-io/conan/issues/17164 """ c = TestClient(light=True) @@ -230,6 +232,48 @@ def package_info(self): assert "libc/0.1: Created package" in c.out +def test_wrong_requirement_test_requires(): + """ https://github.com/conan-io/conan/issues/17312 + + app --------> etas --------------> enum + \\-->hwinfo-/---(test_requires)---/ + \\-----------------------------/ + + app->enum => test=False, direct=True, is_test=True + direct_dependencies (components check) => True + """ + c = TestClient(light=True) + app = textwrap.dedent(""" + from conan import ConanFile + class Pkg(ConanFile): + name = "app" + version = "0.1" + requires = "etas/0.1", "enum/0.1", "hwinfo/0.1" + + def generate(self): + for r, d in self.dependencies.items(): + assert not (r.direct and r.is_test) + + def package_info(self): + self.cpp_info.requires = ["etas::etas", "enum::enum", "hwinfo::hwinfo"] + """) + files = { + "enum/conanfile.py": GenConanfile("enum", "0.1"), + "etas/conanfile.py": GenConanfile("etas", "0.1").with_requirement("enum/0.1"), + "hwinfo/conanfile.py": GenConanfile("hwinfo", "0.1").with_requirement("etas/0.1") + .with_test_requires("enum/0.1"), + "app/conanfile.py": app, + } + c.save(files) + c.run("create enum") + c.run("create etas") + c.run("create hwinfo") + # The assert in generate() doesnt fail + c.run("install app") + # the package_info() doesn't fail + c.run("create app") + + def test_test_requires_options(): """ the default_options = {} values also propagate to ``test_requires()`` """ c = TestClient(light=True) From ccbdbf6b3469a563572e58cfb847dc392df84cb8 Mon Sep 17 00:00:00 2001 From: memsharded Date: Wed, 20 Nov 2024 23:42:34 +0100 Subject: [PATCH 2/2] fix --- conans/__init__.py | 2 +- conans/model/requires.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/conans/__init__.py b/conans/__init__.py index 01522d5b792..92b87aef053 100644 --- a/conans/__init__.py +++ b/conans/__init__.py @@ -1,4 +1,4 @@ CHECKSUM_DEPLOY = "checksum_deploy" # Only when v2 REVISIONS = "revisions" # Only when enabled in config, not by default look at server_launcher.py -__version__ = '2.9.2' +__version__ = '2.9.3' diff --git a/conans/model/requires.py b/conans/model/requires.py index d9a9dbc7646..9d98a6711e4 100644 --- a/conans/model/requires.py +++ b/conans/model/requires.py @@ -254,6 +254,8 @@ def aggregate(self, other): self.transitive_libs = self.transitive_libs or other.transitive_libs if not other.test: self.test = False # it it was previously a test, but also required by non-test + # necessary even if no propagation, order of requires matter + self.is_test = self.is_test or other.is_test # package_id_mode is not being propagated downstream. So it is enough to check if the # current require already defined it or not if self.package_id_mode is None: