From 02d41e167c1e91fd04013deb9a313e065849a2c9 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Sun, 8 Nov 2026 20:44:23 -0400 Subject: [PATCH 1/2] ci_targets_check: a # comment inside a run block is not a target list The scan looked for 'cmake --build' and '--target' on every line of the workflow, including YAML comments -- and the comment that describes this very check says 'adding an unknown target to `cmake --build --target ...` is a hard ninja error'. engine#1583's second attempt added exactly that sentence, and the gate reported two targets called 'What' and 'this': ci_targets_check: ci.yml builds 'What', which no add_executable/add_library defines Skip lines whose first non-space character is '#'; a comment cannot name a target. The self-test case is the prose that tripped it, and on #1583's branch the check now reports 'all 28 target(s) ci.yml builds exist in the configuration it creates' instead of two invented names. --- tools/ci/ci_targets_check.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/ci/ci_targets_check.py b/tools/ci/ci_targets_check.py index 2a6452e89..131790573 100755 --- a/tools/ci/ci_targets_check.py +++ b/tools/ci/ci_targets_check.py @@ -69,6 +69,12 @@ def ci_targets(ci_text): """The target names in ci.yml's `cmake --build … --target …` command.""" names = [] for line in continued_lines(ci_text): + # A YAML `run:` block can carry `#` comments, and they talk about the very command this scans + # ("adding an unknown target to `cmake --build --target ...` is a hard ninja error"), so a comment + # naming the phrase would otherwise contribute its prose as target names. engine#1583's second + # attempt did exactly that: the scan reported targets called 'What' and 'this'. + if line.lstrip().startswith("#"): + continue if "cmake --build" not in line or "--target" not in line: continue words = line.split("--target", 1)[1].split() @@ -273,6 +279,12 @@ def case(what, ci, cmake, want): # An option that defaults ON needs no -D: ONEBIT_NPU_HOST is that shape in the real tree. case("a target under an option that defaults ON passes without a -D", SELF_CI, SELF_CMAKE.replace("if(ONEBIT_NPU)", "if(ONEBIT_HOST)") + "option(ONEBIT_HOST \"x\" ON)\n", 0) + # A comment inside the run block that names the command must not be parsed as targets (engine#1583's + # second attempt did: the scan reported targets 'What' and 'this' from the prose). + case("a # comment mentioning cmake --build --target contributes no target names", + SELF_CI.replace("hidden_test ", "").replace(" - name: Build", + " # NB: adding an unknown target to `cmake --build --target ...` is a hard ninja error\n" + " - name: Build"), SELF_CMAKE, 0) # Unrelated guards must not fail a tree. case("a target under a non-option guard is left alone", SELF_CI, SELF_CMAKE.replace("if(ONEBIT_NPU)", "if(NOT WIN32)"), 0) From a36d24cc1c17cf85d0b5af789f02718f1c536de6 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Sun, 8 Nov 2026 21:52:40 -0400 Subject: [PATCH 2/2] ci_targets_check: a comment inside a continued list is prose, and a comment line still continues Fixes the case engine#1601's reviewer reproduced: a comment after a continuation is joined into the logical line before any full-line check can see it, so cmake --build build --target onebit \ # notatarget trailingprose \ npu_full_elf_test ... reported 'ci_targets_check: ci.yml builds `trailingprose`'. The comment now goes per PHYSICAL line (COMMENT = r'(^|\s)#.*$', so a '#' inside a quoted string survives), before the continuations are joined. One hop further than the suggested fix: the continuation has to be read from the ORIGINAL line, not the stripped one. A line that is only a comment and ends in a backslash still continues the command, so stripping first ended the logical line early and silently dropped every target after it -- my first attempt at this passed the fixture's own check by losing three of its four targets. Both directions are in --self-test now (9 cases, 0 failures), the reviewer's fixture parses as 4 targets, and main still parses 28. --- tools/ci/ci_targets_check.py | 37 ++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/tools/ci/ci_targets_check.py b/tools/ci/ci_targets_check.py index 131790573..85d1e9b9f 100755 --- a/tools/ci/ci_targets_check.py +++ b/tools/ci/ci_targets_check.py @@ -50,17 +50,35 @@ DEFINE = re.compile(r"-D([A-Za-z0-9_]+)=([^\s\"]*)") +COMMENT = re.compile(r"(^|\s)#.*$") + + def continued_lines(text): - """The lines of a YAML `run:` block, with backslash continuations joined.""" + r"""The lines of a YAML `run:` block, comment-stripped, with backslash continuations joined. + + Two things have to happen in this order, and getting it wrong is how this gate invented two + target names in one day: + + * strip the comment **per physical line, before joining** -- a `#` that follows a + continuation is no longer at the start of the logical line once the lines are joined, so a + full-line check cannot see it (engine#1601's review: a `# notatarget trailingprose` inside + a `\`-continued list produced `ci_targets_check: ci.yml builds 'trailingprose'`); + * decide the **continuation from the original line**, not the stripped one -- a line that is + only a comment *and* ends in `\` still continues the command, so stripping it first would + end the logical line early and silently drop every target after it. + + The `(^|\s)` in COMMENT keeps a `#` inside a quoted string (``"a#b"``) from being eaten. + """ out, buf = [], "" for line in text.splitlines(): - stripped = line.rstrip() - if stripped.endswith("\\"): - buf += stripped[:-1] + " " + cont = line.rstrip().endswith("\\") + core = COMMENT.sub("", line).rstrip() + if cont: + buf += (core[:-1] if core.endswith("\\") else core) + " " continue - out.append(buf + stripped) + out.append(buf + core) buf = "" - if buf: + if buf.strip(): out.append(buf) return out @@ -285,6 +303,13 @@ def case(what, ci, cmake, want): SELF_CI.replace("hidden_test ", "").replace(" - name: Build", " # NB: adding an unknown target to `cmake --build --target ...` is a hard ninja error\n" " - name: Build"), SELF_CMAKE, 0) + # … and a comment AFTER a continuation is the same prose, one hop in: the continuations are + # joined first, so it is no longer at the start of the logical line (found in #1601's review). + case("a # comment after a continuation contributes no target names", + SELF_CI.replace("hidden_test ", "").replace( + " plain_test \\\n", + " # notatarget trailingprose \\\n plain_test \\\n"), + SELF_CMAKE, 0) # Unrelated guards must not fail a tree. case("a target under a non-option guard is left alone", SELF_CI, SELF_CMAKE.replace("if(ONEBIT_NPU)", "if(NOT WIN32)"), 0)