Gabe Black has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/56950 )
Change subject: scons: Hook in the kconfig setconfig utility.
......................................................................
scons: Hook in the kconfig setconfig utility.
This little utility lets you set particular values in an existing config
without having to open up the whole menuconfig interface.
Also reorganize things in kconfig.py a little to help share code between
wrappers.
Change-Id: I7cba0c0ef8d318d6c39e49c779ebb2bbdc3d94c8
---
M SConstruct
M site_scons/gem5_scons/kconfig.py
2 files changed, 63 insertions(+), 16 deletions(-)
diff --git a/SConstruct b/SConstruct
index 8ccddee..207d92b 100755
--- a/SConstruct
+++ b/SConstruct
@@ -210,8 +210,9 @@
BUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS)
kconfig_actions = (
- 'menuconfig',
'defconfig',
+ 'menuconfig',
+ 'setconfig',
)
# From itertools-recipes:
@@ -632,16 +633,19 @@
# Handle any requested kconfig action, then exit.
if kconfig_action:
- if kconfig_action == 'menuconfig':
- kconfig.menuconfig(env, kconfig_file.abspath,
config_file.abspath,
- variant_path)
- elif kconfig_action == 'defconfig':
+ if kconfig_action == 'defconfig':
defconfig_key = 'DEFCONFIG'
defconfig_path = ARGUMENTS.get(defconfig_key, None)
if not defconfig_path:
error(f'Tried to defconfig, but {defconfig_key} not set.')
kconfig.defconfig(env, kconfig_file.abspath,
defconfig_path, config_file.abspath)
+ elif kconfig_action == 'menuconfig':
+ kconfig.menuconfig(env, kconfig_file.abspath,
config_file.abspath,
+ variant_path)
+ elif kconfig_action == 'setconfig':
+ kconfig.setconfig(env, kconfig_file.abspath,
config_file.abspath,
+ ARGUMENTS)
else:
error(f'Unrecognized kconfig action {kconfig_action}')
Exit(0)
diff --git a/site_scons/gem5_scons/kconfig.py
b/site_scons/gem5_scons/kconfig.py
index 1ccb1d2..c1fe5ba 100644
--- a/site_scons/gem5_scons/kconfig.py
+++ b/site_scons/gem5_scons/kconfig.py
@@ -28,6 +28,12 @@
from . import error
import kconfiglib
+_kconfig_helpers = {
+ 'DEFCONFIG_PY': 'defconfig.py',
+ 'MENUCONFIG_PY': 'menuconfig.py',
+ 'SETCONFIG_PY': 'setconfig.py',
+}
+
def _prep_env(env, base_kconfig, config_path=None):
kconfig_env = env.Clone()
for key, val in kconfig_env['CONF'].items():
@@ -38,16 +44,24 @@
if config_path:
kconfig_env['ENV']['KCONFIG_CONFIG'] = config_path
+ kconfig_env['BASE_KCONFIG'] = base_kconfig
+
ext = env.Dir('#ext')
kconfiglib_dir = ext.Dir('Kconfiglib')
- defconfig_py = kconfiglib_dir.File('defconfig.py')
- menuconfig_py = kconfiglib_dir.File('menuconfig.py')
-
- kconfig_env['DEFCONFIG_PY'] = defconfig_py
- kconfig_env['MENUCONFIG_PY'] = menuconfig_py
- kconfig_env['BASE_KCONFIG'] = base_kconfig
+ for key, name in _kconfig_helpers.items():
+ kconfig_env[key] = kconfiglib_dir.File(name)
return kconfig_env
+def _process_kconfig(env, base_kconfig):
+ saved_env = os.environ
+ try:
+ os.environ.update({key: str(val) for key, val in
env['ENV'].items()})
+ kconfig = kconfiglib.Kconfig(filename=base_kconfig)
+ finally:
+ os.environ = saved_env
+ return kconfig
+
+
def defconfig(env, base_kconfig, config_in, config_out):
kconfig_env = _prep_env(env, base_kconfig, config_out)
kconfig_env['CONFIG_IN'] = config_in
@@ -63,14 +77,28 @@
if kconfig_env.Execute('"${MENUCONFIG_PY}" "${BASE_KCONFIG}"') != 0:
error("Failed to run menuconfig")
+def setconfig(env, base_kconfig, config_path, assignments):
+ kconfig_env = _prep_env(env, base_kconfig, config_path)
+
+ kconfig = _process_kconfig(kconfig_env, base_kconfig)
+ sym_names = list((sym.name for sym in kconfig.unique_defined_syms))
+
+ filtered = dict({key: val for key, val in
+ assignments.items() if key in sym_names})
+
+ setconfig_cmd_parts = ['"${SETCONFIG_PY}" --kconfig "${BASE_KCONFIG}"']
+ for key, val in filtered.items():
+ if isinstance(val, bool):
+ val = 'y' if val else 'n'
+ setconfig_cmd_parts.append(f'{key}={val}')
+ setconfig_cmd = ' '.join(setconfig_cmd_parts)
+ if kconfig_env.Execute(setconfig_cmd) != 0:
+ error("Failed to run setconfig")
+
def update_env(env, base_kconfig, config_path):
kconfig_env = _prep_env(env, base_kconfig, config_path)
- saved_env = os.environ
- os.environ.update({key: str(val) for key, val in
- kconfig_env['ENV'].items()})
- kconfig = kconfiglib.Kconfig(filename=base_kconfig)
- os.environ = saved_env
+ kconfig = _process_kconfig(kconfig_env, base_kconfig)
kconfig.load_config(config_path)
for sym in kconfig.unique_defined_syms:
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/56950
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I7cba0c0ef8d318d6c39e49c779ebb2bbdc3d94c8
Gerrit-Change-Number: 56950
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <gabe.bl...@gmail.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s