summaryrefslogtreecommitdiff
path: root/examples/merge_config.py
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2019-06-02 18:15:59 +0200
committerUlf Magnusson <ulfalizer@gmail.com>2019-06-03 06:50:06 +0200
commit55bc8c380869ea663092212e8fe388ad7abae596 (patch)
tree200d557c614845bd017de4e411c66c5c0b19fae5 /examples/merge_config.py
parent455e3661c6f50b088b35a3b2662052e7e2a24769 (diff)
Have load_config() and write_(min_)config() return messages
Hardcoding load_config() and write_(min_)config() to write any message to stdout is awkward, because it means that the message can't be easily reused when stdout is the wrong place to write it to (e.g. in menuconfig/guiconfig). This gets extra bad now that there's also the "No change to ..." message. Modify load_config() and write_(min_)config() to return the message as a string instead, and have them always return a message, instead of just when 'filename' is None and verbose=True. This makes things flexible and straightforward. Use the new behavior in menuconfig.py and guiconfig.py. They now show "No change to ..." when saving a file doesn't modify it. Tools that want to write messages to stdout should now do print(kconf.load_config()) / print(kconf.write_config()). There's no clean way to preserve perfect backwards compatibility here, but keep accepting the 'verbose' argument and print a deprecation warning if a value is ever passed for it. That way, scripts will keep running, though possibly with less output on stdout. This changes the meaning of the load_config() return value as well, though I suspect it was only ever used by the menuconfig/guiconfig interfaces. The new behavior applies for kconfiglib.VERSION >= (12, 0, 0).
Diffstat (limited to 'examples/merge_config.py')
-rwxr-xr-x[-rw-r--r--]examples/merge_config.py28
1 files changed, 19 insertions, 9 deletions
diff --git a/examples/merge_config.py b/examples/merge_config.py
index ec022d5..6f60375 100644..100755
--- a/examples/merge_config.py
+++ b/examples/merge_config.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python
+
# This script functions similarly to scripts/kconfig/merge_config.sh from the
# kernel tree, merging multiple configurations fragments to produce a complete
# .config, with unspecified values filled in as for alldefconfig.
@@ -37,7 +39,8 @@
#
# conf3 contents:
#
-# # Ops... assigned twice
+# # Assigned twice (would generate warning if 'warn_assign_override' was
+# # True)
# # CONFIG_FOO is not set
#
# # Ops... this symbol doesn't exist
@@ -54,15 +57,20 @@
# Running:
#
# $ python(3) merge_config.py Kconfig merged conf1 conf2 conf3 conf4
-# conf3:2: warning: FOO (defined at Kconfig:1) set more than once. Old value: "y", new value: "n".
-# conf3:5: warning: attempt to assign the value "y" to the undefined symbol OPS
-# warning: QAZ (defined at Kconfig:10) was assigned the value "y" but got the value "n" -- check dependencies
+# Merged configuration 'conf1'
+# Merged configuration 'conf2'
+# conf3:5: warning: attempt to assign the value 'y' to the undefined symbol OPS
+# Merged configuration 'conf3'
+# Merged configuration 'conf4'
+# Configuration saved to 'merged'
+# warning: QAZ (defined at Kconfig:10) was assigned the value 'y' but got the value 'n' -- check dependencies
# $ cat merged
# Generated by Kconfiglib (https://github.com/ulfalizer/Kconfiglib)
# # CONFIG_FOO is not set
# CONFIG_BAR=y
# CONFIG_BAZ="baz string"
+from __future__ import print_function
import sys
from kconfiglib import Kconfig, BOOL, TRISTATE, TRI_TO_STR
@@ -86,12 +94,13 @@ kconf.enable_undef_warnings()
kconf.disable_override_warnings()
kconf.disable_redun_warnings()
-# Create a merged configuration by loading the fragments with replace=False
+# Create a merged configuration by loading the fragments with replace=False.
+# load_config() and write_config() returns a message to print.
for config in sys.argv[3:]:
- kconf.load_config(config, replace=False)
+ print(kconf.load_config(config, replace=False))
# Write the merged configuration
-kconf.write_config(sys.argv[2])
+print(kconf.write_config(sys.argv[2]))
# Print warnings for symbols whose actual value doesn't match the assigned
# value
@@ -119,5 +128,6 @@ for sym in kconf.defined_syms:
if user_value != sym.str_value:
print("warning: {} was assigned the value '{}' but got the "
- "value '{}' -- check dependencies"
- .format(name_and_loc(sym), user_value, sym.str_value))
+ "value '{}' -- check dependencies".format(
+ name_and_loc(sym), user_value, sym.str_value),
+ file=sys.stderr)