-
Notifications
You must be signed in to change notification settings - Fork 992
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
[question] Force option values on requirements #15519
Comments
Hi @frogarian Thanks for your question.
Yes, packages can validate that the options of their dependencies are the correct ones in their In general the recommendation are:
|
I understand this point when the more downstream consumer actually sets a different value for the option. |
Yes, it is true, the first one requiring the package will define its set of options.
We have this ticket to investigate this: #14764. I think it would be mostly what you are asking for here, so maybe we can close this ticket and follow up there. The main issue is that it is not evident. While it seems that it is desired to be able that some recipe "forces" some option of the dependency, this also brings extreme confusion and frustration when users try to define the value of that option in their command line or in their |
I get your point but to me the way it is now in Conan 2 might also lead to confusion. To the user it is not evident which package is the first to require some other package and thereby define its options. And since defining them is just a suggestion, it seems more or less useless in those cases where a dependency is injected from multiple packages. If on the other hand a user is able to force the option into the graph you might be able to output this to the user and it is at the very least visible in the recipe. Regarding your feature request I'm not sure if this actually covers my problem. In our case for example we have, amongst others, two packages Hope this example demonstrates our dilemma a little better. I'm not sure if this is unique for our use case or why this didn't come up already, but sadly for our case this is really a step back compared to Conan v1. |
The problem is that Conan 1.X had some important bugs in this regard with the graph expansion. Maybe they were not hitting you, as it worked well for some cases, but it was a nightmare in many others, it was mostly flawed. Any package that had conditional requirements based on options and these options would be defined from different consumer packages would easily lead to broken dependency graphs, but in so subtle ways that it could takes tons of time to debug and understand what was happening. Let me put a real example in form of a failing test in Conan 1.X to demonstrate one of the issues: def test_qt():
c = TestClient()
qt = textwrap.dedent("""
from conan import ConanFile
class Qt(ConanFile):
name = "qt"
version = "0.1"
options = {"ssl": [False, True]}
default_options = {"ssl": False}
def requirements(self):
if self.options.ssl:
self.requires("openssl/0.1")
""")
c.save({"openssl/conanfile.py": GenConanfile("openssl", "0.1"),
"qt/conanfile.py": qt,
"sub1/conanfile.py": GenConanfile("sub1", "0.1").with_requires("qt/0.1"),
"sub2/conanfile.py": GenConanfile("sub2", "0.1").with_requires("qt/0.1")
.with_default_option("qt*:ssl", True),
"app/conanfile.py": GenConanfile("app", "0.1").with_requires("sub1/0.1", "sub2/0.1")
})
c.run("create openssl")
c.run("export qt")
c.run("export sub1")
c.run("export sub2")
c.run("install app --build=missing")
print(c.out)
assert "openssl" in c.out # This fails, openssl not there! Even if The only approach that we found that can be managed easily and consistently is defining the optionality in one place. Either in the upstream recipe, in this case |
But isn't this test case failing in Conan v2 as well? |
Sure. The recommendation for defining options is to centralize it in the dependency recipe or in profiles, both in 1.X and 2.0. Trying to distribute options definitions among multiple recipes in the graph is problematic both in 1.X and 2.0, it is an intrinsic problem of decentralization of information in something that doesn't evaluate linearly, like a graph. |
Ok, so it seems that until now with Conan v1 we just got lucky that it somehow worked out for us and with Conan v2 we finally have to stick to those rules. Thanks for clarifying this. |
I am submitting #15571, that is marking this question to be closed. This addresses some of the issues related to this question. But I have been revisiting the "diamond" problem with different options being assigned in different branches, and it is really a challenging problem, that would require a completely different graph computation algorithm, way more costly and slower (requires back-tracking and constant re-evaluation of the graph, increasing from linear to at least polynomial). So the above recommendations are still valid. Thanks for the feedback! |
Closed by #15571, it will be included in next release, but it is possible that initially as undocumented, to see if it could be breaking something first, then document in later future releases. |
What is your question?
The Documentation of the
configure()
method (https://docs.conan.io/2/reference/conanfile/methods/configure.html) states the following:Is there any chance to force an option onto a dependency. Or at least automatically check if the set option was actually used?
In our case we have several libraries, all depending on Qt. Some of them need specific modules of Qt, so they configure those in their recipe. But this only seems to have an effect in some cases, totally not obvious when.
Have you read the CONTRIBUTING guide?
The text was updated successfully, but these errors were encountered: