diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2018-06-05 13:16:12 +0200 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2018-06-05 16:09:37 +0200 |
| commit | a0f0018496f01f22caf358a56b1d6b91f100af1a (patch) | |
| tree | 1ebeaabb12d353ba1e4149709e642b649fd935af | |
| parent | 1684cfc14b7e569b4e4e6628d9edde1ad67bd7b1 (diff) | |
Turn syncconfig.py into genconfig.py and generate header
There should be a script available that generates the output header for
the build. It usually makes sense to generate both the header and any
incremental build information at the same time (automatically during
build), so roll them both into the same script.
| -rwxr-xr-x | genconfig.py | 70 | ||||
| -rw-r--r-- | setup.py | 3 | ||||
| -rwxr-xr-x | syncconfig.py | 37 |
3 files changed, 72 insertions, 38 deletions
diff --git a/genconfig.py b/genconfig.py new file mode 100755 index 0000000..f0412ba --- /dev/null +++ b/genconfig.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python + +# Generates a C header from the configuration, matching the format generated by +# include/generated/autoconf.h in the kernel. +# +# Optionally generates a directory structure with one file per symbol that can +# be used to implement incremental builds. See the docstring for +# Kconfig.sync_deps() in Kconfiglib. +# +# Usage (see argument help texts for more information): +# +# genconfig.py [-h] [--header-path HEADER_FILE] [--sync-deps [OUTPUT_DIR]] [KCONFIG_FILENAME] + +import argparse +import sys + +import kconfiglib + +DESCRIPTION = """ +Generates a header file with defines from the configuration. Optionally +creates/updates a directory with incremental build information as well (see the +docstring for the Kconfig.sync_deps() function in Kconfiglib). The .config file +to generate the configuration from can be specified by setting the +KCONFIG_CONFIG environment variable. +""" + +DEFAULT_HEADER_PATH = "config.h" +DEFAULT_SYNC_DEPS_PATH = "deps/" + +def main(): + parser = argparse.ArgumentParser(description=DESCRIPTION) + + parser.add_argument( + "--header-path", + metavar="HEADER_FILE", + default=DEFAULT_HEADER_PATH, + help="path for the generated header file (default: {})" + .format(DEFAULT_HEADER_PATH)) + + parser.add_argument( + "--sync-deps", + dest="sync_deps_path", + metavar="OUTPUT_DIR", + nargs="?", + default=None, + const=DEFAULT_SYNC_DEPS_PATH, + help="enable generation of build dependency information for " + "incremental builds, optionally specifying the output path " + "(default: {})".format(DEFAULT_SYNC_DEPS_PATH)) + + parser.add_argument( + "kconfig_filename", + metavar="KCONFIG_FILENAME", + nargs="?", + default="Kconfig", + help="top-level Kconfig file (default: Kconfig)") + + args = parser.parse_args() + + + kconf = kconfiglib.Kconfig(args.kconfig_filename) + + kconf.load_config(kconfiglib.standard_config_filename()) + + kconf.write_autoconf(args.header_path) + if args.sync_deps_path is not None: + kconf.sync_deps(args.sync_deps_path) + +if __name__ == "__main__": + main() @@ -17,6 +17,7 @@ setuptools.setup( py_modules=( "kconfiglib", "menuconfig", + "genconfig", "oldconfig", "syncconfig", "alldefconfig", @@ -28,8 +29,8 @@ setuptools.setup( entry_points={ "console_scripts": ( "menuconfig = menuconfig:_main", + "genconfig = genconfig:main", "oldconfig = oldconfig:main", - "syncconfig = syncconfig:main", "alldefconfig = alldefconfig:main", "allnoconfig = allnoconfig:main", "allmodconfig = allmodconfig:main", diff --git a/syncconfig.py b/syncconfig.py deleted file mode 100755 index 7a97d01..0000000 --- a/syncconfig.py +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env python - -# This script can be used to implement incremental builds, where changing a -# symbol will recompile just the source files that reference it. -# -# See the docstring for the Kconfig.sync_deps() function for more usage -# information. -# -# Usage: -# -# (Automatically) run the following command before each build: -# -# $ syncconfig [<top Kconfig file>] <symbol file directory, passed to sync_deps()> -# -# This will indirectly catch any (relevant) changes to Kconfig files and -# environment variables as well, so it's redundant to have separate -# dependencies for those (except as a slight optimization). - -import sys - -import kconfiglib - -def main(): - if not 2 <= len(sys.argv) <= 3: - sys.exit("usage: {} [Kconfig] <Symbol directory>".format(sys.argv[0])) - - if len(sys.argv) == 2: - kconfig_filename = "Kconfig" - sym_dir = sys.argv[1] - else: - kconfig_filename = sys.argv[1] - sym_dir = sys.argv[2] - - kconfiglib.Kconfig(kconfig_filename).sync_deps(sym_dir) - -if __name__ == "__main__": - main() |
