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")
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))
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)