Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/56898 )

Change subject: scons: Add a mechanism to run menuconfig to set up a build dir.
......................................................................

scons: Add a mechanism to run menuconfig to set up a build dir.

If you use target scons at a path which ends in menuconfig, that means
to run menuconfig on the path leading up to it. Or in other words, if
you ran this command:

scons build/foo/bar/menuconfig

That would tell SCons to set up a build directory at the path
build/foo/bar, and then invoke menuconfig so you can set up its
configuration.

In addition to using this mechanism to set up a new build directory, you
can also use it to reconfigure an existing directory.

When running menuconfig, SCons will not let you also supply extra
targets, and it will also force you to only configure one directory at a
time. In the case of menuconfig this doesn't really make much of a
difference and we probably could let you run multiple menuconfigs and
regular targets at the same time, but other tools Kconfiglib provides
take command line arguments and/or command line switches. If those were
allowed on the command line to give adequate control of those tools (or
to make some even usable), having multiple potential targets for them
would make it ambiguous what invocation of the tool each argument/switch
went with. To support those future use case, we need to disallow those
situations now.

This supplements and does not replace the existing mechanism of using
"build/${VARIANT}" to select a config with defconfig.

Change-Id: Ief8e8c2ee6477799455c2004bef06c64be5cc1db
---
M SConstruct
M site_scons/gem5_scons/kconfig.py
2 files changed, 82 insertions(+), 4 deletions(-)



diff --git a/SConstruct b/SConstruct
index b272bec..2112b7e 100755
--- a/SConstruct
+++ b/SConstruct
@@ -144,7 +144,7 @@
 import gem5_scons
 from gem5_scons.builders import ConfigFile, AddLocalRPATH, SwitchingHeaders
 from gem5_scons.builders import Blob
-from gem5_scons.kconfig import defconfig, update_from_kconfig
+from gem5_scons.kconfig import defconfig, menuconfig, update_from_kconfig
 from gem5_scons.sources import TagImpliesTool
 from gem5_scons.util import compareVersions, readCommand

@@ -209,9 +209,33 @@
 # doesn't work (obviously!).
 BUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS)

-# Generate a list of the unique build directories that the collected targets
-# reference.
-variant_paths = set(map(parse_build_path, BUILD_TARGETS))
+kconfig_actions = ('menuconfig',)
+
+# From itertools-recipes:
+# docs.python.org/dev/library/itertools.html#itertools-recipes
+def partition(pred, iterable):
+ 'Use a predicate to partition entries into false entries and true entries'
+    t1, t2 = itertools.tee(iterable)
+    return list(itertools.filterfalse(pred, t1)), list(filter(pred, t2))
+
+regular_targets, kconfig_targets = \
+        partition(lambda p: os.path.basename(p) in kconfig_actions,
+                BUILD_TARGETS)
+
+if kconfig_targets and regular_targets:
+    error("Can't configure build directories and build at the same time")
+
+if len(kconfig_targets) > 1:
+    error("Can only configure one build directory at a time")
+
+if regular_targets:
+    # Generate a list of the unique build directories that the collected
+    # targets reference.
+    variant_paths = set(map(parse_build_path, regular_targets))
+    kconfig_action = None
+elif kconfig_targets:
+    dir_to_configure, kconfig_action = os.path.split(kconfig_targets[0])
+    variant_paths = {dir_to_configure}


 ########################################################################
@@ -603,6 +627,15 @@
     for cb in after_sconsopts_callbacks:
         cb()

+    # Handle any requested kconfig action, then exit.
+    if kconfig_action:
+        if kconfig_action == 'menuconfig':
+            menuconfig(env, kconfig_file.abspath, config_file.abspath,
+                    variant_path)
+        else:
+            error(f'Unrecognized kconfig action {kconfig_action}')
+        Exit(0)
+
     # If no config exists yet, see if we know how to make one?
     if not isfile(config_file.abspath):
         defconfig_file = Dir('#defconfig').File(variant_dir)
diff --git a/site_scons/gem5_scons/kconfig.py b/site_scons/gem5_scons/kconfig.py
index 6026481..e26089f 100644
--- a/site_scons/gem5_scons/kconfig.py
+++ b/site_scons/gem5_scons/kconfig.py
@@ -55,6 +55,14 @@
             '"${CONFIG_IN}"') != 0:
         error("Failed to run defconfig")

+def menuconfig(env, base_kconfig, config_path, main_menu_text,
+        style='aquatic'):
+    kconfig_env = _prep_env(env, base_kconfig, config_path)
+    kconfig_env['ENV']['MENUCONFIG_STYLE'] = style
+    kconfig_env['ENV']['MAIN_MENU_TEXT'] = main_menu_text
+    if kconfig_env.Execute('"${MENUCONFIG_PY}" "${BASE_KCONFIG}"') != 0:
+        error("Failed to run menuconfig")
+
 def update_from_kconfig(env, base_kconfig, config_path):
     kconfig_env = _prep_env(env, base_kconfig, config_path)


--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/56898
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: Ief8e8c2ee6477799455c2004bef06c64be5cc1db
Gerrit-Change-Number: 56898
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

Reply via email to