Skip to content

Commit dfc97e1

Browse files
mikkorapeli-linaronathanchance
authored andcommitted
scripts: kconfig: merge_config.sh: use awk in checks too
Converting from shell/sed/grep loop to awk improves runtime checks of Yocto genericarm64 kernel config from 20 seconds to under 1 second. The checks catch this kind of issues: WARNING: CONFIG_BLK_DEV_DM differs: Requested value: CONFIG_BLK_DEV_DM=y Actual value: CONFIG_BLK_DEV_DM=m WARNING: CONFIG_SECURITY_NETWORK differs: Requested value: CONFIG_SECURITY_NETWORK=n Actual value: CONFIG_SECURITY_NETWORK=y WARNING: Value requested for CONFIG_ARM64_BTI_KERNEL not in final .config Requested value: CONFIG_ARM64_BTI_KERNEL=y Actual value: Signed-off-by: Mikko Rapeli <mikko.rapeli@linaro.org> Link: https://patch.msgid.link/20260122105751.2186609-2-mikko.rapeli@linaro.org Signed-off-by: Nathan Chancellor <nathan@kernel.org>
1 parent 5fa9b82 commit dfc97e1

1 file changed

Lines changed: 86 additions & 11 deletions

File tree

scripts/kconfig/merge_config.sh

Lines changed: 86 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -286,16 +286,91 @@ fi
286286
# allnoconfig: Fills in any missing symbols with # CONFIG_* is not set
287287
make KCONFIG_ALLCONFIG=$TMP_FILE $OUTPUT_ARG $ALLTARGET
288288

289+
# Check all specified config values took effect (might have missed-dependency issues)
290+
if ! "$AWK" -v prefix="$CONFIG_PREFIX" \
291+
-v warnoverride="$WARNOVERRIDE" \
292+
-v strict="$STRICT" \
293+
-v warnredun="$WARNREDUN" '
294+
BEGIN {
295+
strict_violated = 0
296+
cfg_regex = "^" prefix "[a-zA-Z0-9_]+"
297+
notset_regex = "^# " prefix "[a-zA-Z0-9_]+ is not set$"
298+
}
289299
290-
# Check all specified config values took (might have missed-dependency issues)
291-
for CFG in $(sed -n -e "$SED_CONFIG_EXP1" -e "$SED_CONFIG_EXP2" $TMP_FILE); do
300+
# Extract config name from a line, returns "" if not a config line
301+
function get_cfg(line) {
302+
if (match(line, cfg_regex)) {
303+
return substr(line, RSTART, RLENGTH)
304+
} else if (match(line, notset_regex)) {
305+
# Extract CONFIG_FOO from "# CONFIG_FOO is not set"
306+
sub(/^# /, "", line)
307+
sub(/ is not set$/, "", line)
308+
return line
309+
}
310+
return ""
311+
}
292312
293-
REQUESTED_VAL=$(grep -w -e "$CFG" $TMP_FILE)
294-
ACTUAL_VAL=$(grep -w -e "$CFG" "$KCONFIG_CONFIG" || true)
295-
if [ "x$REQUESTED_VAL" != "x$ACTUAL_VAL" ] ; then
296-
echo "Value requested for $CFG not in final .config"
297-
echo "Requested value: $REQUESTED_VAL"
298-
echo "Actual value: $ACTUAL_VAL"
299-
echo ""
300-
fi
301-
done
313+
function warn_mismatch(cfg, merged, final) {
314+
if (warnredun == "true") return
315+
if (final == "" && !(merged ~ / is not set$/ || merged ~ /=n$/)) {
316+
print "WARNING: Value requested for " cfg " not in final .config"
317+
print "Requested value: " merged
318+
print "Actual value: " final
319+
} else if (final == "" && merged ~ / is not set$/) {
320+
# not set, pass
321+
} else if (merged == "" && final != "") {
322+
print "WARNING: " cfg " not in merged config but added in final .config:"
323+
print "Requested value: " merged
324+
print "Actual value: " final
325+
} else {
326+
print "WARNING: " cfg " differs:"
327+
print "Requested value: " merged
328+
print "Actual value: " final
329+
}
330+
}
331+
332+
# First pass: read effective config file, store all lines
333+
FILENAME == ARGV[1] {
334+
cfg = get_cfg($0)
335+
if (cfg != "") {
336+
config_cfg[cfg] = $0
337+
}
338+
next
339+
}
340+
341+
# Second pass: process merged config and compare against effective config
342+
{
343+
cfg = get_cfg($0)
344+
if (cfg == "") next
345+
346+
# strip trailing comment
347+
sub(/[[:space:]]+#.*/, "", $0)
348+
merged_val = $0
349+
final_val = config_cfg[cfg]
350+
351+
if (merged_val == final_val) next
352+
353+
if (merged_val ~ /=n$/ && final_val ~ / is not set$/) next
354+
if (merged_val ~ /=n$/ && final_val == "") next
355+
356+
warn_mismatch(cfg, merged_val, final_val)
357+
358+
if (strict == "true") {
359+
strict_violated = 1
360+
}
361+
}
362+
363+
END {
364+
if (strict_violated) {
365+
exit 1
366+
}
367+
}' \
368+
"$KCONFIG_CONFIG" "$TMP_FILE"; then
369+
# awk exited non-zero, strict mode was violated
370+
STRICT_MODE_VIOLATED=true
371+
fi
372+
373+
if [ "$STRICT" == "true" ] && [ "$STRICT_MODE_VIOLATED" == "true" ]; then
374+
echo "Requested and effective config differ"
375+
exit 1
376+
fi

0 commit comments

Comments
 (0)