Debian Codegraph @

util/kconfig/merge_config.sh

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2 # SPDX-License-Identifier: GPL-2.0-only
3 #
4 # merge_config.sh - Takes a list of config fragment values, and merges
5 # them one by one. Provides warnings on overridden values, and specified
6 # values that did not make it to the resulting .config file (due to missed
7 # dependencies or config symbol removal).
8 #
9 # Portions reused from kconf_check and generate_cfg:
10 # http://git.yoctoproject.org/cgit/cgit.cgi/yocto-kernel-tools/tree/tools/kconf_check
11 # http://git.yoctoproject.org/cgit/cgit.cgi/yocto-kernel-tools/tree/tools/generate_cfg
12 #
13 # Copyright (c) 2009-2010 Wind River Systems, Inc.
14 # Copyright 2011 Linaro
15
16 set -e
17
18 clean_upscip-shell shell coreboot 25.09+dfsg-1 clean_up().() {
19 rmscip-shell system . . rm. -f $TMP_FILE
20 rmscip-shell system . . rm. -f $MERGE_FILE
21 }
22
23 usagescip-shell shell coreboot 25.09+dfsg-1 usage().() {
24 echoscip-shell system . . echo. "Usage: $0 [OPTIONS] [CONFIG [...]]"
25 echoscip-shell system . . echo. " -h display this help text"
26 echoscip-shell system . . echo. " -m only merge the fragments, do not execute the make command"
27 echoscip-shell system . . echo. " -n use allnoconfig instead of alldefconfig"
28 echoscip-shell system . . echo. " -r list redundant entries when merging fragments"
29 echoscip-shell system . . echo. " -y make builtin have precedence over modules"
30 echoscip-shell system . . echo. " -O dir to put generated output files. Consider setting \$KCONFIG_CONFIG instead."
31 echoscip-shell system . . echo. " -s strict mode. Fail if the fragment redefines any value."
32 echoscip-shell system . . echo. " -Q disable warning messages for overridden options."
33 echoscip-shell system . . echo.
34 echoscip-shell system . . echo. "Used prefix: '$CONFIG_PREFIX'. You can redefine it with \$CONFIG_ environment variable."
35 }
36
37 RUNMAKE=true
38 ALLTARGET=alldefconfig
39 WARNREDUN=false
40 BUILTIN=false
41 OUTPUT=.
42 STRICT=false
43 CONFIG_PREFIX=${CONFIG_-CONFIG_}
44 WARNOVERRIDE=echo
45
46 while truescip-shell system . . true.; do
47 case $1 in
48 "-n")
49 ALLTARGET=allnoconfig
50 shift
51 continue
52 ;;
53 "-m")
54 RUNMAKE=false
55 shift
56 continue
57 ;;
58 "-h")
59 usagescip-shell shell coreboot 25.09+dfsg-1 usage().
60 exit
61 ;;
62 "-r")
63 WARNREDUN=true
64 shift
65 continue
66 ;;
67 "-y")
68 BUILTIN=true
69 shift
70 continue
71 ;;
72 "-O")
73 if [scip-shell system . . `[`. -d $2 ];then
74 OUTPUT=$(echoscip-shell system . . echo. $2 | sedscip-shell system . . sed. 's/\/*$//')
75 else
76 echoscip-shell system . . echo. "output directory $2 does not exist" 1>&2
77 exit 1
78 fi
79 shift 2
80 continue
81 ;;
82 "-s")
83 STRICT=true
84 shift
85 continue
86 ;;
87 "-Q")
88 WARNOVERRIDE=true
89 shift
90 continue
91 ;;
92 *)
93 break
94 ;;
95 esac
96 done
97
98 if [scip-shell system . . `[`. "$#" -lt 1 ] ; then
99 usagescip-shell shell coreboot 25.09+dfsg-1 usage().
100 exit
101 fi
102
103 if [scip-shell system . . `[`. -z "$KCONFIG_CONFIG" ]; then
104 if [scip-shell system . . `[`. "$OUTPUT" != . ]; then
105 KCONFIG_CONFIG=$(readlinkscip-shell system . . readlink. -m -- "$OUTPUT/.config")
106 else
107 KCONFIG_CONFIG=.config
108 fi
109 fi
110
111 INITFILE=$1
112 shift;
113
114 if [scip-shell system . . `[`. ! -r "$INITFILE" ]; then
115 echoscip-shell system . . echo. "The base file '$INITFILE' does not exist. Exit." >&2
116 exit 1
117 fi
118
119 MERGE_LIST=$*
120 SED_CONFIG_EXP1="s/^\(${CONFIG_PREFIX}[a-zA-Z0-9_]*\)=.*/\1/p"
121 SED_CONFIG_EXP2="s/^# \(${CONFIG_PREFIX}[a-zA-Z0-9_]*\) is not set$/\1/p"
122
123 TMP_FILE=$(mktempscip-shell system . . mktemp. ./.tmp.config.XXXXXXXXXX)
124 MERGE_FILE=$(mktempscip-shell system . . mktemp. ./.merge_tmp.config.XXXXXXXXXX)
125
126 echoscip-shell system . . echo. "Using $INITFILE as base"
127
128 trap clean_up EXIT
129
130 catscip-shell system . . cat. $INITFILE > $TMP_FILE
131
132 # Merge files, printing warnings on overridden values
133 for ORIG_MERGE_FILE in $MERGE_LIST ; do
134 echoscip-shell system . . echo. "Merging $ORIG_MERGE_FILE"
135 if [scip-shell system . . `[`. ! -r "$ORIG_MERGE_FILE" ]; then
136 echoscip-shell system . . echo. "The merge file '$ORIG_MERGE_FILE' does not exist. Exit." >&2
137 exit 1
138 fi
139 catscip-shell system . . cat. $ORIG_MERGE_FILE > $MERGE_FILE
140 CFG_LIST=$(sedscip-shell system . . sed. -n -e "$SED_CONFIG_EXP1" -e "$SED_CONFIG_EXP2" $MERGE_FILE)
141
142 for CFG in $CFG_LIST ; do
143 grepscip-shell system . . grep. -q -w $CFG $TMP_FILE || continue
144 PREV_VAL=$(grepscip-shell system . . grep. -w $CFG $TMP_FILE)
145 NEW_VAL=$(grepscip-shell system . . grep. -w $CFG $MERGE_FILE)
146 BUILTIN_FLAG=false
147 if [scip-shell system . . `[`. "$BUILTIN" = "true" ] && [scip-shell system . . `[`. "${NEW_VAL#CONFIG_*=}" = "m" ] && [scip-shell system . . `[`. "${PREV_VAL#CONFIG_*=}" = "y" ]; then
148 ${WARNOVERRIDE} Previous value: $PREV_VAL
149 ${WARNOVERRIDE} New value: $NEW_VAL
150 ${WARNOVERRIDE} -y passed, will not demote y to m
151 ${WARNOVERRIDE}
152 BUILTIN_FLAG=true
153 elif [scip-shell system . . `[`. "x$PREV_VAL" != "x$NEW_VAL" ] ; then
154 ${WARNOVERRIDE} Value of $CFG is redefined by fragment $ORIG_MERGE_FILE:
155 ${WARNOVERRIDE} Previous value: $PREV_VAL
156 ${WARNOVERRIDE} New value: $NEW_VAL
157 ${WARNOVERRIDE}
158 if [scip-shell system . . `[`. "$STRICT" = "true" ]; then
159 STRICT_MODE_VIOLATED=true
160 fi
161 elif [scip-shell system . . `[`. "$WARNREDUN" = "true" ]; then
162 ${WARNOVERRIDE} Value of $CFG is redundant by fragment $ORIG_MERGE_FILE:
163 fi
164 if [scip-shell system . . `[`. "$BUILTIN_FLAG" = "false" ]; then
165 sedscip-shell system . . sed. -i "/$CFG[ =]/d" $TMP_FILE
166 else
167 sedscip-shell system . . sed. -i "/$CFG[ =]/d" $MERGE_FILE
168 fi
169 done
170 catscip-shell system . . cat. $MERGE_FILE >> $TMP_FILE
171 done
172
173 if [scip-shell system . . `[`. "$STRICT_MODE_VIOLATED" = "true" ]; then
174 echoscip-shell system . . echo. "The fragment redefined a value and strict mode had been passed."
175 exit 1
176 fi
177
178 if [scip-shell system . . `[`. "$RUNMAKE" = "false" ]; then
179 cpscip-shell system . . cp. -T -- "$TMP_FILE" "$KCONFIG_CONFIG"
180 echoscip-shell system . . echo. "#"
181 echoscip-shell system . . echo. "# merged configuration written to $KCONFIG_CONFIG (needs make)"
182 echoscip-shell system . . echo. "#"
183 exit
184 fi
185
186 # If we have an output dir, setup the O= argument, otherwise leave
187 # it blank, since O=. will create an unnecessary ./source softlink
188 OUTPUT_ARG=""
189 if [scip-shell system . . `[`. "$OUTPUT" != "." ] ; then
190 OUTPUT_ARG="O=$OUTPUT"
191 fi
192
193
194 # Use the merged file as the starting point for:
195 # alldefconfig: Fills in any missing symbols with Kconfig default
196 # allnoconfig: Fills in any missing symbols with # CONFIG_* is not set
197 makescip-shell system . . make. KCONFIG_ALLCONFIG=$TMP_FILE $OUTPUT_ARG $ALLTARGET
198
199
200 # Check all specified config values took (might have missed-dependency issues)
201 for CFG in $(sedscip-shell system . . sed. -n -e "$SED_CONFIG_EXP1" -e "$SED_CONFIG_EXP2" $TMP_FILE); do
202
203 REQUESTED_VAL=$(grepscip-shell system . . grep. -w -e "$CFG" $TMP_FILE)
204 ACTUAL_VAL=$(grepscip-shell system . . grep. -w -e "$CFG" "$KCONFIG_CONFIG" || truescip-shell system . . true.)
205 if [scip-shell system . . `[`. "x$REQUESTED_VAL" != "x$ACTUAL_VAL" ] ; then
206 echoscip-shell system . . echo. "Value requested for $CFG not in final .config"
207 echoscip-shell system . . echo. "Requested value: $REQUESTED_VAL"
208 echoscip-shell system . . echo. "Actual value: $ACTUAL_VAL"
209 echoscip-shell system . . echo. ""
210 fi
211 done