-
Couldn't load subscription status.
- Fork 13
Support conditional deps using "depends on A if B" #21
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
base: main
Are you sure you want to change the base?
Support conditional deps using "depends on A if B" #21
Conversation
Extend the "depends on" syntax to support conditional dependencies using "depends on A if B". While functionally equivalent to "depends on !B || A", "depends on A if B" is much more readable. This change is implemented by converting the "A if B" syntax into the "!B || A" syntax during "depends on" token processing. Signed-off-by: Graham Roff <[email protected]>
|
It doesn't look like this is a 'standard' kconfig language feature: Can you justify why it's worth an extension? https://docs.zephyrproject.org/latest/build/kconfig/extensions.html |
|
You are right that this would be a minor extension to the kconfig language. It has already been proposed as an update to the spec but it looks like the patch was not followed up on (https://lwn.net/Articles/818502/) after some initial discussion. I can see a number of places in Zephyr where this would make the intended dependency a lot easier to understand. Some examples: Kconfig.zephyr: subsys/bluetooth/host/Kconfig: drivers/bluetooth/hci/Kconfig: drivers/ethernet/Kconfig.dwmac: |
|
The language itself acknowledges that expressing conditional dependencies is confusing: https://docs.kernel.org/kbuild/kconfig-language.html#optional-dependencies |
Very interesting, thanks for the reference. I think this makes sense as an extension -- @carlescufi @nashif @tejlmand @kartben thoughts? |
|
@grahamroff-dev I'm assuming that if this is merged and pulled into Zephyr, you would be willing to update the zephyr documentation for kconfig to list this as an additional extension, right? Edit: a couple of additional thoughts if we decide to accept this:
|
this is raising alarm bells for me. regardless of the decision to support the syntax or not, this implementation is a hack and I am afraid it will be a technical debt at best or buggy with all sorts of unexpected edge cases at worst. Obviously, testing is needed to be added for this, but I am not sure if it is worth it, if it's already possible to specify this logic. I would prefer not to add yet another surface area for bugs, the build tooling is already complex enough with endless amounts of trickery as it is |
|
Dependencies that take the form "A depends on B if C" are a design flaw, as they are a laying violation. A module can depend on another module, that is, "A depends on B". B must provide an interface which fulfills B, that is, no matter what other options are selected, B must always provide B. The form "A depends on B if C" can not fulfill this promise, as this indicate that C would modify B, that is not allowed. How would any other module which depends on B, deal with B suddenly providing a different promise, based on what should be a completely unrelated option? Take the example |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment
|
I actually had this discussion with @tejlmand recently w.r.t. one of the Bluetooth specifications. Here's an example of a set of conditional dependencies from the Common Audio Profile that use the language "Mandatory if X is supported" syntax
|
|
I want to clarify that this change is not adding additional capability to the dependency system in Kconfig. It is already possible, and done in many places (I listed a few above), to logically have a conditional dependency using the syntactically confusing (!B || A). The purpose of this change is to allow expressing this in a more readable way as "A if B". I do not believe the implementation is a hack, it is a clean and simple way to handle this syntax feature.
I believe this is a misinterpretation of what the conditional is implying. B always provides the same capabilities (C does not modify B or is even related to B necessarily) - but those capabilities are only required by A when C is also selected. I agree that such dependencies should be examined carefully to make sure the code design is logical, but it would not always be a layering violation to have them (as I believe the examples above indicate). I can certainly update the documentation and provide test cases in whatever location such things are hosted for the Zephyr scripting tools. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extend the "depends on" syntax to support conditional dependencies using "depends on A if B". While functionally equivalent to "depends on !B || A", "depends on A if B" is much more readable.
you're changing the meaning of if and depends on for the language.
Which again gives me the impression that the spec itself has not been read, meaning risk of bugs / unintended side-effect and thus tech debt increases.
Regarding depends on then the spec states:
- dependencies:
depends on <expr>This defines a dependency for this menu entry. If multiple dependencies are defined, they are connected with ‘&&’. Dependencies are applied to all other options within this menu entry (which also accept an “if” expression), so these two examples are equivalent:
bool "foo" if BAR default y if BARand:
depends on BAR bool "foo" default y
based on above, then allowing the construct depends on BAR if BAZ would require it to be equivalent to:
bool "foo" if BAR if BAZ
default y if BAR if BAZ
which syntactically would be wrong, whereas today's construct of depends on BAR || !BAZ is valid:
bool "foo" if BAR || !BAZ
default y if BAR || !BAZ
Ref: https://docs.kernel.org/kbuild/kconfig-language.html#menu-attributes
|
The conditional dependency should be defined as: So it is the Looking at your example (which technically has the order swapped for the two arguments), I would argue that Is a lot less readable than: Both express the same thing logically and evaluate to the same result, but one is much simpler to understand. |
"my" example is based on the specification which states that the With your proposed change, then the The equivalent to you would need to write another form, such as: but There is another long form alternative version, such as: but both forms removes the straight forward relationship between The Kconfig specification itself lives in Linux kernel project, and we follow that specification. Examples
|
This is the objection that I was expecting in the first place ;) I believe that the specification itself is lacking in not supporting this construct. All other elements support a trailing "if " except "depends on", their documentation indicates that conditional dependencies are confusing to represent (see link above), and many examples exist in Zephyr (have not looked in Linux) where such a conditional dependency exists and has to be expressed in the confusing syntax (BT folks even chimed in above that this syntax would be preferred as it aligns with their specification). If I am understanding the main objection, it is that such a change is not just a simple extension of the specification, but to some degree "breaks" it by implying a syntax of
Or something along those lines at least. I fully understand not wanting to take such a change if the source-of-truth reference spec does not support it, so the next step would be to suggest it to the Kconfig maintainer in Linux to get their feedback. Do folks here see value in trying to do that, or are the objections to this update more fundamental than just a spec violation? At the end of the day, I believe the patch provides a fully functional implementation of a logically intuitive and consistent syntax update - minus the actual spec update ;). If anyone has examples of some construct that does not behave logically, let me know and I can test them out (I have extensive tests for this). |
that was the objection I gave in the first comment here: #21 (review)
I even copied the text and link to the Zephyr kernel Kconfig language specification, including the text
Except that it's not only the text part, but you also need to consider the part regarding
And what about this example: with your proposed text, then Sure you can write your way out of that, but end-result goes from a very short text with a very easy to understand equivalent example today to something more complex. Personally when you get to more complex scenarios, then it's easier to concatenate deps directly in mind with this: to become
Sure, feel free to propose it upstream, that would be the correct place to start out. |

Extend the "depends on" syntax to support conditional dependencies using "depends on A if B". While functionally equivalent to "depends on !B || A", "depends on A if B" is much more readable.
This change is implemented by converting the "A if B" syntax into the "!B || A" syntax during "depends on" token processing.