klipper-flash: fix getConfigField across multi-line configs

#533030 changed `getConfigField`'s regex to stop it matching commented-out lines,
but in doing so broke checking across multiple lines.
`builtins.match` requires the whole string to match,
and `[^#\r\n]*` can never cross a newline,
so the field can only be found if it sits on line 1 of the file.

Fix by regexing each line independently.

Assisted-by: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Carson Full
2026-08-20 19:59:16 -05:00
parent 1f6f5c91fc
commit 856ccd705c

View File

@@ -17,9 +17,11 @@ let
field:
with builtins;
let
matches = match ''^[^#\r\n]*${field}="([a-zA-Z0-9_]+)".*$'' (readFile firmwareConfig);
lines = lib.splitString "\n" (readFile firmwareConfig);
matchLine = line: match ''${field}="([a-zA-Z0-9_]+)".*'' line;
matched = lib.findFirst (line: matchLine line != null) null lines;
in
if matches != null then head matches else null;
if matched != null then head (matchLine matched) else null;
matchPlatform = getConfigField "CONFIG_BOARD_DIRECTORY";
matchBoard = getConfigField "CONFIG_MCU";
matchAvrdudeProtocol = getConfigField "CONFIG_AVRDUDE_PROTOCOL";