77import sys
88import textwrap
99
10+ msg_prefix = "\n > NFC-Mode:"
11+
1012def get_relevant_bolt_changes (dir : str ) -> str :
1113 # Return a list of bolt source changes that are relevant to testing.
1214 all_changes = subprocess .run (
@@ -49,7 +51,7 @@ def switch_back(
4951 # the HEAD is. Must be called after checking out the previous commit on all
5052 # exit paths.
5153 if switch_back :
52- print (" Switching back to current revision.." )
54+ print (f" { msg_prefix } Switching back to current revision.." )
5355 if stash :
5456 subprocess .run (shlex .split ("git stash pop" ), cwd = source_dir )
5557 subprocess .run (shlex .split (f"git checkout { old_ref } " ), cwd = source_dir )
@@ -64,8 +66,10 @@ def main():
6466 parser = argparse .ArgumentParser (
6567 description = textwrap .dedent (
6668 """
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.
6973 """
7074 )
7175 )
@@ -104,7 +108,7 @@ def main():
104108 if not args .create_wrapper and len (wrapper_args ) > 0 :
105109 parser .parse_args ()
106110
107- # find the repo directory
111+ # Find the repo directory.
108112 source_dir = None
109113 try :
110114 CMCacheFilename = f"{ args .build_dir } /CMakeCache.txt"
@@ -118,23 +122,22 @@ def main():
118122 except Exception as e :
119123 sys .exit (e )
120124
121- # clean the previous llvm-bolt if it exists
125+ # Clean the previous llvm-bolt if it exists.
122126 bolt_path = f"{ args .build_dir } /bin/llvm-bolt"
123127 if os .path .exists (bolt_path ):
124128 os .remove (bolt_path )
125129
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.." )
128132 subprocess .run (
129133 shlex .split ("cmake --build . --target llvm-bolt" ), cwd = args .build_dir
130134 )
131135
132136 if not os .path .exists (bolt_path ):
133137 sys .exit (f"Failed to build the current revision: '{ bolt_path } '" )
134138
135- # rename llvm-bolt
139+ # Rename llvm-bolt and memorize the old hash for logging.
136140 os .replace (bolt_path , f"{ bolt_path } .new" )
137- # memorize the old hash for logging
138141 old_ref = get_git_ref_or_rev (source_dir )
139142
140143 if args .check_bolt_sources :
@@ -147,7 +150,7 @@ def main():
147150 print (f"BOLT source changes were found:\n { file_changes } " )
148151 open (marker , "a" ).close ()
149152
150- # determine whether a stash is needed
153+ # Determine whether a stash is needed.
151154 stash = subprocess .run (
152155 shlex .split ("git status --porcelain" ),
153156 cwd = source_dir ,
@@ -156,40 +159,40 @@ def main():
156159 text = True ,
157160 ).stdout
158161 if stash :
159- # save local changes before checkout
162+ # Save local changes before checkout.
160163 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.
162166 subprocess .run (shlex .split (f"git checkout -f { args .cmp_rev } " ), cwd = source_dir )
163- # get the parent commit hash for logging
164167 new_ref = get_git_ref_or_rev (source_dir )
165168
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.." )
168171 subprocess .run (
169172 shlex .split ("cmake --build . --target llvm-bolt" ), cwd = args .build_dir
170173 )
171174
172- # rename llvm-bolt
175+ # Rename llvm-bolt.
173176 if not os .path .exists (bolt_path ):
174177 print (f"Failed to build the previous revision: '{ bolt_path } '" )
175178 switch_back (args .switch_back , stash , source_dir , old_ref , new_ref )
176179 sys .exit (1 )
177180 os .replace (bolt_path , f"{ bolt_path } .old" )
178181
179- # symlink llvm-bolt-wrapper
182+ # Symlink llvm-bolt-wrapper
180183 if args .create_wrapper :
184+ print (f"{ msg_prefix } Creating llvm-bolt wrapper.." )
181185 script_dir = os .path .dirname (os .path .abspath (__file__ ))
182186 wrapper_path = f"{ script_dir } /llvm-bolt-wrapper.py"
183187 try :
184- # set up llvm-bolt-wrapper.ini
188+ # Set up llvm-bolt-wrapper.ini
185189 ini = subprocess .check_output (
186190 shlex .split (f"{ wrapper_path } { bolt_path } .old { bolt_path } .new" )
187191 + wrapper_args ,
188192 text = True ,
189193 )
190194 with open (f"{ args .build_dir } /bin/llvm-bolt-wrapper.ini" , "w" ) as f :
191195 f .write (ini )
192- # symlink llvm-bolt-wrapper
193196 os .symlink (wrapper_path , bolt_path )
194197 except Exception as e :
195198 print ("Failed to create a wrapper:\n " + str (e ))
@@ -199,11 +202,17 @@ def main():
199202 switch_back (args .switch_back , stash , source_dir , old_ref , new_ref )
200203
201204 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."
205207 )
206208
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+
207216
208217if __name__ == "__main__" :
209218 main ()
0 commit comments