Skip to content

Commit d55f8a3

Browse files
[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.
1 parent 768227b commit d55f8a3

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

bolt/utils/nfc-check-setup.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,26 @@ def main():
8080

8181
source_dir = None
8282
# find the repo directory
83-
with open(f"{args.build_dir}/CMakeCache.txt") as f:
84-
for line in f:
85-
m = re.match(r"LLVM_SOURCE_DIR:STATIC=(.*)", line)
86-
if m:
87-
source_dir = m.groups()[0]
88-
if not source_dir:
89-
sys.exit("Source directory is not found")
83+
try:
84+
CMCacheFilename=f"{args.build_dir}/CMakeCache.txt"
85+
with open(CMCacheFilename) as f:
86+
for line in f:
87+
m = re.match(r"LLVM_SOURCE_DIR:STATIC=(.*)", line)
88+
if m:
89+
source_dir = m.groups()[0]
90+
if not source_dir:
91+
raise Exception(f"Source directory not found: '{CMCacheFilename}'")
92+
except Exception as e:
93+
sys.exit(e)
9094

9195
# build the current commit
9296
subprocess.run(
9397
shlex.split("cmake --build . --target llvm-bolt"), cwd=args.build_dir
9498
)
99+
100+
if not os.path.exists(bolt_path):
101+
sys.exit(f"Failed to build the current revision: '{bolt_path}'")
102+
95103
# rename llvm-bolt
96104
os.replace(bolt_path, f"{bolt_path}.new")
97105
# memorize the old hash for logging
@@ -122,12 +130,17 @@ def main():
122130
subprocess.run(shlex.split(f"git checkout -f {args.cmp_rev}"), cwd=source_dir)
123131
# get the parent commit hash for logging
124132
new_ref = get_git_ref_or_rev(source_dir)
133+
125134
# build the previous commit
126135
subprocess.run(
127136
shlex.split("cmake --build . --target llvm-bolt"), cwd=args.build_dir
128137
)
138+
129139
# rename llvm-bolt
140+
if not os.path.exists(bolt_path):
141+
sys.exit(f"Failed to build the previous revision: '{bolt_path}'")
130142
os.replace(bolt_path, f"{bolt_path}.old")
143+
131144
if args.switch_back:
132145
if stash:
133146
subprocess.run(shlex.split("git stash pop"), cwd=source_dir)

0 commit comments

Comments
 (0)