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

Apply general scope options to consumer Conanfile first #3361

Merged
merged 4 commits into from
Aug 22, 2018
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
1 change: 1 addition & 0 deletions conans/client/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def load_conan(self, conanfile_path, output, consumer=False, reference=None, loc
result._env_values.update(self._env_values)

if consumer:
self._user_options[result.name].update(self._user_options["*"])
self._user_options.descope_options(result.name)
result.options.initialize_upstream(self._user_options, local=local)
self._user_options.clear_unscoped_options()
Expand Down
5 changes: 2 additions & 3 deletions conans/model/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,8 @@ def propagate_upstream(self, package_values, down_ref, own_ref, pattern_options)


class Options(object):
""" all options of a package, both its own options and the upstream
ones.
Owned by conanfile
""" All options of a package, both its own options and the upstream ones.
Owned by ConanFile.
"""
def __init__(self, options):
assert isinstance(options, PackageOptions)
Expand Down
56 changes: 56 additions & 0 deletions conans/test/integration/options_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,59 @@ class ConanLib(ConanFile):
client.user_io.out)
conaninfo = load(os.path.join(client.current_folder, CONANINFO))
self.assertNotIn("zlib:shared=True", conaninfo)

def general_scope_options_test(self):
# https://github.com/conan-io/conan/issues/2538
client = TestClient()
conanfile_libA = """
from conans import ConanFile

class LibA(ConanFile):
name = "libA"
version = "0.1"
options = {"shared": [True, False]}
default_options= "shared=False"

def configure(self):
self.output.info("shared=%s" % self.options.shared)
"""
conanfile_libB = """
from conans import ConanFile

class LibB(ConanFile):
name = "libB"
version = "0.1"
options = {"shared": [True, False]}
default_options= "shared=False"
requires = "libA/0.1@danimtb/testing"

def configure(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test looks a bit complex for the use case. Just defining -o *:shared in the command line should be enough to check it, wouldn't it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. this is in fact the real issue this is testing. Read the description in the PR comments

self.options["*"].shared = self.options.shared
self.output.info("shared=%s" % self.options.shared)
"""
client.save({"conanfile_liba.py": conanfile_libA,
"conanfile_libb.py": conanfile_libB})

for without_configure_line in [True, False]:
client.save({"conanfile_liba.py": conanfile_libA})

if without_configure_line:
client.save({"conanfile_libb.py": conanfile_libB.replace(
" self.options[\"*\"].shared = self.options.shared", "")})
else:
client.save({"conanfile_libb.py": conanfile_libB})

# Test info
client.run("export conanfile_liba.py danimtb/testing")
client.run("info conanfile_libb.py -o *:shared=True")
self.assertIn("PROJECT: shared=True", client.out)
self.assertIn("libA/0.1@danimtb/testing: shared=True", client.out)
# Test create
client.run("create conanfile_liba.py danimtb/testing -o *:shared=True")
client.run("create conanfile_libb.py danimtb/testing -o *:shared=True")
self.assertIn("libB/0.1@danimtb/testing: shared=True", client.out)
self.assertIn("libA/0.1@danimtb/testing: shared=True", client.out)
# Test install
client.run("install conanfile_libb.py -o *:shared=True")
self.assertIn("PROJECT: shared=True", client.out)
self.assertIn("libA/0.1@danimtb/testing: shared=True", client.out)