Skip to content

Commit 625f9ee

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 ae9047b commit 625f9ee

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

bolt/utils/nfc-check-setup.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,26 @@ def main():
9191

9292
source_dir = None
9393
# find the repo directory
94-
with open(f"{args.build_dir}/CMakeCache.txt") as f:
95-
for line in f:
96-
m = re.match(r"LLVM_SOURCE_DIR:STATIC=(.*)", line)
97-
if m:
98-
source_dir = m.groups()[0]
99-
if not source_dir:
100-
sys.exit("Source directory is not found")
94+
try:
95+
CMCacheFilename=f"{args.build_dir}/CMakeCache.txt"
96+
with open(CMCacheFilename) as f:
97+
for line in f:
98+
m = re.match(r"LLVM_SOURCE_DIR:STATIC=(.*)", line)
99+
if m:
100+
source_dir = m.groups()[0]
101+
if not source_dir:
102+
raise Exception(f"Source directory not found: '{CMCacheFilename}'")
103+
except Exception as e:
104+
sys.exit(e)
101105

102106
# build the current commit
103107
subprocess.run(
104108
shlex.split("cmake --build . --target llvm-bolt"), cwd=args.build_dir
105109
)
110+
111+
if not os.path.exists(bolt_path):
112+
sys.exit(f"Failed to build the current revision: '{bolt_path}'")
113+
106114
# rename llvm-bolt
107115
os.replace(bolt_path, f"{bolt_path}.new")
108116
# memorize the old hash for logging
@@ -133,11 +141,15 @@ def main():
133141
subprocess.run(shlex.split(f"git checkout -f {args.cmp_rev}"), cwd=source_dir)
134142
# get the parent commit hash for logging
135143
new_ref = get_git_ref_or_rev(source_dir)
144+
136145
# build the previous commit
137146
subprocess.run(
138147
shlex.split("cmake --build . --target llvm-bolt"), cwd=args.build_dir
139148
)
149+
140150
# rename llvm-bolt
151+
if not os.path.exists(bolt_path):
152+
sys.exit(f"Failed to build the previous revision: '{bolt_path}'")
141153
os.replace(bolt_path, f"{bolt_path}.old")
142154

143155
# symlink llvm-bolt-wrapper

0 commit comments

Comments
 (0)