-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Proof of concept of adding options per-requirement #10112
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
Merged
memsharded
merged 12 commits into
conan-io:develop2
from
memsharded:feature/develop2_build_requires_options
Dec 13, 2021
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
13f5082
proof of concept of adding options per-requirement
memsharded c663260
Merge branch 'develop2' into feature/develop2_build_requires_options
memsharded 03b2549
review
memsharded 2f4d14a
add test docstrings
memsharded b7d6f3e
Merge branch 'develop2' into feature/develop2_build_requires_options
memsharded e0a0598
wip
memsharded b6c1c67
wip
memsharded 343c389
Merge branch 'develop2' into feature/develop2_build_requires_options
memsharded b7dfbf9
apply visible=True option
memsharded a35857b
adding graph tests for visible=False not overriden, not forced
memsharded 967eb2e
merged develop2
memsharded 5bcc32d
review
memsharded File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
conans/test/integration/options/test_options_build_requires.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import textwrap | ||
|
|
||
| from conans.test.assets.genconanfile import GenConanfile | ||
| from conans.test.utils.tools import TestClient | ||
|
|
||
|
|
||
| def test_build_requires_options_different(): | ||
| # copied from https://github.com/conan-io/conan/pull/9839 | ||
| client = TestClient() | ||
|
|
||
| conanfile_openssl_1_1_1 = GenConanfile("openssl", "1.1.1") | ||
| conanfile_openssl_3_0_0 = GenConanfile("openssl", "3.0.0") \ | ||
| .with_option("no_fips", [True, False]) \ | ||
| .with_default_option("no_fips", True) | ||
| conanfile_cmake = GenConanfile("cmake", "0.1") \ | ||
| .with_requires("openssl/1.1.1") | ||
| conanfile_consumer = GenConanfile("consumer", "0.1") \ | ||
| .with_build_requires("cmake/0.1") \ | ||
| .with_requires("openssl/3.0.0") | ||
|
|
||
| client.save({"openssl_1_1_1.py": conanfile_openssl_1_1_1, | ||
| "openssl_3_0_0.py": conanfile_openssl_3_0_0, | ||
| "conanfile_cmake.py": conanfile_cmake, | ||
| "conanfile.py": conanfile_consumer}) | ||
|
|
||
| client.run("create openssl_1_1_1.py") | ||
| client.run("create openssl_3_0_0.py") | ||
| client.run("create conanfile_cmake.py") | ||
| client.run("install conanfile.py") | ||
|
|
||
|
|
||
| def test_different_options_values(): | ||
| c = TestClient() | ||
| protobuf = textwrap.dedent(""" | ||
| from conans import ConanFile | ||
| class Proto(ConanFile): | ||
| options = {"shared": [True, False]} | ||
| default_options = {"shared": False} | ||
|
|
||
| def package_info(self): | ||
| self.output.info("MYOPTION: {}-{}".format(self.context, self.options.shared)) | ||
| """) | ||
|
|
||
| c.save({"protobuf/conanfile.py": protobuf, | ||
| "consumer/conanfile.py": GenConanfile().with_requires("protobuf/1.0") | ||
| .with_build_requires("protobuf/1.0")}) | ||
|
|
||
| c.run("create protobuf protobuf/1.0@") | ||
| c.run("create protobuf protobuf/1.0@ -o protobuf:shared=True") | ||
| c.run("install consumer") | ||
| assert "protobuf/1.0: MYOPTION: host-False" in c.out | ||
| assert "protobuf/1.0: MYOPTION: build-False" in c.out | ||
| # specifying it in the profile works | ||
| c.run("install consumer -o protobuf:shared=True") | ||
| assert "protobuf/1.0: MYOPTION: host-True" in c.out | ||
| assert "protobuf/1.0: MYOPTION: build-False" in c.out | ||
| c.run("install consumer -o protobuf:shared=True -o:b protobuf:shared=False") | ||
| assert "protobuf/1.0: MYOPTION: host-True" in c.out | ||
| assert "protobuf/1.0: MYOPTION: build-False" in c.out | ||
| c.run("install consumer -o protobuf:shared=False -o:b protobuf:shared=True") | ||
| assert "protobuf/1.0: MYOPTION: host-False" in c.out | ||
| assert "protobuf/1.0: MYOPTION: build-True" in c.out | ||
| c.run("install consumer -o:b protobuf:shared=True") | ||
| assert "protobuf/1.0: MYOPTION: host-False" in c.out | ||
| assert "protobuf/1.0: MYOPTION: build-True" in c.out | ||
|
|
||
|
|
||
| def test_different_options_values_recipe(): | ||
| c = TestClient() | ||
| protobuf = textwrap.dedent(""" | ||
| from conans import ConanFile | ||
| class Proto(ConanFile): | ||
| options = {"shared": [True, False]} | ||
| default_options = {"shared": False} | ||
|
|
||
| def package_info(self): | ||
| self.output.info("MYOPTION: {}-{}".format(self.context, self.options.shared)) | ||
| """) | ||
| consumer_recipe = textwrap.dedent(""" | ||
| from conans import ConanFile | ||
| class Consumer(ConanFile): | ||
| def requirements(self): | ||
| self.requires("protobuf/1.0", options={{"protobuf:shared": {host}}}) | ||
| def build_requirements(self): | ||
| self.build_requires("protobuf/1.0", options={{"protobuf:shared": {build}}}) | ||
| """) | ||
| c.save({"conanfile.py": protobuf}) | ||
|
|
||
| c.run("create . protobuf/1.0@") | ||
| c.run("create . protobuf/1.0@ -o protobuf:shared=True") | ||
|
|
||
| for host, build in ((True, True), (True, False), (False, True), (False, False)): | ||
| c.save({"conanfile.py": consumer_recipe.format(host=host, build=build)}) | ||
| c.run("install .") | ||
| assert f"protobuf/1.0: MYOPTION: host-{host}" in c.out | ||
| assert f"protobuf/1.0: MYOPTION: build-{build}" in c.out | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.