@@ -42,6 +42,23 @@ def get_git_ref_or_rev(dir: str) -> str:
42
42
cmd_rev = "git rev-parse --short HEAD"
43
43
return subprocess .check_output (shlex .split (cmd_rev ), cwd = dir , text = True ).strip ()
44
44
45
+ def switch_back (
46
+ switch_back : bool , stash : bool , source_dir : str , old_ref : str , new_ref : str
47
+ ):
48
+ # Switch back to the current revision if needed and inform the user of where
49
+ # the HEAD is. Must be called after checking out the previous commit on all
50
+ # exit paths.
51
+ if switch_back :
52
+ print ("Switching back to current revision.." )
53
+ if stash :
54
+ subprocess .run (shlex .split ("git stash pop" ), cwd = source_dir )
55
+ subprocess .run (shlex .split (f"git checkout { old_ref } " ), cwd = source_dir )
56
+ else :
57
+ print (
58
+ f"The repository { source_dir } has been switched from { old_ref } "
59
+ f"to { new_ref } . Local changes were stashed. Switch back using\n \t "
60
+ f"git checkout { old_ref } \n "
61
+ )
45
62
46
63
def main ():
47
64
parser = argparse .ArgumentParser (
@@ -87,10 +104,8 @@ def main():
87
104
if not args .create_wrapper and len (wrapper_args ) > 0 :
88
105
parser .parse_args ()
89
106
90
- bolt_path = f"{ args .build_dir } /bin/llvm-bolt"
91
-
92
- source_dir = None
93
107
# find the repo directory
108
+ source_dir = None
94
109
try :
95
110
CMCacheFilename = f"{ args .build_dir } /CMakeCache.txt"
96
111
with open (CMCacheFilename ) as f :
@@ -103,6 +118,11 @@ def main():
103
118
except Exception as e :
104
119
sys .exit (e )
105
120
121
+ # clean the previous llvm-bolt if it exists
122
+ bolt_path = f"{ args .build_dir } /bin/llvm-bolt"
123
+ if os .path .exists (bolt_path ):
124
+ os .remove (bolt_path )
125
+
106
126
# build the current commit
107
127
print ("NFC-Setup: Building current revision.." )
108
128
subprocess .run (
@@ -151,7 +171,9 @@ def main():
151
171
152
172
# rename llvm-bolt
153
173
if not os .path .exists (bolt_path ):
154
- sys .exit (f"Failed to build the previous revision: '{ bolt_path } '" )
174
+ print (f"Failed to build the previous revision: '{ bolt_path } '" )
175
+ switch_back (args .switch_back , stash , source_dir , old_ref , new_ref )
176
+ sys .exit (1 )
155
177
os .replace (bolt_path , f"{ bolt_path } .old" )
156
178
157
179
# symlink llvm-bolt-wrapper
@@ -170,18 +192,12 @@ def main():
170
192
# symlink llvm-bolt-wrapper
171
193
os .symlink (wrapper_path , bolt_path )
172
194
except Exception as e :
173
- sys .exit ("Failed to create a wrapper:\n " + str (e ))
195
+ print ("Failed to create a wrapper:\n " + str (e ))
196
+ switch_back (args .switch_back , stash , source_dir , old_ref , new_ref )
197
+ sys .exit (1 )
198
+
199
+ switch_back (args .switch_back , stash , source_dir , old_ref , new_ref )
174
200
175
- if args .switch_back :
176
- if stash :
177
- subprocess .run (shlex .split ("git stash pop" ), cwd = source_dir )
178
- subprocess .run (shlex .split (f"git checkout { old_ref } " ), cwd = source_dir )
179
- else :
180
- print (
181
- f"The repository { source_dir } has been switched from { old_ref } "
182
- f"to { new_ref } . Local changes were stashed. Switch back using\n \t "
183
- f"git checkout { old_ref } \n "
184
- )
185
201
print (
186
202
f"Build directory { args .build_dir } is ready to run BOLT tests, e.g.\n "
187
203
"\t bin/llvm-lit -sv tools/bolt/test\n or\n "
0 commit comments