7
7
import sys
8
8
import textwrap
9
9
10
+ msg_prefix = "\n > NFC-Mode:"
11
+
10
12
def get_relevant_bolt_changes (dir : str ) -> str :
11
13
# Return a list of bolt source changes that are relevant to testing.
12
14
all_changes = subprocess .run (
@@ -49,7 +51,7 @@ def switch_back(
49
51
# the HEAD is. Must be called after checking out the previous commit on all
50
52
# exit paths.
51
53
if switch_back :
52
- print (" Switching back to current revision.." )
54
+ print (f" { msg_prefix } Switching back to current revision.." )
53
55
if stash :
54
56
subprocess .run (shlex .split ("git stash pop" ), cwd = source_dir )
55
57
subprocess .run (shlex .split (f"git checkout { old_ref } " ), cwd = source_dir )
@@ -64,8 +66,10 @@ def main():
64
66
parser = argparse .ArgumentParser (
65
67
description = textwrap .dedent (
66
68
"""
67
- This script builds two versions of BOLT (with the current and
68
- previous revision).
69
+ This script builds two versions of BOLT:
70
+ llvm-bolt.new, using the current revision, and llvm-bolt.old using
71
+ the previous revision. These can be used to check whether the
72
+ current revision changes BOLT's functional behavior.
69
73
"""
70
74
)
71
75
)
@@ -104,7 +108,7 @@ def main():
104
108
if not args .create_wrapper and len (wrapper_args ) > 0 :
105
109
parser .parse_args ()
106
110
107
- # find the repo directory
111
+ # Find the repo directory.
108
112
source_dir = None
109
113
try :
110
114
CMCacheFilename = f"{ args .build_dir } /CMakeCache.txt"
@@ -118,23 +122,22 @@ def main():
118
122
except Exception as e :
119
123
sys .exit (e )
120
124
121
- # clean the previous llvm-bolt if it exists
125
+ # Clean the previous llvm-bolt if it exists.
122
126
bolt_path = f"{ args .build_dir } /bin/llvm-bolt"
123
127
if os .path .exists (bolt_path ):
124
128
os .remove (bolt_path )
125
129
126
- # build the current commit
127
- print ("NFC-Setup: Building current revision.." )
130
+ # Build the current commit.
131
+ print (f" { msg_prefix } Building current revision.." )
128
132
subprocess .run (
129
133
shlex .split ("cmake --build . --target llvm-bolt" ), cwd = args .build_dir
130
134
)
131
135
132
136
if not os .path .exists (bolt_path ):
133
137
sys .exit (f"Failed to build the current revision: '{ bolt_path } '" )
134
138
135
- # rename llvm-bolt
139
+ # Rename llvm-bolt and memorize the old hash for logging.
136
140
os .replace (bolt_path , f"{ bolt_path } .new" )
137
- # memorize the old hash for logging
138
141
old_ref = get_git_ref_or_rev (source_dir )
139
142
140
143
if args .check_bolt_sources :
@@ -147,7 +150,7 @@ def main():
147
150
print (f"BOLT source changes were found:\n { file_changes } " )
148
151
open (marker , "a" ).close ()
149
152
150
- # determine whether a stash is needed
153
+ # Determine whether a stash is needed.
151
154
stash = subprocess .run (
152
155
shlex .split ("git status --porcelain" ),
153
156
cwd = source_dir ,
@@ -156,40 +159,40 @@ def main():
156
159
text = True ,
157
160
).stdout
158
161
if stash :
159
- # save local changes before checkout
162
+ # Save local changes before checkout.
160
163
subprocess .run (shlex .split ("git stash push -u" ), cwd = source_dir )
161
- # check out the previous/cmp commit
164
+
165
+ # Check out the previous/cmp commit and get its commit hash for logging.
162
166
subprocess .run (shlex .split (f"git checkout -f { args .cmp_rev } " ), cwd = source_dir )
163
- # get the parent commit hash for logging
164
167
new_ref = get_git_ref_or_rev (source_dir )
165
168
166
- # build the previous commit
167
- print ("NFC-Setup: Building previous revision.." )
169
+ # Build the previous commit.
170
+ print (f" { msg_prefix } Building previous revision.." )
168
171
subprocess .run (
169
172
shlex .split ("cmake --build . --target llvm-bolt" ), cwd = args .build_dir
170
173
)
171
174
172
- # rename llvm-bolt
175
+ # Rename llvm-bolt.
173
176
if not os .path .exists (bolt_path ):
174
177
print (f"Failed to build the previous revision: '{ bolt_path } '" )
175
178
switch_back (args .switch_back , stash , source_dir , old_ref , new_ref )
176
179
sys .exit (1 )
177
180
os .replace (bolt_path , f"{ bolt_path } .old" )
178
181
179
- # symlink llvm-bolt-wrapper
182
+ # Symlink llvm-bolt-wrapper
180
183
if args .create_wrapper :
184
+ print (f"{ msg_prefix } Creating llvm-bolt wrapper.." )
181
185
script_dir = os .path .dirname (os .path .abspath (__file__ ))
182
186
wrapper_path = f"{ script_dir } /llvm-bolt-wrapper.py"
183
187
try :
184
- # set up llvm-bolt-wrapper.ini
188
+ # Set up llvm-bolt-wrapper.ini
185
189
ini = subprocess .check_output (
186
190
shlex .split (f"{ wrapper_path } { bolt_path } .old { bolt_path } .new" )
187
191
+ wrapper_args ,
188
192
text = True ,
189
193
)
190
194
with open (f"{ args .build_dir } /bin/llvm-bolt-wrapper.ini" , "w" ) as f :
191
195
f .write (ini )
192
- # symlink llvm-bolt-wrapper
193
196
os .symlink (wrapper_path , bolt_path )
194
197
except Exception as e :
195
198
print ("Failed to create a wrapper:\n " + str (e ))
@@ -199,11 +202,17 @@ def main():
199
202
switch_back (args .switch_back , stash , source_dir , old_ref , new_ref )
200
203
201
204
print (
202
- f"Build directory { args .build_dir } is ready to run BOLT tests, e.g.\n "
203
- "\t bin/llvm-lit -sv tools/bolt/test\n or\n "
204
- "\t bin/llvm-lit -sv tools/bolttests"
205
+ f"{ msg_prefix } Completed!\n Build directory { args .build_dir } is ready for"
206
+ " NFC-Mode comparison between the two revisions."
205
207
)
206
208
209
+ if args .create_wrapper :
210
+ print (
211
+ "Can run BOLT tests using:\n "
212
+ "\t bin/llvm-lit -sv tools/bolt/test\n or\n "
213
+ "\t bin/llvm-lit -sv tools/bolttests"
214
+ )
215
+
207
216
208
217
if __name__ == "__main__" :
209
218
main ()
0 commit comments