This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit a0cc455922db30f85c9669efdd6ec9e918933d56 Author: yinshengkai <yinsheng...@xiaomi.com> AuthorDate: Mon Sep 11 20:34:31 2023 +0800 tools: add support for merge_config Usage example: ./tools/merge_config.py -o defconfig .config1 .config2 Signed-off-by: yinshengkai <yinsheng...@xiaomi.com> --- Documentation/quickstart/configuring.rst | 10 +++++ tools/merge_config.py | 69 ++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/Documentation/quickstart/configuring.rst b/Documentation/quickstart/configuring.rst index 0cf176549a..4ff36999c8 100644 --- a/Documentation/quickstart/configuring.rst +++ b/Documentation/quickstart/configuring.rst @@ -140,3 +140,13 @@ The default header file search path includes: CONFIG_XXX2=y #include "configs/system.config" #include "configs/net.config" + +Merge configuration +-------------------------- + +Multiple config fragments can be merged manually using the tools/merge_config.py script. + +.. code-block:: console + + $ cd nuttx + $ ./tools/merge_config.py -o defconfig .config1 .config2 diff --git a/tools/merge_config.py b/tools/merge_config.py new file mode 100755 index 0000000000..6dc2fc762a --- /dev/null +++ b/tools/merge_config.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python3 +############################################################################ +# tools/merge_config.py +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +import argparse +import os + +try: + from kconfiglib import Kconfig +except ModuleNotFoundError: + print("Please execute the following command to install dependencies:") + print("pip install kconfiglib") + exit() + +script_path = os.path.split(os.path.realpath(__file__))[0] +topdir = os.path.join(script_path, "..") +kconfig_path = os.path.join(topdir, "Kconfig") + +# Set environment variables + +os.environ["BINDIR"] = os.path.join(topdir) +os.environ["APPSDIR"] = os.path.join(topdir, "../apps") +os.environ["APPSBINDIR"] = os.path.join(topdir, "../apps") + + +def merge_configs(output_file, input_files): + kconf = Kconfig(kconfig_path, suppress_traceback=True) + + kconf.warn_assign_undef = True + kconf.warn_assign_override = False + kconf.warn_assign_redun = False + + for input_file in input_files: + print(kconf.load_config(input_file, replace=False)) + + # Save the merged configuration to the output file + + kconf.write_min_config(output_file) + print(f"Configuration successfully merged to {output_file}") + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Merge Kconfig configuration files") + parser.add_argument( + "-o", "--output", required=True, help="Output merged configuration file" + ) + parser.add_argument( + "input_files", nargs="+", help="List of input configuration files" + ) + args = parser.parse_args() + + merge_configs(args.output, args.input_files)