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

fix propagation of options like *:shared=True defined in recipes #13855

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
6 changes: 4 additions & 2 deletions conans/model/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,10 @@ def get_upstream_options(self, down_options, own_ref, is_consumer):
upstream_options = Options()
for pattern, options in down_options._deps_package_options.items():
if ref_matches(own_ref, pattern, is_consumer=is_consumer):
# Remove the exact match to this package, don't further propagate up
continue
# Remove the exact match-name to this package, don't further propagate up
pattern_name = pattern.split("/", 1)[0]
if "*" not in pattern_name:
continue
self._deps_package_options.setdefault(pattern, _PackageOptions()).update_options(options)

upstream_options._deps_package_options = self._deps_package_options
Expand Down
121 changes: 121 additions & 0 deletions conans/test/integration/options/options_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,3 +505,124 @@ def configure(self):
assert "dep2/1.0: SHARED: True!!" in c.out
assert "dep3/1.0: SHARED: True!!" in c.out
assert "dep4/1.0: SHARED: True!!" in c.out


class TestTransitiveOptionsShared:
"""
https://github.com/conan-io/conan/issues/13854
"""
@pytest.fixture()
def client(self):
c = TestClient()
c.save({"toollib/conanfile.py": GenConanfile("toollib", "0.1").with_shared_option(False),
"tool/conanfile.py": GenConanfile("tool", "0.1").with_shared_option(False)
.with_requires("toollib/0.1"),
"dep2/conanfile.py": GenConanfile("dep2", "0.1").with_shared_option(False)
.with_tool_requires("tool/0.1"),
"dep1/conanfile.py": GenConanfile("dep1", "0.1").with_shared_option(False)
.with_requires("dep2/0.1"),
"pkg/conanfile.py": GenConanfile("pkg", "0.1").with_shared_option(False)
.with_requires("dep1/0.1"),
"app/conanfile.txt": "[requires]\npkg/0.1"})
c.run("export toollib")
c.run("export tool")
c.run("export dep2")
c.run("export dep1")
c.run("export pkg")
return c

@staticmethod
def check(client):
# tools and libs in build context do not get propagated the options
for dep in ("toollib", "tool"):
client.run(f"list {dep}/*:*")
assert "shared: False" in client.out
# But the whole host context does
for dep in ("dep1", "dep2", "pkg"):
client.run(f"list {dep}/*:*")
assert "shared: True" in client.out

def test_transitive_options_shared_cli(self, client):
client.run("install app --build=missing -o *:shared=True")
self.check(client)

def test_transitive_options_shared_profile(self, client):
client.save({"profile": "[options]\n*:shared=True"})
client.run("install app --build=missing -pr=profile")
self.check(client)

def test_transitive_options_conanfile_txt(self, client):
client.save({"app/conanfile.txt": "[requires]\npkg/0.1\n[options]\n*:shared=True\n"})
client.run("install app --build=missing")
self.check(client)

def test_transitive_options_conanfile_py(self, client):
client.save({"app/conanfile.py": GenConanfile().with_requires("pkg/0.1")
.with_default_option("*:shared", True)})
client.run("install app/conanfile.py --build=missing")
self.check(client)

def test_transitive_options_conanfile_py_create(self, client):
conanfile = GenConanfile("app", "0.1").with_requires("pkg/0.1") \
.with_default_option("*:shared", True)
client.save({"app/conanfile.py": conanfile})
client.run("create app --build=missing")
self.check(client)


class TestTransitiveOptionsSharedInvisible:
"""
https://github.com/conan-io/conan/issues/13854
When a requirement is visible=False
"""
@pytest.fixture()
def client(self):
c = TestClient()
c.save({"dep2/conanfile.py": GenConanfile("dep2", "0.1").with_shared_option(False),
"dep1/conanfile.py": GenConanfile("dep1", "0.1").with_shared_option(False)
.with_requirement("dep2/0.1",
visible=False),
"pkg/conanfile.py": GenConanfile("pkg", "0.1").with_shared_option(False)
.with_requires("dep1/0.1"),
"app/conanfile.txt": "[requires]\npkg/0.1"})
c.run("export dep2")
c.run("export dep1")
c.run("export pkg")
return c

@staticmethod
def check(client, value):
for dep in ("dep1", "pkg"):
client.run(f"list {dep}/*:*")
assert f"shared: True" in client.out

# dep2 cannot be affected from downstream conanfile consumers options, only from profile
client.run(f"list dep2/*:*")
assert f"shared: {value}" in client.out

def test_transitive_options_shared_cli(self, client):
client.run("install app --build=missing -o *:shared=True")
self.check(client, True)

def test_transitive_options_shared_profile(self, client):
client.save({"profile": "[options]\n*:shared=True"})
client.run("install app --build=missing -pr=profile")
self.check(client, True)

def test_transitive_options_conanfile_txt(self, client):
client.save({"app/conanfile.txt": "[requires]\npkg/0.1\n[options]\n*:shared=True\n"})
client.run("install app --build=missing")
self.check(client, False)

def test_transitive_options_conanfile_py(self, client):
client.save({"app/conanfile.py": GenConanfile().with_requires("pkg/0.1")
.with_default_option("*:shared", True)})
client.run("install app/conanfile.py --build=missing")
self.check(client, False)

def test_transitive_options_conanfile_py_create(self, client):
conanfile = GenConanfile("app", "0.1").with_requires("pkg/0.1") \
.with_default_option("*:shared", True)
client.save({"app/conanfile.py": conanfile})
client.run("create app --build=missing")
self.check(client, False)