Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tests/copyright_check_untracked_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
18 changes: 18 additions & 0 deletions tools/copyright.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"""
import argparse
import fnmatch
import re
import subprocess
import sys

Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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
Expand Down
Loading