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:
Unified · Split
| @@ -286,16 +286,91 @@ fi · 285 unmodified lines | |||
| 286 | # allnoconfig: Fills in any missing symbols with # CONFIG_* is not set | 286 | # allnoconfig: Fills in any missing symbols with # CONFIG_* is not set |
| 287 | make KCONFIG_ALLCONFIG=$TMP_FILE $OUTPUT_ARG $ALLTARGET | 287 | make KCONFIG_ALLCONFIG=$TMP_FILE $OUTPUT_ARG $ALLTARGET |
| 288 | 288 | ||
| 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 | } | ||
| 289 | 299 | ||
| 290 | # Check all specified config values took (might have missed-dependency issues) | 300 | # Extract config name from a line, returns "" if not a config line |
| 291 | for CFG in $(sed -n -e "$SED_CONFIG_EXP1" -e "$SED_CONFIG_EXP2" $TMP_FILE); do | 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 | } | ||
| 292 | 312 | ||
| 293 | REQUESTED_VAL=$(grep -w -e "$CFG" $TMP_FILE) | 313 | function warn_mismatch(cfg, merged, final) { |
| 294 | ACTUAL_VAL=$(grep -w -e "$CFG" "$KCONFIG_CONFIG" || true) | 314 | if (warnredun == "true") return |
| 295 | if [ "x$REQUESTED_VAL" != "x$ACTUAL_VAL" ] ; then | 315 | if (final == "" && !(merged ~ / is not set$/ || merged ~ /=n$/)) { |
| 296 | echo "Value requested for $CFG not in final .config" | 316 | print "WARNING: Value requested for " cfg " not in final .config" |
| 297 | echo "Requested value: $REQUESTED_VAL" | 317 | print "Requested value: " merged |
| 298 | echo "Actual value: $ACTUAL_VAL" | 318 | print "Actual value: " final |
| 299 | echo "" | 319 | } else if (final == "" && merged ~ / is not set$/) { |
| 300 | fi | 320 | # not set, pass |
| 301 | done | 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 | ||