From b6492272e44f5b78bc7e5b5c33ba8d8194e027de Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Sun, 8 Nov 2026 19:32:46 -0400 Subject: [PATCH] copyright.py: skip untracked generated sources in a build tree A build tree's generated sources carry no notice by design, and .h/.c are known styles, so an untracked build*/generated/*.h went straight to missing[] rather than being skipped the way an unknown-style file is. A developer clone with a build dir therefore read 36 'missing copyright notice' lines while main was clean -- the same shape as engine#1564 (.hrx123/logs), one step further in: there the style was unknown, here it is known and the file is simply generated. Only the untracked case is skipped. A TRACKED file under a build directory is still an error, because then it is repo content: the test pins both directions. before: missing copyright notice: build1336/generated/recipes_default.h (x36) after: (nothing; the same clone is clean) Refs engine#1564. --- tests/copyright_check_untracked_test.py | 18 ++++++++++++++++++ tools/copyright.py | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/tests/copyright_check_untracked_test.py b/tests/copyright_check_untracked_test.py index 9e5fd37b8..cbe0fd5c6 100755 --- a/tests/copyright_check_untracked_test.py +++ b/tests/copyright_check_untracked_test.py @@ -147,5 +147,23 @@ def git(repo, *args): check("no comment style known" in (rc.stdout + rc.stderr), "and it is named as an unknown style", rc.stdout + rc.stderr) + # A build tree's generated sources carry no notice by design, and `.h` IS a known style, so before this + # an untracked `build*/generated/*.h` went straight to missing[] -- 36 of them in a developer clone with a + # build dir, while `main` was clean. Untracked + under a build dir is skipped; TRACKED is still an error. + git(repo, "rm", "-q", "--cached", "probe-dump.jsonl") + git(repo, "commit", "-q", "-m", "drop the tracked jsonl") + os.makedirs(os.path.join(repo, "build-1336", "generated")) + with open(os.path.join(repo, "build-1336", "generated", "recipes_default.h"), "w") as f: + f.write("static const int k = 1;\n") + rc = run(repo, "--check") + check(rc.returncode == 0, + "an UNTRACKED generated source in a build tree is skipped, not failed", + rc.stdout + rc.stderr) + git(repo, "add", "-f", "build-1336/generated/recipes_default.h") + git(repo, "commit", "-q", "-m", "track a generated header") + rc = run(repo, "--check") + check(rc.returncode != 0, "the same generated source TRACKED is still an error: it is repo content now", + rc.stdout + rc.stderr) + print(f"copyright_check_untracked_test: {len(FAIL)} failure(s)") sys.exit(1 if FAIL else 0) diff --git a/tools/copyright.py b/tools/copyright.py index df4a0f73a..278812a53 100644 --- a/tools/copyright.py +++ b/tools/copyright.py @@ -10,6 +10,7 @@ """ import argparse import fnmatch +import re import subprocess import sys @@ -126,6 +127,21 @@ def exempt(path): NOTICE_WINDOW = 20 # the lines has_notice() looks at; duplicated_notice() uses the same window +BUILD_DIR = re.compile(r"(^|/)(build[^/]*|cmake-build[^/]*)/") + + +def under_build_dir(path): + """True when a path sits in a build tree, tracked or not. + + A build tree holds generated sources (`build*/generated/recipes_default.h` and friends) that carry no + notice by design, and it is never repo content until someone commits it. Before this, an untracked + generated `.h` was not skipped the way an unknown-style file is -- `.h` IS a known style, so it went + straight to missing[] -- and a developer clone with a build dir read 36 "missing copyright notice" + lines while `main` was clean. Only the untracked case is skipped: a TRACKED file in a build tree is + still an error, because then it is repo content (engine#1564's argument, applied to a known style). + """ + return BUILD_DIR.search(path) is not None + def has_notice(text): head = "\n".join(text.splitlines()[:NOTICE_WINDOW]) @@ -175,6 +191,8 @@ def listing(*args): for path in filter(None, files): if exempt(path): continue + if path in untracked and under_build_dir(path): + continue block = notice_block(path) if block is None: # A file this tool cannot attach a notice to. If it is IN the repository that is a real gap -- a source