Skip to content

Commit 589bffe

Browse files
authored
improve error message for build-scripts with deps (#18869)
1 parent b7687c0 commit 589bffe

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

conan/internal/model/requires.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,9 @@ def transform_downstream(self, pkg_type, require, dep_pkg_type):
304304
elif pkg_type is PackageType.HEADER:
305305
downstream_require = Requirement(require.ref, headers=require.headers, libs=require.libs, run=require.run)
306306
else:
307-
assert pkg_type == PackageType.UNKNOWN
307+
if pkg_type != PackageType.UNKNOWN:
308+
raise ConanException(f"Package '{self.ref}' with type '{pkg_type}' cannot have "
309+
f"a '{dep_pkg_type}' dependency to '{require.ref}'")
308310
# TODO: This is undertested, changing it did not break tests
309311
downstream_require = require.copy_requirement()
310312
elif dep_pkg_type is PackageType.HEADER:

test/integration/build_requires/build_requires_test.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ def configure(self):
602602

603603
def test_transitive_build_scripts_error():
604604
# https://github.com/conan-io/conan/issues/18235
605-
c = TestClient()
605+
c = TestClient(light=True)
606606
meta = textwrap.dedent("""
607607
from conan import ConanFile
608608
@@ -631,3 +631,29 @@ def requirements(self):
631631
c.run("create meta")
632632
c.run("install product")
633633
# It doesn't crash
634+
635+
636+
def test_transitive_build_scripts_library_error():
637+
# https://github.com/conan-io/conan/issues/18856
638+
c = TestClient(light=True)
639+
tool = textwrap.dedent("""
640+
from conan import ConanFile
641+
642+
class Product(ConanFile):
643+
name = "tool"
644+
version = "0.1"
645+
package_type = "build-scripts"
646+
def requirements(self):
647+
self.requires("dep/0.1")
648+
""")
649+
650+
c.save({"dep/conanfile.py": GenConanfile("dep", "0.1").with_package_type("static-library"),
651+
"tool/conanfile.py": tool})
652+
c.run("create dep")
653+
c.run("create tool")
654+
# Tool-requires, not an issue
655+
c.run("install --tool-requires=tool/0.1")
656+
# requires, it crashed with traceback, now a clear error message
657+
c.run("install --requires=tool/0.1", assert_error=True)
658+
assert ("ERROR: Package 'tool/0.1' with type 'build-scripts' cannot have "
659+
"a 'static-library' dependency to 'dep/0.1'") in c.out

0 commit comments

Comments
 (0)