-
Notifications
You must be signed in to change notification settings - Fork 7.5k
[kconfig] Allow user-input when new options are detected #5426
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
Comments
This is no longer the case with
|
Right now our script ignores the current |
@carlescufi There's some usability issues here in that you can't give a I'm thinking of allowing diff --git a/scripts/kconfig/kconfig.py b/scripts/kconfig/kconfig.py
index de8316556..4a020c5a1 100755
--- a/scripts/kconfig/kconfig.py
+++ b/scripts/kconfig/kconfig.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
# Modified from: https://github.com/ulfalizer/Kconfiglib/blob/master/examples/merge_config.py
-from kconfiglib import Kconfig, Symbol, BOOL, STRING, TRISTATE, TRI_TO_STR
+from kconfiglib import Kconfig, Symbol, BOOL, STRING, TRISTATE, TRI_TO_STR, \
+ STR_TO_STRI
import sys
if len(sys.argv) < 5:
@@ -25,6 +26,40 @@ for config in sys.argv[5:]:
for config in sys.argv[4:]:
kconf.load_config(config, replace=False)
+# Look for new modifiable symbols and prompt the user for a value for them,
+# oldconfig-style
+for sym in kconf.defined_syms:
+ if sym.user_value is None and sym.visibility:
+ if len(sym.assignable) == 1:
+ # Skip bool/tristate symbols that are already locked to a
+ # particular value through a select
+ continue
+
+ # Loop until the user enters a valid value or a blank string (for the
+ # default value)
+ while True:
+ prompt = "Value for new symbol {} (".format(sym.name)
+ if sym.type in (BOOL, TRISTATE):
+ prompt += "available: {}, ".format(
+ ", ".join([TRI_TO_STR[val] for val in sym.assignable]))
+ prompt += "default '{}'): ".format(sym.str_value)
+
+ # If the user enters a blank value, use the default value
+ val_str = input(prompt) or sym.str_value
+
+ if sym.type in (BOOL, TRISTATE):
+ if val_str in STR_TO_TRI and \
+ sym.set_value(STR_TO_TRI[val_str]):
+ # Valid value input
+ break
+ else:
+ if sym.set_value(val_str):
+ # Valid value input
+ break
+
+ # Invalid value input, loop
+ print("Invalid value -- try again")
+
# Write the merged configuration
kconf.write_config(sys.argv[2])
|
@ulfalizer thanks for the input and code.
Understood, but for that
first to load that |
@carlescufi To check for and load an existing if os.path.exists(".config"):
kconf.load_config(".config")
else:
# Load fragments... Maybe I'm misunderstanding the model you have in mind though. |
@ulfalizer No, I don't think you're misunderstanding, it's just that before switching to Python we seem to have been using the
|
@carlescufi Yep, with that change, it should respect an existing |
@ulfalizer I tried running your patch on a completely clean build but I got asked about values that should default to "n" automatically (no default implies "n" AFAIK), such as this which should simply default to "n". |
@carlescufi That matches the |
There's also |
Right, but what I see now is that if it's say an
instead of prompting the user. So I guess what we would need is something aking to EDIT: in fact I just checked and before switching to Python we used to invoke |
Hmm... that shouldn't happen. Here's a test Kconfig:
When I run the script against that with an empty
The final
|
@ulfalizer I meant it happens in the current vanilla Zephyr tree without the snippet here. Maybe it's not quite clear, but what I'm trying to replicate here is the old behavior where:
I assume the description above fits our previous |
Getting pretty deep in Kconfig arcana, but you can end up with When writing out a new Kconfiglib works exactly like the C implementation when it comes to these things. Need that to generate the same |
@carlescufi This should work in order to get that behavior: if os.path.exists(".config"):
kconf.load_config(".config")
# Do the new oldconfig stuff
...
else:
# Load fragments... (this implicitly works like olddefconfig due to normal Kconfig semantics)
|
|
To clarify, when writing out a So simply doing |
@carlescufi And yeah, running the |
Implements the standard 'make oldconfig' functionality, prompting the user for the values of new symbols to update an old .config file. This came up in zephyrproject-rtos/zephyr#5426.
Hello, I spent some time implementing a more robust You might want to drop the script alongside from oldconfig import do_oldconfig
...
do_oldconfig(kconf) I added a small bonus feature as well: Inputting '??' as the value displays the Kconfig help text of the item. Don't think that's a value that's very likely to come up in practice... |
@ulfalizer wow that is a lot of info to digest and try :) I will do that and submit a PR to Zephyr with all this in mind. I think we had a strange hybrid of |
I just made I also simplified oldconfig.py by making use of that, so you will need to add that Kconfiglib commit for the latest version of No other example-breaking updates planned for now. :) On an unrelated note, I updated merge_config.py so that it prints the symbol location(s) in the warning about the assigned value not matching the final value. |
@ulfalizer thanks! Now that we have an "official" fork under the zephyrproject-rtos user it makes it easier for me to rebase. Will do that and then continue with related oldconfig work. |
Closing this since in Zephyr we have settled on considering |
When Kbuild detected that new kconfig options were introduced to an existing project it would prompt the user for what he wanted to do with these new options.
CMake does not support this, new options will result in Kconfig aborting.
CMake needs to deal with this use-case in a more graceful way. It is not clear how though,
the straightforward solution would be to mimic Kbuild and accept user-input when new options
are detected. But it is not clear if Kbuild's behaviour is the desired behaviour.
The text was updated successfully, but these errors were encountered: