Skip to content

Commit

Permalink
merged release/2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded committed Jan 2, 2024
2 parents 6608d64 + f734566 commit 029b5b5
Show file tree
Hide file tree
Showing 11 changed files with 167 additions and 11 deletions.
2 changes: 1 addition & 1 deletion conan/tools/gnu/pkgconfigdeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def package_info(self):
requires = self._get_cpp_info_requires_names(self._dep.cpp_info)
# If we have found some component requires it would be enough
if not requires:
# If no requires were found, let's try to get all the direct dependencies,
# If no requires were found, let's try to get all the direct visible dependencies,
# e.g., requires = "other_pkg/1.0"
requires = [_get_package_name(req, self._build_context_suffix)
for req in self._transitive_reqs.values()]
Expand Down
2 changes: 1 addition & 1 deletion conans/model/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def dumps(self):
"""
Returns a string with the format ``name=conf-value``
"""
return "\n".join([v.dumps() for v in reversed(self._values.values())])
return "\n".join([v.dumps() for v in sorted(self._values.values(), key=lambda x: x._name)])

def serialize(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion conans/model/requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def transform_downstream(self, pkg_type, require, dep_pkg_type):
if require.build: # public!
# TODO: To discuss if this way of conflicting build_requires is actually useful or not
downstream_require = Requirement(require.ref, headers=False, libs=False, build=True,
run=False, visible=True, direct=False)
run=False, visible=self.visible, direct=False)
return downstream_require

if self.build: # Build-requires
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,6 @@ def test_catalyst(arch):
t.run_command('lipo -info "%s"' % app)
assert "architecture: %s" % expected_arch in t.out

#FIXME: recover when ci is fixed for M2
#FIXME: recover when ci is fixed for M2
#t.run_command('"%s"' % app)
#assert "running catalyst 160100" in t.out
62 changes: 62 additions & 0 deletions conans/test/integration/graph/core/graph_manager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,68 @@ def test_d_b_header_only_transitive_headers_b(self):
(libb, True, False, False, False),
(liba, True, True, False, False)])

def test_visible_transitivity(self):
# app -> libd/0.1 -> libc/0.1 -(visible=False)-> libb0.1 -> liba0.1
self.recipe_conanfile("liba/0.1", GenConanfile())
self.recipe_conanfile("libb/0.1", GenConanfile().with_requirement("liba/0.1"))
self.recipe_conanfile("libc/0.1", GenConanfile().with_requirement("libb/0.1",
visible=False))
self.recipe_conanfile("libd/0.1", GenConanfile().with_requirement("libc/0.1"))
consumer = self.recipe_consumer("app/0.1", ["libd/0.1"])

deps_graph = self.build_consumer(consumer)

self.assertEqual(5, len(deps_graph.nodes))
app = deps_graph.root
libd = app.dependencies[0].dst
libc = libd.dependencies[0].dst
libb = libc.dependencies[0].dst
liba = libb.dependencies[0].dst

self._check_node(app, "app/0.1", deps=[libd])
self._check_node(libd, "libd/0.1#123", deps=[libc], dependents=[app])
self._check_node(libc, "libc/0.1#123", deps=[libb], dependents=[libd])
self._check_node(libb, "libb/0.1#123", deps=[liba], dependents=[libc])
self._check_node(liba, "liba/0.1#123", dependents=[libb])

# node, headers, lib, build, run
_check_transitive(app, [(libd, True, True, False, False),
(libc, True, True, False, False)])
_check_transitive(libd, [(libc, True, True, False, False)])
_check_transitive(libc, [(libb, True, True, False, False),
(liba, True, True, False, False)])

def test_visible_build_transitivity(self):
# app -> libd/0.1 -> libc/0.1 -(visible=True, build=True)-> libb0.1 -> liba0.1
self.recipe_conanfile("liba/0.1", GenConanfile())
self.recipe_conanfile("libb/0.1", GenConanfile().with_requirement("liba/0.1"))
self.recipe_conanfile("libc/0.1", GenConanfile().with_requirement("libb/0.1", build=True))
self.recipe_conanfile("libd/0.1", GenConanfile().with_requirement("libc/0.1"))
consumer = self.recipe_consumer("app/0.1", ["libd/0.1"])

deps_graph = self.build_consumer(consumer)

self.assertEqual(5, len(deps_graph.nodes))
app = deps_graph.root
libd = app.dependencies[0].dst
libc = libd.dependencies[0].dst
libb = libc.dependencies[0].dst
liba = libb.dependencies[0].dst

