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

[develop2] Let dependency define package_id modes #11441

Merged
merged 4 commits into from
Jul 26, 2022
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
2 changes: 1 addition & 1 deletion conans/client/graph/compute_pid.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def compute_package_id(node, new_config):
build_data = OrderedDict()
for require, transitive in node.transitive_deps.items():
dep_node = transitive.node
require.deduce_package_id_mode(conanfile.package_type, dep_node.conanfile.package_type,
require.deduce_package_id_mode(conanfile.package_type, dep_node,
non_embed_mode, embed_mode, build_mode, unknown_mode)
if require.package_id_mode is not None:
req_info = RequirementInfo(dep_node.pref.ref, dep_node.pref.package_id,
Expand Down
9 changes: 8 additions & 1 deletion conans/model/requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,17 @@ def transform_downstream(self, pkg_type, require, dep_pkg_type):
downstream_require.direct = False
return downstream_require

def deduce_package_id_mode(self, pkg_type, dep_pkg_type, non_embed_mode, embed_mode, build_mode,
def deduce_package_id_mode(self, pkg_type, dep_node, non_embed_mode, embed_mode, build_mode,
unknown_mode):
# If defined by the ``require(package_id_mode=xxx)`` trait, that is higher priority
# The "conf" values are defaults, no hard overrides
if self.package_id_mode:
return

dep_conanfile = dep_node.conanfile
dep_pkg_type = dep_conanfile.package_type
if self.build:
build_mode = getattr(dep_conanfile, "build_mode", build_mode)
if build_mode and self.direct:
self.package_id_mode = build_mode
return # At the moment no defaults
Expand All @@ -330,6 +333,10 @@ def deduce_package_id_mode(self, pkg_type, dep_pkg_type, non_embed_mode, embed_m
self.package_id_mode = "unrelated_mode"
return

# If the dependency defines the mode, that has priority over default
embed_mode = getattr(dep_conanfile, "package_id_embed_mode", embed_mode)
non_embed_mode = getattr(dep_conanfile, "package_id_non_embed_mode", non_embed_mode)
unknown_mode = getattr(dep_conanfile, "package_id_unknown_mode", unknown_mode)
if self.headers or self.libs: # only if linked
if pkg_type in (PackageType.SHARED, PackageType.APP):
if dep_pkg_type is PackageType.SHARED:
Expand Down
30 changes: 30 additions & 0 deletions conans/test/integration/package_id/package_id_modes_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import textwrap

from conans.test.utils.tools import GenConanfile, TestClient


Expand Down Expand Up @@ -49,3 +51,31 @@ def test_basic_default_modes_application():
new_package_id = "efe870a1b1b4fe60e55aa6e2d17436665404370f"
assert new_package_id != package_id
c.assert_listed_binary({"engine/1.0": (new_package_id, "Build")})


class TestDepDefinedMode:
def test_dep_defined(self):
c = TestClient()
dep = textwrap.dedent("""
from conan import ConanFile
class Dep(ConanFile):
name = "dep"
package_type = "static-library"
package_id_embed_mode = "major_mode"
package_id_non_embed_mode = "major_mode"
""")
c.save({"dep/conanfile.py": dep,
"pkg/conanfile.py": GenConanfile("pkg", "0.1").with_requires("dep/[*]")
.with_shared_option(False)})
c.run("create dep --version=0.1")
c.run("create pkg")
c.assert_listed_binary({"pkg/0.1": ("66a9e6a31e63f77952fd72744d0d5da07970f42e", "Build")})
c.run("create pkg -o pkg/*:shared=True")
c.assert_listed_binary({"pkg/0.1": ("5a5828e18eef6a86813b01d4f5a83ea7d87d1139", "Build")})

# using dep 0.2, still same, because dependency chose "major_mode"
c.run("create dep --version=0.2")
c.run("create pkg")
c.assert_listed_binary({"pkg/0.1": ("66a9e6a31e63f77952fd72744d0d5da07970f42e", "Build")})
c.run("create pkg -o pkg/*:shared=True")
c.assert_listed_binary({"pkg/0.1": ("5a5828e18eef6a86813b01d4f5a83ea7d87d1139", "Build")})