[llvm-branch-commits] [llvm] [BOLT] Improve file handling in NFC-Mode (PR #146513)
Paschalis Mpeis via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Jul 1 06:48:54 PDT 2025
https://github.com/paschalis-mpeis updated https://github.com/llvm/llvm-project/pull/146513
>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 1/4] [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)
>From 5bcb1c9b65e000ba5b2299cff49743820b0af430 Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis <Paschalis.Mpeis at arm.com>
Date: Tue, 1 Jul 2025 12:50:08 +0100
Subject: [PATCH 2/4] python formatter and nits
---
bolt/utils/nfc-check-setup.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/bolt/utils/nfc-check-setup.py b/bolt/utils/nfc-check-setup.py
index 812689bdce75a..692b3e48e0d44 100755
--- a/bolt/utils/nfc-check-setup.py
+++ b/bolt/utils/nfc-check-setup.py
@@ -81,7 +81,7 @@ def main():
source_dir = None
# find the repo directory
try:
- CMCacheFilename=f"{args.build_dir}/CMakeCache.txt"
+ 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)
@@ -93,6 +93,7 @@ def main():
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
)
@@ -132,6 +133,7 @@ def main():
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
)
>From 2939a3ec27974aee1e7ca1f6e527e89b42512d8b Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis <Paschalis.Mpeis at arm.com>
Date: Tue, 1 Jul 2025 12:55:46 +0100
Subject: [PATCH 3/4] code formatter (2)
---
bolt/utils/nfc-check-setup.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/bolt/utils/nfc-check-setup.py b/bolt/utils/nfc-check-setup.py
index 692b3e48e0d44..497f3997545ff 100755
--- a/bolt/utils/nfc-check-setup.py
+++ b/bolt/utils/nfc-check-setup.py
@@ -93,7 +93,7 @@ def main():
sys.exit(e)
# build the current commit
- print ("NFC-Setup: Building current revision..")
+ print("NFC-Setup: Building current revision..")
subprocess.run(
shlex.split("cmake --build . --target llvm-bolt"), cwd=args.build_dir
)
@@ -133,7 +133,7 @@ def main():
new_ref = get_git_ref_or_rev(source_dir)
# build the previous commit
- print ("NFC-Setup: Building previous revision..")
+ print("NFC-Setup: Building previous revision..")
subprocess.run(
shlex.split("cmake --build . --target llvm-bolt"), cwd=args.build_dir
)
>From 6648b77cf456b635ea03c3bef299bc631f5ac8e0 Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis <Paschalis.Mpeis at arm.com>
Date: Tue, 1 Jul 2025 13:22:14 +0100
Subject: [PATCH 4/4] Handling switch back
---
bolt/utils/nfc-check-setup.py | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/bolt/utils/nfc-check-setup.py b/bolt/utils/nfc-check-setup.py
index 497f3997545ff..6cf1df5c177ae 100755
--- a/bolt/utils/nfc-check-setup.py
+++ b/bolt/utils/nfc-check-setup.py
@@ -138,11 +138,7 @@ def main():
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")
-
+ # A build error may have occurred, so switch back before renaming.
if args.switch_back:
if stash:
subprocess.run(shlex.split("git stash pop"), cwd=source_dir)
@@ -153,6 +149,12 @@ def main():
f"to {new_ref}. Local changes were stashed. Switch back using\n\t"
f"git checkout {old_ref}\n"
)
+
+ # 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")
+
print(
f"Build directory {args.build_dir} is ready to run BOLT tests, e.g.\n"
"\tbin/llvm-lit -sv tools/bolt/test\nor\n"
More information about the llvm-branch-commits
mailing list