[llvm] Users/paschalis mpeis/nfc check improve file handling (PR #146513)

Paschalis Mpeis via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 1 04:41:51 PDT 2025


https://github.com/paschalis-mpeis created https://github.com/llvm/llvm-project/pull/146513

None

>From ccdabc59f77204827a0a280e0d1651d32eea4e8f Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis <Paschalis.Mpeis at arm.com>
Date: Sat, 28 Jun 2025 13:23:16 +0100
Subject: [PATCH 1/3] DRAFT: remove llvm-bolt-wrapper logic from nfc setup

---
 bolt/utils/nfc-check-setup.py | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)

diff --git a/bolt/utils/nfc-check-setup.py b/bolt/utils/nfc-check-setup.py
index 275ac7b886d00..9e4fc8bc101b1 100755
--- a/bolt/utils/nfc-check-setup.py
+++ b/bolt/utils/nfc-check-setup.py
@@ -48,8 +48,7 @@ def main():
         description=textwrap.dedent(
             """
             This script builds two versions of BOLT (with the current and
-            previous revision) and sets up symlink for llvm-bolt-wrapper.
-            Passes the options through to llvm-bolt-wrapper.
+            previous revision).
             """
         )
     )
@@ -76,7 +75,7 @@ def main():
         default="HEAD^",
         help="Revision to checkout to compare vs HEAD",
     )
-    args, wrapper_args = parser.parse_known_args()
+    args = parser.parse_args()
     bolt_path = f"{args.build_dir}/bin/llvm-bolt"
 
     source_dir = None
@@ -90,7 +89,6 @@ def main():
         sys.exit("Source directory is not found")
 
     script_dir = os.path.dirname(os.path.abspath(__file__))
-    wrapper_path = f"{script_dir}/llvm-bolt-wrapper.py"
     # build the current commit
     subprocess.run(
         shlex.split("cmake --build . --target llvm-bolt"), cwd=args.build_dir
@@ -131,15 +129,6 @@ def main():
     )
     # rename llvm-bolt
     os.replace(bolt_path, f"{bolt_path}.old")
-    # set up llvm-bolt-wrapper.ini
-    ini = subprocess.check_output(
-        shlex.split(f"{wrapper_path} {bolt_path}.old {bolt_path}.new") + wrapper_args,
-        text=True,
-    )
-    with open(f"{args.build_dir}/bin/llvm-bolt-wrapper.ini", "w") as f:
-        f.write(ini)
-    # symlink llvm-bolt-wrapper
-    os.symlink(wrapper_path, bolt_path)
     if args.switch_back:
         if stash:
             subprocess.run(shlex.split("git stash pop"), cwd=source_dir)

>From 768227b6be4e71f6c7fce803e7ab7eab4c88d332 Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis <Paschalis.Mpeis at arm.com>
Date: Tue, 1 Jul 2025 10:14:24 +0100
Subject: [PATCH 2/3] Addressing reviewers

---
 bolt/utils/nfc-check-setup.py | 1 -
 1 file changed, 1 deletion(-)

diff --git a/bolt/utils/nfc-check-setup.py b/bolt/utils/nfc-check-setup.py
index 9e4fc8bc101b1..4884e616a0fa3 100755
--- a/bolt/utils/nfc-check-setup.py
+++ b/bolt/utils/nfc-check-setup.py
@@ -88,7 +88,6 @@ def main():
     if not source_dir:
         sys.exit("Source directory is not found")
 
-    script_dir = os.path.dirname(os.path.abspath(__file__))
     # build the current commit
     subprocess.run(
         shlex.split("cmake --build . --target llvm-bolt"), cwd=args.build_dir

>From d55f8a334f1cc0ee72a7a8bcfdbb1695222ef91a Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis <Paschalis.Mpeis at arm.com>
Date: Tue, 1 Jul 2025 12:37:31 +0100
Subject: [PATCH 3/3] [BOLT] Improve file handling in NFC-Mode

This patch introduce the following improvements:
- Catch an exception when the CMakeCache.txt is not present
- Bail out gracefully when llvm-bolt did not build successfully the
  current or previous revision.
---
 bolt/utils/nfc-check-setup.py | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/bolt/utils/nfc-check-setup.py b/bolt/utils/nfc-check-setup.py
index 4884e616a0fa3..812689bdce75a 100755
--- a/bolt/utils/nfc-check-setup.py
+++ b/bolt/utils/nfc-check-setup.py
@@ -80,18 +80,26 @@ def main():
 
     source_dir = None
     # find the repo directory
-    with open(f"{args.build_dir}/CMakeCache.txt") as f:
-        for line in f:
-            m = re.match(r"LLVM_SOURCE_DIR:STATIC=(.*)", line)
-            if m:
-                source_dir = m.groups()[0]
-    if not source_dir:
-        sys.exit("Source directory is not found")
+    try:
+        CMCacheFilename=f"{args.build_dir}/CMakeCache.txt"
+        with open(CMCacheFilename) as f:
+            for line in f:
+                m = re.match(r"LLVM_SOURCE_DIR:STATIC=(.*)", line)
+                if m:
+                    source_dir = m.groups()[0]
+        if not source_dir:
+            raise Exception(f"Source directory not found: '{CMCacheFilename}'")
+    except Exception as e:
+        sys.exit(e)
 
     # build the current commit
     subprocess.run(
         shlex.split("cmake --build . --target llvm-bolt"), cwd=args.build_dir
     )
+
+    if not os.path.exists(bolt_path):
+        sys.exit(f"Failed to build the current revision: '{bolt_path}'")
+
     # rename llvm-bolt
     os.replace(bolt_path, f"{bolt_path}.new")
     # memorize the old hash for logging
@@ -122,12 +130,17 @@ def main():
     subprocess.run(shlex.split(f"git checkout -f {args.cmp_rev}"), cwd=source_dir)
     # get the parent commit hash for logging
     new_ref = get_git_ref_or_rev(source_dir)
+
     # build the previous commit
     subprocess.run(
         shlex.split("cmake --build . --target llvm-bolt"), cwd=args.build_dir
     )
+
     # rename llvm-bolt
+    if not os.path.exists(bolt_path):
+        sys.exit(f"Failed to build the previous revision: '{bolt_path}'")
     os.replace(bolt_path, f"{bolt_path}.old")
+
     if args.switch_back:
         if stash:
             subprocess.run(shlex.split("git stash pop"), cwd=source_dir)



More information about the llvm-commits mailing list