|
7 | 7 | import sys
|
8 | 8 | import textwrap
|
9 | 9 |
|
| 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 |
10 | 33 |
|
11 | 34 | def get_git_ref_or_rev(dir: str) -> str:
|
12 | 35 | # Run 'git symbolic-ref -q --short HEAD || git rev-parse --short HEAD'
|
@@ -36,6 +59,12 @@ def main():
|
36 | 59 | default=os.getcwd(),
|
37 | 60 | help="Path to BOLT build directory, default is current " "directory",
|
38 | 61 | )
|
| 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 | + ) |
39 | 68 | parser.add_argument(
|
40 | 69 | "--switch-back",
|
41 | 70 | default=False,
|
@@ -71,6 +100,16 @@ def main():
|
71 | 100 | # memorize the old hash for logging
|
72 | 101 | old_ref = get_git_ref_or_rev(source_dir)
|
73 | 102 |
|
| 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 | + |
74 | 113 | # determine whether a stash is needed
|
75 | 114 | stash = subprocess.run(
|
76 | 115 | shlex.split("git status --porcelain"),
|
|
0 commit comments