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 -o &:option=value wildcard for consumer #9316

Merged
merged 3 commits into from Aug 31, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion conans/model/options.py
Expand Up @@ -631,7 +631,8 @@ def initialize_upstream(self, user_values, name=None):
# This code is necessary to process patterns like *:shared=True
# To apply to the current consumer, which might not have name
for pattern, pkg_options in sorted(user_values._reqs_options.items()):
if fnmatch.fnmatch(name or "", pattern):
# pattern = & means the consumer, irrespective of name
if fnmatch.fnmatch(name or "", pattern) or pattern == "&":
self._package_options.initialize_patterns(pkg_options)
# Then, the normal assignment of values, which could override patterns
self._package_options.values = user_values._package_values
Expand Down
25 changes: 18 additions & 7 deletions conans/test/functional/configuration/profile_test.py
Expand Up @@ -685,35 +685,44 @@ def test_profile_from_temp_absolute_path():

def test_consumer_specific_settings():
client = TestClient()
dep = str(GenConanfile().with_settings("build_type"))
dep = str(GenConanfile().with_settings("build_type").with_option("shared", [True, False])
.with_default_option("shared", False))
configure = """
def configure(self):
self.output.warn("I'm {} and my build type is {}".format(self.name,
self.settings.build_type))
self.output.warn("I'm {} and my shared is {}".format(self.name, self.options.shared))
"""
dep += configure
client.save({"conanfile.py": dep})
client.run("create . dep/1.0@")
client.run("create . dep/1.0@ -s build_type=Debug")
client.run("create . dep/1.0@ -s build_type=Debug -o dep:shared=True")

consumer = str(GenConanfile().with_settings("build_type").with_requires("dep/1.0"))
consumer = str(GenConanfile().with_settings("build_type").with_requires("dep/1.0")
.with_option("shared", [True, False]).with_default_option("shared", False))
consumer += configure
client.save({"conanfile.py": consumer})

# Regular install with release
client.run("install . -s build_type=Release")
assert "I'm dep and my build type is Release" in client.out
assert "I'm None and my build type is Release" in client.out
assert "I'm dep and my shared is False" in client.out
assert "I'm None and my shared is False" in client.out

# Now the dependency by name
client.run("install . -s dep:build_type=Debug")
client.run("install . -s dep:build_type=Debug -o dep:shared=True")
assert "I'm dep and my build type is Debug" in client.out
assert "I'm None and my build type is Release" in client.out
assert "I'm dep and my shared is True" in client.out
assert "I'm None and my shared is False" in client.out

# Now the consumer using &
client.run("install . -s &:build_type=Debug")
client.run("install . -s &:build_type=Debug -o &:shared=True")
assert "I'm dep and my build type is Release" in client.out
assert "I'm None and my build type is Debug" in client.out
assert "I'm dep and my shared is False" in client.out
assert "I'm None and my shared is True" in client.out

# Now use a conanfile.txt
client.save({"conanfile.txt": textwrap.dedent("""
Expand All @@ -726,15 +735,17 @@ def configure(self):
assert "I'm dep and my build type is Release" in client.out

# Now the dependency by name
client.run("install . -s dep:build_type=Debug")
client.run("install . -s dep:build_type=Debug -o dep:shared=True")
assert "I'm dep and my build type is Debug" in client.out
assert "I'm dep and my shared is True" in client.out

# Test that the generators take the setting
if platform.system() != "Windows": # Toolchain in windows is multiconfig
# Now the consumer using &
client.run("install . -s &:build_type=Debug -g CMakeToolchain")
client.run("install . -s &:build_type=Debug -g CMakeToolchain")
assert "I'm dep and my build type is Release" in client.out
# Verify the cmake toolchain takes Debug
assert "I'm dep and my shared is False" in client.out
contents = client.load("conan_toolchain.cmake")
assert 'set(CMAKE_BUILD_TYPE "Debug"' in contents

Expand Down