From ec76214f680c824997461638d35654a3d540714b Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Fri, 18 Feb 2022 00:59:58 -0800 Subject: [PATCH] scons: Hook up the savedefconfig kconfig helper. This helper utility lets you save the defconfig which would give rise to a given config. For instance, you could use menuconfig to set up a config how you want it with the options you cared about configured, and then use savedefconfig to save a defconfig of that somewhere to the side, in the gem5 defconfig directory, etc. Then later, you could use that defconfig to set up a new build directory with that same config, even if the kconfig options have changed a little bit since then. A saved defconfig like that can also be a good way to visually see what options have been set to something interesting, and an easier way to pass a config to someone else to use, to put in bug reports, etc. Change-Id: Ifd344278638c59b48c261b36058832034c009c78 --- SConstruct | 18 ++++++++++++++++++ site_scons/gem5_scons/kconfig.py | 17 +++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/SConstruct b/SConstruct index fa321b2873..57134b6863 100755 --- a/SConstruct +++ b/SConstruct @@ -264,6 +264,7 @@ kconfig_actions = ( 'guiconfig', 'listnewconfig', 'menuconfig', + 'savedefconfig', 'setconfig', ) @@ -316,6 +317,17 @@ Kconfig tools: scons menuconfig build/foo/bar + savedefconfig: + Save a defconfig file which would give rise to the current config. + For instance, you could use menuconfig to set up a config how you want + it with the options you cared about, and then use savedefconfig to save + a minimal config file. These files would be suitable to use in the + defconfig directory. The second argument specifies the filename for + the new defconfig file. + + scons savedefconfig build/foo/bar new_def_config + + setconfig: Set values in an existing config directory as specified on the command line. For example, to enable gem5's built in systemc kernel: @@ -856,6 +868,12 @@ for variant_path in variant_paths: elif kconfig_action == 'menuconfig': kconfig.menuconfig(env, kconfig_file.abspath, config_file.abspath, variant_path) + elif kconfig_action == 'savedefconfig': + if len(kconfig_args) != 1: + error('Usage: scons defconfig ') + defconfig_path = makePathAbsolute(kconfig_args[0]) + kconfig.savedefconfig(env, kconfig_file.abspath, + config_file.abspath, defconfig_path) elif kconfig_action == 'setconfig': kconfig.setconfig(env, kconfig_file.abspath, config_file.abspath, ARGUMENTS) diff --git a/site_scons/gem5_scons/kconfig.py b/site_scons/gem5_scons/kconfig.py index 5638aa7643..347e11277d 100644 --- a/site_scons/gem5_scons/kconfig.py +++ b/site_scons/gem5_scons/kconfig.py @@ -33,6 +33,7 @@ _kconfig_helpers = { "GUICONFIG_PY": "guiconfig.py", "LISTNEWCONFIG_PY": "listnewconfig.py", "MENUCONFIG_PY": "menuconfig.py", + "SAVEDEFCONFIG_PY": "savedefconfig.py", "SETCONFIG_PY": "setconfig.py", } @@ -130,6 +131,22 @@ def menuconfig( error("Failed to run menuconfig") +def savedefconfig(env, base_kconfig, config_in, config_out): + """ + Interface of handling savedefconfig.py of Kconfiglib + """ + kconfig_env = _prep_env(env, base_kconfig, config_in) + kconfig_env["CONFIG_OUT"] = config_out + if ( + kconfig_env.Execute( + '"${SAVEDEFCONFIG_PY}" ' + '--kconfig "${BASE_KCONFIG}" --out "${CONFIG_OUT}"' + ) + != 0 + ): + error("Failed to run savedefconfig") + + def setconfig(env, base_kconfig, config_path, assignments): """ Interface of handling setconfig.py of Kconfiglib