Atlas - merge_config.py
Home / ext / kconfiglib / examples Lines: 1 | Size: 3635 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1#!/usr/bin/env python3 2 3# This script functions similarly to scripts/kconfig/merge_config.sh from the 4# kernel tree, merging multiple configurations fragments to produce a complete 5# .config, with unspecified values filled in as for alldefconfig. 6# 7# The generated .config respects symbol dependencies, and a warning is printed 8# if any symbol gets a different value from the assigned value. 9# 10# For a real-world merging example based on this script, see 11# https://github.com/zephyrproject-rtos/zephyr/blob/master/scripts/kconfig/kconfig.py. 12# 13# Here's a demo: 14# 15# Kconfig contents: 16# 17# config FOO 18# bool "FOO" 19# 20# config BAR 21# bool "BAR" 22# 23# config BAZ 24# string "BAZ" 25# 26# config QAZ 27# bool "QAZ" if n 28# 29# 30# conf1 contents: 31# 32# CONFIG_FOO=y 33# 34# 35# conf2 contents: 36# 37# CONFIG_BAR=y 38# 39# 40# conf3 contents: 41# 42# # Assigned twice (would generate warning if 'warn_assign_override' was 43# # True) 44# # CONFIG_FOO is not set 45# 46# # Ops... this symbol doesn't exist 47# CONFIG_OPS=y 48# 49# CONFIG_BAZ="baz string" 50# 51# 52# conf4 contents: 53# 54# CONFIG_QAZ=y 55# 56# 57# Running: 58# 59# $ python(3) merge_config.py Kconfig merged conf1 conf2 conf3 conf4 60# Merged configuration 'conf1' 61# Merged configuration 'conf2' 62# conf3:5: warning: attempt to assign the value 'y' to the undefined symbol OPS 63# Merged configuration 'conf3' 64# Merged configuration 'conf4' 65# Configuration saved to 'merged' 66# warning: QAZ (defined at Kconfig:10) was assigned the value 'y' but got the value 'n' -- check dependencies 67# $ cat merged 68# Generated by Kconfiglib (https://github.com/ulfalizer/Kconfiglib) 69# # CONFIG_FOO is not set 70# CONFIG_BAR=y 71# CONFIG_BAZ="baz string" 72 73from __future__ import print_function 74import sys 75 76from kconfiglib import Kconfig, BOOL, TRISTATE, TRI_TO_STR 77 78 79if len(sys.argv) < 4: 80 sys.exit("usage: merge_config.py Kconfig merged_config config1 [config2 ...]") 81 82kconf = Kconfig(sys.argv[1], suppress_traceback=True) 83 84# Enable warnings for assignments to undefined symbols 85kconf.warn_assign_undef = True 86 87# (This script uses alldefconfig as the base. Other starting states could be 88# set up here as well. The approach in examples/allnoconfig_simpler.py could 89# provide an allnoconfig starting state for example.) 90 91# Disable warnings generated for multiple assignments to the same symbol within 92# a (set of) configuration files. Assigning a symbol multiple times might be 93# done intentionally when merging configuration files. 94kconf.warn_assign_override = False 95kconf.warn_assign_redun = False 96 97# Create a merged configuration by loading the fragments with replace=False. 98# load_config() and write_config() returns a message to print. 99for config in sys.argv[3:]: 100 print(kconf.load_config(config, replace=False)) 101 102# Write the merged configuration 103print(kconf.write_config(sys.argv[2])) 104 105# Print warnings for symbols whose actual value doesn't match the assigned 106# value 107for sym in kconf.defined_syms: 108 # Was the symbol assigned to? 109 if sym.user_value is not None: 110 # Tristate values are represented as 0, 1, 2. Having them as 111 # "n", "m", "y" is more convenient here, so convert. 112 if sym.type in (BOOL, TRISTATE): 113 user_value = TRI_TO_STR[sym.user_value] 114 else: 115 user_value = sym.user_value 116 117 if user_value != sym.str_value: 118 print("warning: {} was assigned the value '{}' but got the " 119 "value '{}' -- check dependencies".format( 120 sym.name_and_loc, user_value, sym.str_value), 121 file=sys.stderr) 122[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.