summaryrefslogtreecommitdiff
path: root/kconfiglib.py
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2018-05-30 21:18:49 +0200
committerUlf Magnusson <ulfalizer@gmail.com>2018-05-30 21:40:27 +0200
commitf9b158ebb3d81c923461981d2b087989c284c2d4 (patch)
tree0720a09a931c0a241bb444077708389fa7efc035 /kconfiglib.py
parent791b930930b9ddcb752c97c8a8ef859b7afbeb0e (diff)
Add tool helper for loading/saving .config files
Removes repeated KCONFIG_CONFIG boilerplate. Also make allyesconfig use KCONFIG_CONFIG when writing (oversight), and document the sys.exit() behavior for standard_kconfig().
Diffstat (limited to 'kconfiglib.py')
-rw-r--r--kconfiglib.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/kconfiglib.py b/kconfiglib.py
index 1b57821..1a1d629 100644
--- a/kconfiglib.py
+++ b/kconfiglib.py
@@ -4487,14 +4487,28 @@ def unescape(s):
def standard_kconfig():
"""
- Helper for implementing tools. Loads either a top-level Kconfig specified
- as an argument, or "Kconfig" otherwise. Returns the Kconfig instance.
+ Helper for tools. Loads the top-level Kconfig specified as the first
+ command-line argument, or "Kconfig" if there are no command-line arguments.
+ Returns the Kconfig instance.
+
+ Exits with sys.exit() (which raises a SystemExit exception) and prints a
+ usage note to stderr if more than one command-line argument is passed.
"""
if len(sys.argv) > 2:
sys.exit("usage: {} [Kconfig]".format(sys.argv[0]))
return Kconfig("Kconfig" if len(sys.argv) < 2 else sys.argv[1])
+def standard_config_filename():
+ """
+ Helper for tools. Returns the value of KCONFIG_CONFIG (which specifies the
+ .config file to load/save) if it is set, and ".config" otherwise.
+ """
+ config_filename = os.environ.get("KCONFIG_CONFIG")
+ if config_filename is not None:
+ return config_filename
+ return ".config"
+
#
# Internal functions
#