Skip to content

Commit bc2e590

Browse files
authored
fix(toolshed): accept // seals so C/C++ generated files can be sealed (#2539)
`check_generated_file_seals.py` declares three comment styles for the seal line, one per generated-file family: _COMMENT_CHARS = {".py": b"#", ..., ".rst": b"..", ".c": b"//", ".cpp": b"//", ".h": b"//"} and `validate_generated_file_seal` compares the seal's captured prefix against `expected_comment_prefix(filepath)` so a `.rst` file cannot be sealed with a `#`, and so on. But the marker regex only ever accepts two of the three: rb"^(?P<prefix>#|\.\.) " `//` can never be captured, so `fullmatch` returns None for any sealed `.c` / `.cpp` / `.h` file and it is rejected as `MALFORMED generated-file seal` before the prefix comparison runs at all. The `b"//"` entries in `_COMMENT_CHARS` and the branch that would validate them are dead. Add `//` to the alternation, with a note tying it to `_COMMENT_CHARS` so the two do not drift again. This also adds the first tests for the script, under `toolshed/tests/`, and runs them alongside the existing `ci/tools/tests` in the nightly tooling job. The parametrized case is driven from `_COMMENT_CHARS` itself, so a future entry whose prefix the regex cannot match fails immediately instead of silently becoming dead code.
1 parent 8457bb0 commit bc2e590

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

toolshed/check_generated_file_seals.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
assert GENERATED_FILE_MARKER_FRAGMENT in GENERATED_FILE_SEAL_TOKEN
1717
_TOKEN_BYTES = GENERATED_FILE_SEAL_TOKEN.encode("ascii")
1818
_MARKER_REGEX = re.compile(
19-
rb"^(?P<prefix>#|\.\.) "
19+
# Keep the alternation in sync with the values of _COMMENT_CHARS below:
20+
# a prefix that is not matched here can never reach the
21+
# expected_comment_prefix() comparison in validate_generated_file_seal().
22+
rb"^(?P<prefix>#|\.\.|//) "
2023
+ re.escape(_TOKEN_BYTES)
2124
+ rb" format=(?P<format>[0-9]+); content-sha256=(?P<digest>[0-9a-f]{64})\n$"
2225
)

0 commit comments

Comments
 (0)