self._check_node(app, "app/0.1", deps=[libd])
self._check_node(libd, "libd/0.1#123", deps=[libc], dependents=[app])
self._check_node(libc, "libc/0.1#123", deps=[libb], dependents=[libd])
self._check_node(libb, "libb/0.1#123", deps=[liba], dependents=[libc])
self._check_node(liba, "liba/0.1#123", dependents=[libb])

# node, headers, lib, build, run
_check_transitive(app, [(libd, True, True, False, False),
(libc, True, True, False, False),
(libb, False, False, True, False)])
_check_transitive(libd, [(libc, True, True, False, False),
(libb, False, False, True, False)])
_check_transitive(libc, [(libb, True, True, True, False)])


class TestLinearFiveLevelsLibraries(GraphManagerTest):
def test_all_static(self):
Expand Down
26 changes: 26 additions & 0 deletions conans/test/integration/graph/core/test_build_requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,32 @@ def test_build_require_conflict(self):
self._check_node(grass2, "grass/0.2#123", dependents=[cheetah])


class TestBuildRequiresVisible(GraphManagerTest):

def test_visible_build(self):
self._cache_recipe("liba/0.1", GenConanfile())
self._cache_recipe("libb/0.1", GenConanfile().with_requirement("liba/0.1", build=True))
self._cache_recipe("libc/0.1", GenConanfile().with_requirement("libb/0.1", visible=False))
deps_graph = self.build_graph(GenConanfile("app", "0.1").with_require("libc/0.1"))

self.assertEqual(4, len(deps_graph.nodes))
app = deps_graph.root
libc = app.dependencies[0].dst
libb = libc.dependencies[0].dst
liba = libb.dependencies[0].dst

self._check_node(app, "app/0.1@", deps=[libc], dependents=[])
self._check_node(libc, "libc/0.1#123", deps=[libb], dependents=[app])
self._check_node(libb, "libb/0.1#123", deps=[liba], dependents=[libc])
self._check_node(liba, "liba/0.1#123", deps=[], dependents=[libb])

# node, include, link, build, run
_check_transitive(app, [(libc, True, True, False, False)])
_check_transitive(libc, [(libb, True, True, False, False),
(liba, False, False, True, False)]) # liba is build & visible!
_check_transitive(libb, [(liba, True, True, True, False)])


class TestTestRequire(GraphManagerTest):

