diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2019-02-11 02:56:03 +0100 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2019-02-11 03:07:30 +0100 |
| commit | 22d3cc30fd6bc38da2af2a446a8babe28e79701c (patch) | |
| tree | 23277d5fdc66222eacf5fa69249e23b61ef36da1 | |
| parent | f01cbb4d04143fcc0388f65be6f424e48a839e83 (diff) | |
setconfig: Add script
This is a simple script for updating configuration values from the
command line, with (optional) checking that the assigned value matches
the actual symbol value afterwards (which it might not if there are
unsatisfied dependencies).
Sample usage:
$ setconfig FOO_SUPPORT=y BAR_BITS=8
This is useful for patching the configuration in automated build
systems, in a way that's safer than directly patching configuration
files.
| -rw-r--r-- | README.rst | 4 | ||||
| -rwxr-xr-x | setconfig.py | 85 | ||||
| -rw-r--r-- | setup.py | 2 |
3 files changed, 90 insertions, 1 deletions
@@ -54,7 +54,7 @@ installed with e.g. Microsoft Windows is supported. The ``pip`` installation will give you both the base library and the following -executables. All but one mirror functionality available in the C tools. +executables. All but two mirror functionality available in the C tools. - `menuconfig <https://github.com/ulfalizer/Kconfiglib/blob/master/menuconfig.py>`_ @@ -74,6 +74,8 @@ executables. All but one mirror functionality available in the C tools. - `genconfig <https://github.com/ulfalizer/Kconfiglib/blob/master/genconfig.py>`_ +- `setconfig <https://github.com/ulfalizer/Kconfiglib/blob/master/setconfig.py>`_ + ``genconfig`` is intended to be run at build time. It generates a C header from the configuration and (optionally) information that can be used to rebuild only files that reference Kconfig symbols that have changed value. diff --git a/setconfig.py b/setconfig.py new file mode 100755 index 0000000..54f166b --- /dev/null +++ b/setconfig.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python + +# Copyright (c) 2019, Ulf Magnusson +# SPDX-License-Identifier: ISC + +import argparse +import sys + +import kconfiglib + + +def main(): + parser = argparse.ArgumentParser(description=""" +Simple utility for setting configuration values from the command line. + +Sample usage: + + $ setconfig FOO_SUPPORT=y BAR_BITS=8 + +Note: Symbol names should not be prefixed with 'CONFIG_'. + +The exit status on errors is 1. + +The default input/output configuration file is '.config'. A different filename +can be passed in the KCONFIG_CONFIG environment variable. +""") + + parser.add_argument( + "--kconfig", + default="Kconfig", + help="Base Kconfig file (default: Kconfig)") + + parser.add_argument( + "--no-check-exists", + dest='check_exists', + action='store_false', + help="Ignore assignments to non-existent symbols instead of erroring " + "out") + + parser.add_argument( + "--no-check-value", + dest='check_value', + action='store_false', + help="Ignore assignments that didn't \"take\" (where the symbol got a " + "different value, e.g. due to unsatisfied dependencies) instead " + "of erroring out") + + parser.add_argument( + "assignments", + metavar="ASSIGNMENT", + nargs="*", + help="A 'NAME=value' assignments") + + args = parser.parse_args() + + kconf = kconfiglib.Kconfig(args.kconfig) + kconf.load_config() + + for arg in args.assignments: + if "=" not in arg: + sys.exit("error: no '=' in assignment: '{}'".format(arg)) + name, value = arg.split("=", 1) + + if name not in kconf.syms: + if not args.check_exists: + continue + sys.exit("error: no symbol '{}' in configuration".format(name)) + + sym = kconf.syms[name] + + if not sym.set_value(value): + sys.exit("error: '{}' is an invalid value for the {} symbol {}" + .format(value, kconfiglib.TYPE_TO_STR[sym.type], name)) + + if args.check_value and sym.str_value != value: + sys.exit("error: {} was assigned the value '{}', but got the " + "value '{}'. Check the symbol's dependencies, and make " + "sure that it has a prompt." + .format(name, value, sym.str_value)) + + kconf.write_config() + + +if __name__ == "__main__": + main() @@ -34,6 +34,7 @@ setuptools.setup( "allmodconfig", "allyesconfig", "listnewconfig", + "setconfig", ), # TODO: Don't install the menuconfig on Python 2. It won't run there. @@ -49,6 +50,7 @@ setuptools.setup( "allmodconfig = allmodconfig:main", "allyesconfig = allyesconfig:main", "listnewconfig = listnewconfig:main", + "setconfig = setconfig:main", ) }, |
