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

Paschalis Mpeis via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 5 08:41:22 PDT 2025


https://github.com/paschalis-mpeis updated https://github.com/llvm/llvm-project/pull/142931

>From 1066d0f5a09cc7deb538b5826b9a6d8d57882097 Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis <Paschalis.Mpeis at arm.com>
Date: Thu, 5 Jun 2025 09:11:16 +0100
Subject: [PATCH 1/2] [BOLT] Create marker for source changes in nfc-mode
 testing.

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.
---
 bolt/utils/nfc-check-setup.py | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/bolt/utils/nfc-check-setup.py b/bolt/utils/nfc-check-setup.py
index 710b183505853..ce101f34bb644 100755
--- a/bolt/utils/nfc-check-setup.py
+++ b/bolt/utils/nfc-check-setup.py
@@ -7,6 +7,18 @@
 import sys
 import textwrap
 
+def get_relevant_bolt_changes(dir: str) -> str:
+    # Return a list of bolt source changes that are relevant to tests.
+    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'
@@ -36,6 +48,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,
@@ -71,6 +89,16 @@ def main():
     # memorize the old hash for logging
     old_ref = get_git_ref_or_rev(source_dir)
 
+    if args.check_bolt_changes:
+        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"),

>From d037f0d9cf6b9e6a78f382598edcf664d57436b0 Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis <Paschalis.Mpeis at arm.com>
Date: Thu, 5 Jun 2025 16:19:00 +0100
Subject: [PATCH 2/2] Fix formatter and flag name.

---
 bolt/utils/nfc-check-setup.py | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/bolt/utils/nfc-check-setup.py b/bolt/utils/nfc-check-setup.py
index ce101f34bb644..feb61499263f9 100755
--- a/bolt/utils/nfc-check-setup.py
+++ b/bolt/utils/nfc-check-setup.py
@@ -8,16 +8,24 @@
 import textwrap
 
 def get_relevant_bolt_changes(dir: str) -> str:
-    # Return a list of bolt source changes that are relevant to tests.
+    # 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)
+        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)
+        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)
+        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:
@@ -89,14 +97,14 @@ def main():
     # memorize the old hash for logging
     old_ref = get_git_ref_or_rev(source_dir)
 
-    if args.check_bolt_changes:
+    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}")
+            print(f"BOLT source changes were found:\n{file_changes}")
             open(marker, "a").close()
 
     # determine whether a stash is needed



More information about the llvm-commits mailing list