From f3c7aaa5c0a8545806573588d3f305bef5a635d5 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 20 Nov 2024 07:10:07 +0100 Subject: [PATCH] warn if building in cache with editable (#17325) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * warn if building in cache with editable * Update conans/client/graph/graph_binaries.py * Update test/integration/editable/transitive_editable_test.py --------- Co-authored-by: Abril Rincón Blanco --- conans/client/graph/graph_binaries.py | 4 ++++ .../editable/transitive_editable_test.py | 23 +++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/conans/client/graph/graph_binaries.py b/conans/client/graph/graph_binaries.py index db960e5251f..0a07140173e 100644 --- a/conans/client/graph/graph_binaries.py +++ b/conans/client/graph/graph_binaries.py @@ -230,6 +230,10 @@ def _evaluate_node(self, node, build_mode, remotes, update): "didn't enable 'tools.graph:vendor=build' to compute " \ "its dependencies" node.binary = BINARY_INVALID + if any(n.node.binary in (BINARY_EDITABLE, BINARY_EDITABLE_BUILD) + for n in node.transitive_deps.values()): + conanfile.output.warning("Package is being built in the cache using editable " + "dependencies, this is dangerous", warn_tag="risk") def _process_node(self, node, build_mode, remotes, update): # Check that this same reference hasn't already been checked diff --git a/test/integration/editable/transitive_editable_test.py b/test/integration/editable/transitive_editable_test.py index 96113b84dcf..bb37efab4b2 100644 --- a/test/integration/editable/transitive_editable_test.py +++ b/test/integration/editable/transitive_editable_test.py @@ -5,7 +5,7 @@ def test_transitive_editables_half_diamond(): # https://github.com/conan-io/conan/issues/4445 - client = TestClient() + client = TestClient(light=True) client.save({"libc/conanfile.py": GenConanfile("libc", "0.1"), "libb/conanfile.py": GenConanfile("libb", "0.1").with_require("libc/0.1"), "liba/conanfile.py": GenConanfile("liba", "0.1").with_requires("libb/0.1", @@ -78,7 +78,7 @@ def layout(self): def test_transitive_editables_python_requires_version_range(): # https://github.com/conan-io/conan/issues/14411 - client = TestClient(default_server_user=True) + client = TestClient(default_server_user=True, light=True) client.save({"dep/conanfile.py": GenConanfile("dep", "0.1"), "pkg/conanfile.py": GenConanfile("pkg", "0.1").with_python_requires("dep/[*]")}) client.run("editable add pkg", assert_error=True) @@ -124,7 +124,7 @@ def test_transitive_editable_cascade_build(): """ https://github.com/conan-io/conan/issues/15292 """ - c = TestClient() + c = TestClient(light=True) pkga = GenConanfile("pkga", "1.0").with_package_type("static-library") pkgb = GenConanfile("pkgb", "1.0").with_requires("pkga/1.0").with_package_type("static-library") pkgc = GenConanfile("pkgc", "1.0").with_requires("pkgb/1.0").with_package_type("static-library") @@ -168,7 +168,7 @@ def test_transitive_editable_cascade_package_id(): """ https://github.com/conan-io/conan/issues/15292 """ - c = TestClient() + c = TestClient(light=True) pkga = GenConanfile("pkga", "1.0").with_package_type("static-library") pkgb = GenConanfile("pkgb", "1.0").with_requires("pkga/1.0").with_package_type("static-library") pkgc = GenConanfile("pkgc", "1.0").with_requires("pkgb/1.0").with_package_type("shared-library") @@ -207,3 +207,18 @@ def test_transitive_editable_cascade_package_id(): # The consumers didn't need a new binary, even if I modified pkg c.assert_listed_binary({"pkgb/1.0": (pkgb_id, "Cache"), "pkgc/1.0": (pkgc_id, "Build")}) + + +def test_warning_from_cache(): + c = TestClient(light=True) + c.save({"pkga/conanfile.py": GenConanfile("pkga", "1.0"), + "pkgb/conanfile.py": GenConanfile("pkgb", "1.0").with_requires("pkga/1.0"), + "pkgc/conanfile.py": GenConanfile("pkgc", "1.0").with_requires("pkgb/1.0")}) + c.run("editable add pkga") + c.run("create pkgb") + assert "pkgb/1.0: WARN: risk: Package is being built in the cache using editable" in c.out + c.run("create pkgc") + assert "pkgc/1.0: WARN: risk: Package is being built in the cache using editable" in c.out + c.run("create pkgc --build=*") + assert "pkgb/1.0: WARN: risk: Package is being built in the cache using editable" in c.out + assert "pkgc/1.0: WARN: risk: Package is being built in the cache using editable" in c.out