[Buildroot] [PATCH 3/3] support/kconfig: Add option to fail merge_config.sh on invalid configs

Charlie Jenkins charlie at rivosinc.com
Fri Apr 11 02:35:20 UTC 2025


merge_config.sh will print a message if the value requested does not end
up in the final config. To allow tools to automatically detect if there
is an invalid config, add an option "-f" to fail merge_config.sh if the
requested config values don't end up in the final config.

Signed-off-by: Charlie Jenkins <charlie at rivosinc.com>
---
 support/kconfig/merge_config.sh | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/support/kconfig/merge_config.sh b/support/kconfig/merge_config.sh
index 26bf41cab53ea54993a15b8be4ff40940a62e793..54707438bfc3b763534267d4112c6fa95b48b7be 100755
--- a/support/kconfig/merge_config.sh
+++ b/support/kconfig/merge_config.sh
@@ -22,7 +22,7 @@
 
 clean_up() {
 	rm -f $TMP_FILE
-	exit
+	exit $1
 }
 trap clean_up HUP INT TERM
 
@@ -35,6 +35,7 @@ usage() {
 	echo "  -O    dir to put generated output files.  Consider setting \$KCONFIG_CONFIG instead."
 	echo "  -e    colon-separated list of br2-external trees to use (optional)"
 	echo "  -C    change to directory before doing anything else"
+	echo "  -f    set exit code to 1 if config values are not properly set"
 	echo
 	echo "Used prefix: '$CONFIG_PREFIX'. You can redefine it with \$CONFIG_
 	environment variable."
@@ -87,6 +88,11 @@ while true; do
 		shift 2
 		continue
 		;;
+	"-f")
+		FAIL_ON_INCORRECT_CONFIG=true
+		shift
+		continue
+		;;
 	*)
 		break
 		;;
@@ -195,6 +201,7 @@ fi
 # allnoconfig: Fills in any missing symbols with # CONFIG_* is not set
 make KCONFIG_ALLCONFIG=$TMP_FILE $EXTERNAL_ARG $OUTPUT_ARG $ALLTARGET
 
+incorrect_configs=0
 
 # Check all specified config values took (might have missed-dependency issues)
 for CFG in $(sed -n -e "$SED_CONFIG_EXP1" -e "$SED_CONFIG_EXP2" $TMP_FILE); do
@@ -202,6 +209,7 @@ for CFG in $(sed -n -e "$SED_CONFIG_EXP1" -e "$SED_CONFIG_EXP2" $TMP_FILE); do
 	REQUESTED_VAL=$(grep -w -e "$CFG" $TMP_FILE)
 	ACTUAL_VAL=$(grep -w -e "$CFG" "$KCONFIG_CONFIG")
 	if [ "x$REQUESTED_VAL" != "x$ACTUAL_VAL" ] ; then
+		incorrect_configs=1
 		echo "Value requested for $CFG not in final .config"
 		echo "Requested value:  $REQUESTED_VAL"
 		echo "Actual value:     $ACTUAL_VAL"
@@ -213,4 +221,8 @@ if [ -z "$BASE_DIRECTORY" ]; then
 	cd "$ORIGINAL_DIR" || clean_up
 fi
 
+if [ "$FAIL_ON_INCORRECT_CONFIG" = "true" ]; then
+	clean_up $incorrect_configs
+fi
+
 clean_up

-- 
2.43.0



More information about the buildroot mailing list