summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2018-02-07 05:00:56 +0100
committerUlf Magnusson <ulfalizer@gmail.com>2018-02-07 05:10:25 +0100
commit7cdfe6dda5435e85aec2ab0410d58fcae6ae4071 (patch)
treebae955fbd7742ef656281be12ee3de3a58d669a2 /examples
parent4b31adf8efbb5341c369b32022401df65f419362 (diff)
Give symbol locations in merge_config.py warnings
Helpful for debugging. Piggyback some small fixes: - Don't imply that merge_config.py is an executable file or that it only runs under Python 3. Remove the hashbang line and fix the example in the overview. - Add some #'s to the overview .config files that had accidentally been left out. - Fix a questionable sentence in oldconfig.py's name_and_loc_str() docstring.
Diffstat (limited to 'examples')
-rw-r--r--examples/merge_config.py29
-rw-r--r--examples/oldconfig.py4
2 files changed, 23 insertions, 10 deletions
diff --git a/examples/merge_config.py b/examples/merge_config.py
index bc6e4b8..a6110f8 100644
--- a/examples/merge_config.py
+++ b/examples/merge_config.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python3
-#
# 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 +35,7 @@
# conf3 contents:
#
# # Ops... assigned twice
-# CONFIG_FOO is not set
+# # CONFIG_FOO is not set
#
# Ops... this symbol doesn't exist
# CONFIG_OPS=y
@@ -52,13 +50,13 @@
#
# Running:
#
-# $ ./merge_config.py Kconfig merged conf1 conf2 conf3 conf4
-# conf3:2: warning: FOO set more than once. Old value: "y", new value: "n".
+# $ 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 was assigned the value "y" but got the value "n" -- check dependencies
+# 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_FOO is not set
# CONFIG_BAR=y
# CONFIG_BAZ="baz string"
from kconfiglib import Kconfig, Symbol, BOOL, TRISTATE, TRI_TO_STR
@@ -86,6 +84,21 @@ kconf.write_config(sys.argv[2])
# Print warnings for symbols whose actual value doesn't match the assigned
# value
+
+def name_and_loc_str(sym):
+ """
+ Helper for printing the symbol name along with the location(s) in the
+ Kconfig files where the symbol is defined
+ """
+ # If the symbol has no menu nodes, it is undefined
+ if not sym.nodes:
+ return sym.name + " (undefined)"
+
+ return "{} (defined at {})".format(
+ sym.name,
+ ", ".join("{}:{}".format(node.filename, node.linenr)
+ for node in sym.nodes))
+
for sym in kconf.defined_syms:
# Was the symbol assigned to?
if sym.user_value is not None:
@@ -99,4 +112,4 @@ 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(sym.name, user_value, sym.str_value))
+ .format(name_and_loc_str(sym), user_value, sym.str_value))
diff --git a/examples/oldconfig.py b/examples/oldconfig.py
index aa8e253..737ddae 100644
--- a/examples/oldconfig.py
+++ b/examples/oldconfig.py
@@ -60,7 +60,7 @@
#
# $ touch .config # Run with empty .config
#
-# $ python oldconfig.py Kconfig
+# $ python(3) oldconfig.py Kconfig
# BOOL_SYM prompt (BOOL_SYM, defined at Kconfig:5) [n/Y] foo
# Invalid tristate value
# BOOL_SYM prompt (BOOL_SYM, defined at Kconfig:5) [n/Y] n
@@ -118,7 +118,7 @@ def print_help(node):
def name_and_loc_str(sym):
"""
Helper for printing the symbol name along with the location(s) in the
- Kconfig files where it is defined
+ Kconfig files where the symbol is defined
"""
return "{}, defined at {}".format(
sym.name,