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

allow not propagating components to consumers #12966

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
8 changes: 0 additions & 8 deletions conans/model/build_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,14 +400,6 @@ def _raise_incorrect_components_definition(self, package_name, package_requires)

def _check_components_requires_instersection(comp_requires):
reqs = [it.split(COMPONENT_SCOPE)[0] for it in comp_requires if COMPONENT_SCOPE in it]
# Raise on components requires without package requires
for pkg_require in pkg_requires:
if package_requires[pkg_require].private or package_requires[pkg_require].override:
# Not standard requires, skip
continue
if pkg_require not in reqs:
raise ConanException("Package require '%s' not used in components requires"
% pkg_require)
# Raise on components requires requiring inexistent package requires
for comp_require in reqs:
reason = None
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import textwrap
import unittest

import pytest

from conans.test.utils.tools import TestClient


Expand Down Expand Up @@ -133,25 +131,6 @@ def package_info(self):
self.assertIn("ERROR: Component 'top::not-existing' not found in 'top'"
" package requirement", t.out)

def test_unused_requirement(self):
""" Requires should include all listed requirements
This error is known when creating the package if the requirement is consumed.
"""
consumer = textwrap.dedent("""
from conans import ConanFile

class Recipe(ConanFile):
requires = "top/version"
def package_info(self):
self.cpp_info.requires = ["other::other"]
""")
t = TestClient()
t.save({'top.py': self.top, 'consumer.py': consumer})
t.run('create top.py top/version@')
t.run('create consumer.py wrong/version@', assert_error=True)
self.assertIn("wrong/version package_info(): Package require 'top' not used"
" in components requires", t.out)

def test_wrong_requirement(self):
""" If we require a wrong requirement, we get a meaninful error.
This error is known when creating the package if the requirement is not there.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,26 +116,6 @@ def package_info(self):
assert "Component 'top::not-existing' not found in 'top' package requirement" in t.out


def test_unused_requirement(top_conanfile):
""" Requires should include all listed requirements
This error is known when creating the package if the requirement is consumed.
"""
consumer = textwrap.dedent("""
from conans import ConanFile

class Recipe(ConanFile):
requires = "top/version"
def package_info(self):
self.cpp_info.requires = ["other::other"]
""")
t = TestClient()
t.save({'top.py': top_conanfile, 'consumer.py': consumer})
t.run('create top.py top/version@')
t.run('create consumer.py wrong/version@', assert_error=True)
assert "wrong/version package_info(): Package require 'top' not used in components " \
"requires" in t.out


def test_wrong_requirement(top_conanfile):
""" If we require a wrong requirement, we get a meaninful error.
This error is known when creating the package if the requirement is not there.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,59 +391,6 @@ def test_package_requires_in_components_requires(self):
client.run("create conanfile1.py")
client.run("create conanfile2.py")

conanfile = GenConanfile("consumer", "0.1") \
.with_requirement("dep1/0.1") \
.with_requirement("dep2/0.1") \
.with_package_info(cpp_info={"components": {"kk": {"requires": []}}},
env_info={})
client.save({"conanfile.py": conanfile})
client.run("create conanfile.py", assert_error=True)
self.assertIn("consumer/0.1 package_info(): Package require 'dep1' not used in "
"components requires", client.out)

conanfile = GenConanfile("consumer", "0.1") \
.with_requirement("dep1/0.1") \
.with_requirement("dep2/0.1") \
.with_package_info(cpp_info={"components": {"kk": {"requires": ["dep1::dep1"]}}},
env_info={})
client.save({"conanfile.py": conanfile})
client.run("create conanfile.py", assert_error=True)
self.assertIn("consumer/0.1 package_info(): Package require 'dep2' not used in components "
"requires", client.out)

conanfile = GenConanfile("consumer", "0.1") \
.with_requirement("dep1/0.1") \
.with_requirement("dep2/0.1") \
.with_package_info(cpp_info={"components": {"kk": {"requires": ["dep1::dep1"]},
"kkk": {"requires": ["kk"]}}},
env_info={})
client.save({"conanfile.py": conanfile})
client.run("create conanfile.py", assert_error=True)
self.assertIn("consumer/0.1 package_info(): Package require 'dep2' not used in components "
"requires", client.out)

conanfile = GenConanfile("consumer", "0.1") \
.with_requirement("dep1/0.1") \
.with_requirement("dep2/0.1") \
.with_package_info(cpp_info={"components": {"kk": {"requires": []},
"kkk": {"requires": ["kk"]}}},
env_info={})
client.save({"conanfile.py": conanfile})
client.run("create conanfile.py", assert_error=True)
self.assertIn("consumer/0.1 package_info(): Package require 'dep1' not used in components "
"requires", client.out)

conanfile = GenConanfile("consumer", "0.1") \
.with_requirement("dep1/0.1") \
.with_requirement("dep2/0.1") \
.with_package_info(cpp_info={"components": {"kk": {"requires": ["dep2::comp"]},
"kkk": {"requires": ["dep3::dep3"]}}},
env_info={})
client.save({"conanfile.py": conanfile})
client.run("create conanfile.py", assert_error=True)
self.assertIn("consumer/0.1 package_info(): Package require 'dep1' not used in components "
"requires", client.out)

conanfile = GenConanfile("consumer", "0.1") \
.with_requirement("dep2/0.1") \
.with_package_info(cpp_info={"components": {"kk": {"requires": ["dep2::comp"]},
Expand Down
25 changes: 25 additions & 0 deletions conans/test/integration/test_components.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import textwrap

from conans.test.assets.genconanfile import GenConanfile
from conans.test.utils.tools import TestClient


Expand All @@ -23,3 +24,27 @@ def package_info(self):
assert "a requires c"
assert "b requires a"
assert "c rquires b"


def test_components_not_required():
"""
Allow requiring and building against one component, but not propagating it
https://github.com/conan-io/conan/issues/12965
"""
c = TestClient()
conanfile = textwrap.dedent("""
from conan import ConanFile

class TestcycleConan(ConanFile):
name = "wayland"
version = "1.0"
requires = "expat/1.0"

def package_info(self):
self.cpp_info.components["wayland-scanner"].libdirs = []
""")
c.save({"expat/conanfile.py": GenConanfile("expat", "1.0"),
"wayland/conanfile.py": conanfile})
c.run("create expat")
c.run("create wayland")
assert "wayland/1.0: Created package" in c.out