[llvm-branch-commits] [llvm] [BOLT] Improve file handling in NFC-Mode (PR #146513)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Jul 1 05:17:22 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-bolt

Author: Paschalis Mpeis (paschalis-mpeis)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/146513.diff


1 Files Affected:

- (modified) bolt/utils/nfc-check-setup.py (+22-7) 


``````````diff
diff --git a/bolt/utils/nfc-check-setup.py b/bolt/utils/nfc-check-setup.py
index 4884e616a0fa3..497f3997545ff 100755
--- a/bolt/utils/nfc-check-setup.py
+++ b/bolt/utils/nfc-check-setup.py
@@ -80,18 +80,27 @@ 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
+    print("NFC-Setup: Building current revision..")
     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 +131,18 @@ 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
+    print("NFC-Setup: Building previous revision..")
     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)

``````````

</details>


https://github.com/llvm/llvm-project/pull/146513


More information about the llvm-branch-commits mailing list