Skip to content

[BOLT] Create marker for source changes in nfc-mode testing. #142931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
39 changes: 39 additions & 0 deletions bolt/utils/nfc-check-setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,29 @@
import sys
import textwrap

def get_relevant_bolt_changes(dir: str) -> str:
# Return a list of bolt source changes that are relevant to testing.
all_changes = subprocess.run(
shlex.split("git show HEAD --name-only --pretty=''"),
cwd=dir,
text=True,
stdout=subprocess.PIPE,
)
keep_bolt = subprocess.run(
shlex.split("grep '^bolt'"),
input=all_changes.stdout,
text=True,
stdout=subprocess.PIPE,
)
keep_relevant = subprocess.run(
shlex.split(
"grep -v -e '^bolt/docs' -e '^bolt/utils/docker' -e '^bolt/utils/dot2html'"
),
input=keep_bolt.stdout,
text=True,
stdout=subprocess.PIPE,
)
return keep_relevant.stdout

def get_git_ref_or_rev(dir: str) -> str:
# Run 'git symbolic-ref -q --short HEAD || git rev-parse --short HEAD'
Expand Down Expand Up @@ -36,6 +59,12 @@ def main():
default=os.getcwd(),
help="Path to BOLT build directory, default is current " "directory",
)
parser.add_argument(
"--check-bolt-sources",
default=False,
action="store_true",
help="Create a marker file (.llvm-bolt.changes) if any relevant BOLT sources are modified",
)
parser.add_argument(
"--switch-back",
default=False,
Expand Down Expand Up @@ -71,6 +100,16 @@ def main():
# memorize the old hash for logging
old_ref = get_git_ref_or_rev(source_dir)

if args.check_bolt_sources:
marker = f"{args.build_dir}/.llvm-bolt.changes"
if os.path.exists(marker):
os.remove(marker)
file_changes = get_relevant_bolt_changes(source_dir)
# Create a marker file if any relevant BOLT source files changed.
if len(file_changes) > 0:
print(f"BOLT source changes were found:\n{file_changes}")
open(marker, "a").close()

# determine whether a stash is needed
stash = subprocess.run(
shlex.split("git status --porcelain"),
Expand Down
Loading