summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2018-05-30 20:19:08 +0200
committerUlf Magnusson <ulfalizer@gmail.com>2018-05-30 20:38:11 +0200
commit791b930930b9ddcb752c97c8a8ef859b7afbeb0e (patch)
tree269fac721dc55365f6582e521d511c87a19f03b0
parent38cca3bdeca7d91044e11ddf2193e07c5d223ad3 (diff)
Add tool helper for selecting the top-level Kconfig
standard_kconfig() gets the top-level Kconfig file from the first command-line argument, defaulting to "Kconfig". This removes some boilerplate from tools.
-rwxr-xr-xallnoconfig.py5
-rwxr-xr-xallyesconfig.py5
-rw-r--r--kconfiglib.py10
-rwxr-xr-xmenuconfig.py8
-rwxr-xr-xoldconfig.py8
-rw-r--r--testsuite.py2
6 files changed, 19 insertions, 19 deletions
diff --git a/allnoconfig.py b/allnoconfig.py
index 240fffb..a840ea6 100755
--- a/allnoconfig.py
+++ b/allnoconfig.py
@@ -15,10 +15,7 @@ import sys
import kconfiglib
def main():
- if len(sys.argv) > 2:
- sys.exit("usage: {} [Kconfig]".format(sys.argv[0]))
-
- kconf = kconfiglib.Kconfig("Kconfig" if len(sys.argv) < 2 else sys.argv[1])
+ kconf = kconfiglib.standard_kconfig()
# Avoid warnings printed by Kconfiglib when assigning a value to a symbol that
# has no prompt. Such assignments never have an effect.
diff --git a/allyesconfig.py b/allyesconfig.py
index e405e3d..a0eb01d 100755
--- a/allyesconfig.py
+++ b/allyesconfig.py
@@ -32,10 +32,7 @@ import sys
import kconfiglib
def main():
- if len(sys.argv) > 2:
- sys.exit("usage: {} [Kconfig]".format(sys.argv[0]))
-
- kconf = kconfiglib.Kconfig("Kconfig" if len(sys.argv) < 2 else sys.argv[1])
+ kconf = kconfiglib.standard_kconfig()
# Avoid warnings printed by Kconfiglib when assigning a value to a symbol that
# has no prompt. Such assignments never have an effect.
diff --git a/kconfiglib.py b/kconfiglib.py
index d69da5b..1b57821 100644
--- a/kconfiglib.py
+++ b/kconfiglib.py
@@ -4485,6 +4485,16 @@ def unescape(s):
"""
return _unescape_re_sub(r"\1", 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.
+ """
+ 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])
+
#
# Internal functions
#
diff --git a/menuconfig.py b/menuconfig.py
index 8ad3d94..584bf8e 100755
--- a/menuconfig.py
+++ b/menuconfig.py
@@ -95,7 +95,8 @@ from kconfiglib import Kconfig, \
BOOL, TRISTATE, STRING, INT, HEX, UNKNOWN, \
AND, OR, NOT, \
expr_value, split_expr, \
- TRI_TO_STR, TYPE_TO_STR
+ TRI_TO_STR, TYPE_TO_STR, \
+ standard_kconfig
#
@@ -282,10 +283,7 @@ _expr_str = _expr_str_val
# 'entry_points' can be used. It produces a handy menuconfig.exe launcher on
# Windows.
def _main():
- if len(sys.argv) > 2:
- sys.exit("usage: {} [Kconfig]".format(sys.argv[0]))
-
- menuconfig(Kconfig("Kconfig" if len(sys.argv) < 2 else sys.argv[1]))
+ menuconfig(standard_kconfig())
def menuconfig(kconf):
"""
diff --git a/oldconfig.py b/oldconfig.py
index 1b58831..70a3f5f 100755
--- a/oldconfig.py
+++ b/oldconfig.py
@@ -100,7 +100,8 @@
# $ python oldconfig.py Kconfig # Everything's already up to date
# Configuration written to .config
from __future__ import print_function
-from kconfiglib import Kconfig, Symbol, Choice, BOOL, TRISTATE, HEX
+from kconfiglib import Kconfig, Symbol, Choice, BOOL, TRISTATE, HEX, \
+ standard_kconfig
import os
import sys
@@ -299,10 +300,7 @@ def do_oldconfig_for_node(node):
# 'entry_points' can be used. It produces a handy oldconfig.exe launcher on
# Windows.
def main():
- if len(sys.argv) > 2:
- sys.exit("usage: {} [Kconfig]".format(sys.argv[0]))
-
- kconf = Kconfig("Kconfig" if len(sys.argv) < 2 else sys.argv[1])
+ kconf = standard_kconfig()
config_filename = os.environ.get("KCONFIG_CONFIG")
if config_filename is None:
diff --git a/testsuite.py b/testsuite.py
index 8bf9502..b18b7cf 100644
--- a/testsuite.py
+++ b/testsuite.py
@@ -1968,7 +1968,7 @@ def all_arch_srcarch_kconfigs():
def test_all_no(conf, arch, srcarch):
"""
- Verify that allnoconfig.py script generates the same .config as 'make
+ Verify that allnoconfig.py generates the same .config as 'make
allnoconfig', for each architecture. Runs the script via 'make
scriptconfig', so kinda slow even in speedy mode.
"""