Skip to content

Commit

Permalink
tools: add support for merge_config
Browse files Browse the repository at this point in the history
Usage example:
./tools/merge_config.py -o defconfig .config1 .config2

Signed-off-by: yinshengkai <[email protected]>
  • Loading branch information
Gary-Hobson authored and xiaoxiang781216 committed Sep 14, 2023
1 parent d0ca0d4 commit a0cc455
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Documentation/quickstart/configuring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
69 changes: 69 additions & 0 deletions tools/merge_config.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit a0cc455

Please sign in to comment.