def test_basic(self):
Expand Down
2 changes: 1 addition & 1 deletion conans/test/integration/graph/test_dependencies_visit.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def generate(self):
False, "=>zlib/0.1"),
('print("=>{}".format(self.dependencies.get("zlib", build=False).ref))',
False, "=>zlib/0.2"),
('print("=>{}".format(self.dependencies.get("zlib", build=True, visible=True).ref))',
('print("=>{}".format(self.dependencies.get("zlib", build=True, visible=False).ref))',
False, "=>zlib/0.1"),
('self.dependencies.get("cmake", build=True)', True,
'There are more than one requires matching the specified filters: {\'build\': True}\n'
Expand Down
16 changes: 16 additions & 0 deletions conans/test/integration/graph/test_skip_binaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,19 @@ def test_skipped_intermediate_header():
# liba brings only libraries
assert "set(liba_INCLUDE_DIRS_RELEASE )" in liba_data
assert "set(liba_LIBS_RELEASE liba)" in liba_data


def test_skip_visible_build():
# https://github.com/conan-io/conan/issues/15346
c = TestClient()
c.save({"liba/conanfile.py": GenConanfile("liba", "0.1"),
"libb/conanfile.py": GenConanfile("libb", "0.1").with_requirement("liba/0.1",
build=True),
"libc/conanfile.py": GenConanfile("libc", "0.1").with_requirement("libb/0.1",
visible=False),
"app/conanfile.py": GenConanfile("app", "0.1").with_requires("libc/0.1")})
c.run("create liba")
c.run("create libb")
c.run("create libc")
c.run("install app --format=json")
assert re.search(r"Skipped binaries(\s*)libb/0.1, liba/0.1", c.out)
25 changes: 20 additions & 5 deletions conans/test/integration/package_id/package_id_and_confs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
PKG_ID_NO_CONF = "ebec3dc6d7f6b907b3ada0c3d3cdc83613a2b715"
PKG_ID_1 = "89d32f25195a77f4ae2e77414b870781853bdbc1"
PKG_ID_2 = "7f9ed92704709f56ecc7b133322479caf3ffd7ad"
PKG_ID_3 = "45b796ec237c7e2399944e79bee49b56fd022067"
PKG_ID_3 = "a9f917f3bad3b48b5bceae70214764274ccd6337"
PKG_ID_USER_1 = "571b5dae13b37a78c1993842739bd475879092ea"
PKG_ID_USER_2 = "54a394d26f9c35add86f20ac02cacc3c7e18f02c"
PKG_ID_USER_3 = "002f9fb964ba1ba1fa1d38cb907968295645afb1"
PKG_ID_USER_3 = "54a394d26f9c35add86f20ac02cacc3c7e18f02c"


@pytest.mark.parametrize("package_id_confs, package_id", [
Expand Down Expand Up @@ -105,11 +105,26 @@ class Pkg(ConanFile):

def test_conf_pkg_id_user_pattern_not_defined():
tc = TestClient(light=True)
tc.save({
"lib/conanfile.py": GenConanfile("lib", "1.0"),
})
tc.save({"lib/conanfile.py": GenConanfile("lib", "1.0")})
tc.save_home({"global.conf": "tools.info.package_id:confs=['user.*']"})

# This used to break the build because `user.*` conf was not valid
tc.run("create lib")
assert "lib/1.0: Package 'da39a3ee5e6b4b0d3255bfef95601890afd80709' created" in tc.out


@pytest.mark.parametrize("conf,pkgconf", [
("user.foo:value=1\nuser.bar:value=2", "['user.foo:value', 'user.bar:value']"),
("user.foo:value=1\nuser.bar:value=2", "['user.bar:value', 'user.foo:value']"),
("user.bar:value=2\nuser.foo:value=1", "['user.foo:value', 'user.bar:value']"),
("user.bar:value=2\nuser.foo:value=1", "['user.bar:value', 'user.foo:value']"),
])
def test_package_id_order(conf, pkgconf):
"""Ensure the order of the definitions in the conf file does not affect the package_id"""
tc = TestClient(light=True)
tc.save({"profile": f"[conf]\ntools.info.package_id:confs={pkgconf}\n" +
conf,
"conanfile.py": GenConanfile("pkg", "1.0")})
tc.run("create . -pr=profile")
# They should all have the same pkg id - note that this did not happen before 2.0.17
tc.assert_listed_binary({"pkg/1.0": ("43227c40b8725e89d30a9f97c0652629933a3685", "Build")})
37 changes: 37 additions & 0 deletions conans/test/integration/toolchains/gnu/test_pkgconfigdeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,3 +806,40 @@ def build(self):

c.assert_listed_require({"example/1.0": "Cache"})
c.assert_listed_require({"example/1.0": "Cache"}, build=True)


def test_pkg_config_deps_and_private_deps():
"""
Testing that no errors are raised when the dependency tree has a private one in the middle
of it.
Issue related: https://github.com/conan-io/conan/issues/15311
"""
client = TestClient()
client.save({"conanfile.py": GenConanfile("private", "0.1")})
client.run("create .")
conanfile = textwrap.dedent("""
from conan import ConanFile
class ConsumerConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "PkgConfigDeps"
name = "pkg"
version = "0.1"
def requirements(self):
self.requires("private/0.1", visible=False)
""")
client.save({"conanfile.py": conanfile}, clean_first=True)
client.run("create .")
conanfile = textwrap.dedent("""
from conan import ConanFile
class ConsumerConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "PkgConfigDeps"
def requirements(self):
self.requires("pkg/0.1")
""")
client.save({"conanfile.py": conanfile}, clean_first=True)
# Now, it passes and creates the pc files correctly (the skipped one is not created)
client.run("install .")
assert "Requires:" not in client.load("pkg.pc")
2 changes: 1 addition & 1 deletion conans/test/unittests/model/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ def test_compose_conf_complex():
c2.loads(text)
c.update_conf_definition(c2)
expected_text = textwrap.dedent("""\
user.company.cpu:jobs=5
user.company.build:ccflags=--m otherflag
user.company.cpu:jobs=5
user.company.list:objs=[0, 1, 2, 3, 4, 'mystr', {'a': 1}, 5, 6, {'b': 2}]
user.company.network:proxies={'url': 'http://api.site.com/apiv2'}
zlib:user.company.check:shared=!
Expand Down

0 comments on commit 029b5b5

Please sign in to comment.