Skip to content

Commit d681c73

Browse files
[BOLT] Create marker for source changes in nfc-mode testing. (#142931)
Currently NFC tests only trigger when the llvm-bolt binary itself changes. This patch adds `--check-bolt-sources`, which scans git output for any modifications under bolt/, excluding: - bolt/docs - bolt/utils/docker - bolt/utils/dot2html If any matching files change between versions, a `.llvm-bolt.changes` marker is created. Buildbots can then use this marker to trigger in-tree tests.
1 parent a8998fa commit d681c73

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

bolt/utils/nfc-check-setup.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,29 @@
77
import sys
88
import textwrap
99

10+
def get_relevant_bolt_changes(dir: str) -> str:
11+
# Return a list of bolt source changes that are relevant to testing.
12+
all_changes = subprocess.run(
13+
shlex.split("git show HEAD --name-only --pretty=''"),
14+
cwd=dir,
15+
text=True,
16+
stdout=subprocess.PIPE,
17+
)
18+
keep_bolt = subprocess.run(
19+
shlex.split("grep '^bolt'"),
20+
input=all_changes.stdout,
21+
text=True,
22+
stdout=subprocess.PIPE,
23+
)
24+
keep_relevant = subprocess.run(
25+
shlex.split(
26+
"grep -v -e '^bolt/docs' -e '^bolt/utils/docker' -e '^bolt/utils/dot2html'"
27+
),
28+
input=keep_bolt.stdout,
29+
text=True,
30+
stdout=subprocess.PIPE,
31+
)
32+
return keep_relevant.stdout
1033

1134
def get_git_ref_or_rev(dir: str) -> str:
1235
# Run 'git symbolic-ref -q --short HEAD || git rev-parse --short HEAD'
@@ -36,6 +59,12 @@ def main():
3659
default=os.getcwd(),
3760
help="Path to BOLT build directory, default is current " "directory",
3861
)
62+
parser.add_argument(
63+
"--check-bolt-sources",
64+
default=False,
65+
action="store_true",
66+
help="Create a marker file (.llvm-bolt.changes) if any relevant BOLT sources are modified",
67+
)
3968
parser.add_argument(
4069
"--switch-back",
4170
default=False,
@@ -71,6 +100,16 @@ def main():
71100
# memorize the old hash for logging
72101
old_ref = get_git_ref_or_rev(source_dir)
73102

103+
if args.check_bolt_sources:
104+
marker = f"{args.build_dir}/.llvm-bolt.changes"
105+
if os.path.exists(marker):
106+
os.remove(marker)
107+
file_changes = get_relevant_bolt_changes(source_dir)
108+
# Create a marker file if any relevant BOLT source files changed.
109+
if len(file_changes) > 0:
110+
print(f"BOLT source changes were found:\n{file_changes}")
111+
open(marker, "a").close()
112+
74113
# determine whether a stash is needed
75114
stash = subprocess.run(
76115
shlex.split("git status --porcelain"),

0 commit comments

Comments
 (0)