scons: Add a mechanism to run menuconfig to set up a build dir.
If you call scons with the fist argument set to menuconfig, that means
to run menuconfig on the path following it. Or in other words, if
you ran this command:
scons menuconfig build/foo/bar
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.
This supplements and does not replace the existing mechanism of using
"build/${VARIANT}" to select a config with defconfig.
Change-Id: Ief8e8c2ee6477799455c2004bef06c64be5cc1db
This commit is contained in:
70
SConstruct
70
SConstruct
@@ -259,27 +259,60 @@ Targets:
|
||||
#
|
||||
########################################################################
|
||||
|
||||
kconfig_actions = ('menuconfig',)
|
||||
|
||||
Help("""
|
||||
Kconfig:
|
||||
In addition to the default configs, you can also create your own
|
||||
configs, or edit one that already exists. To edit or create a config
|
||||
for a particular directory, give SCons a target which is the directory
|
||||
to configure, and then "menuconfig". For example:
|
||||
|
||||
scons menuconfig build/foo/bar
|
||||
|
||||
will set up a build directory in build/foo/bar if one doesn't already
|
||||
exist, and open the menuconfig editor to view/set configuration
|
||||
values.
|
||||
""", append=True)
|
||||
|
||||
# Take a list of paths (or SCons Nodes) and return a list with all
|
||||
# paths made absolute and ~-expanded. Paths will be interpreted
|
||||
# relative to the launch directory unless a different root is provided
|
||||
|
||||
def makePathAbsolute(path, root=GetLaunchDir()):
|
||||
return abspath(os.path.join(root, expanduser(str(path))))
|
||||
def makePathListAbsolute(path_list, root=GetLaunchDir()):
|
||||
return [abspath(os.path.join(root, expanduser(str(p))))
|
||||
for p in path_list]
|
||||
return [makePathAbsolute(p, root) for p in path_list]
|
||||
|
||||
# Each target must have 'build' in the interior of the path; the
|
||||
# directory below this will determine the build parameters. For
|
||||
# example, for target 'foo/bar/build/X86/arch/x86/blah.do' we
|
||||
# recognize that X86 specifies the configuration because it
|
||||
# follow 'build' in the build path.
|
||||
if BUILD_TARGETS and BUILD_TARGETS[0] in kconfig_actions:
|
||||
# The build targets are really arguments for the kconfig action.
|
||||
kconfig_args = BUILD_TARGETS[:]
|
||||
BUILD_TARGETS[:] = []
|
||||
|
||||
# The funky assignment to "[:]" is needed to replace the list contents
|
||||
# in place rather than reassign the symbol to a new list, which
|
||||
# doesn't work (obviously!).
|
||||
BUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS)
|
||||
kconfig_action = kconfig_args[0]
|
||||
if len(kconfig_args) < 2:
|
||||
error(f'Missing arguments for kconfig action {kconfig_action}')
|
||||
dir_to_configure = makePathAbsolute(kconfig_args[1])
|
||||
|
||||
# Generate a list of the unique build directories that the collected targets
|
||||
# reference.
|
||||
variant_paths = set(map(parse_build_path, BUILD_TARGETS))
|
||||
kconfig_args = kconfig_args[2:]
|
||||
|
||||
variant_paths = {dir_to_configure}
|
||||
else:
|
||||
# Each target must have 'build' in the interior of the path; the
|
||||
# directory below this will determine the build parameters. For
|
||||
# example, for target 'foo/bar/build/X86/arch/x86/blah.do' we
|
||||
# recognize that X86 specifies the configuration because it
|
||||
# follow 'build' in the build path.
|
||||
|
||||
# The funky assignment to "[:]" is needed to replace the list contents
|
||||
# in place rather than reassign the symbol to a new list, which
|
||||
# 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_action = None
|
||||
|
||||
|
||||
########################################################################
|
||||
@@ -758,6 +791,15 @@ for variant_path in variant_paths:
|
||||
for cb in after_sconsopts_callbacks:
|
||||
cb()
|
||||
|
||||
# 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)
|
||||
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):
|
||||
buildopts_file = Dir('#build_opts').File(variant_dir)
|
||||
|
||||
@@ -73,6 +73,19 @@ def defconfig(env, base_kconfig, config_in, config_out):
|
||||
error("Failed to run defconfig")
|
||||
|
||||
|
||||
def menuconfig(
|
||||
env, base_kconfig, config_path, main_menu_text, style="aquatic"
|
||||
):
|
||||
"""
|
||||
Interface of handling menuconfig.py of Kconfiglib
|
||||
"""
|
||||
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_env(env, base_kconfig, config_path):
|
||||
"""
|
||||
Update the Scons' env["CONF"] options from kconfig env
|
||||
|
||||
Reference in New Issue
Block a user