@@ -191,16 +191,13 @@ def generate_single_gyb_file(
191
191
# `sources_dir/gyb_generated`.
192
192
def generate_gyb_files_helper (
193
193
sources_dir : str ,
194
- destination_dir : Optional [ str ] ,
194
+ destination_dir : str ,
195
195
gyb_exec : str ,
196
196
add_source_locations : bool ,
197
197
verbose : bool ,
198
198
) -> None :
199
199
temp_files_dir = tempfile .gettempdir ()
200
200
make_dir_if_needed (temp_files_dir )
201
-
202
- if destination_dir is None :
203
- destination_dir = os .path .join (sources_dir , "gyb_generated" )
204
201
make_dir_if_needed (destination_dir )
205
202
206
203
# Clear any *.swift files that are relics from the previous run.
@@ -288,23 +285,26 @@ def generate_syntax_node_template_gyb_files(
288
285
# Maps directories containing .gyb files to the directories the generated files should
289
286
# live in.
290
287
def gyb_dir_mapping (
291
- swiftsyntax_destination : Optional [str ] = None ,
292
- swiftsyntax_raw_destination : Optional [str ] = None ,
293
- swiftsyntaxbuilder_destination : Optional [str ] = None ,
294
- swiftsyntaxparser_destination : Optional [str ] = None ,
295
- generateswiftsyntaxbuilder_destination : Optional [str ] = None ,
296
- ) -> Dict [str , Optional [str ]]:
297
- return {
298
- SWIFTSYNTAX_DIR : swiftsyntax_destination ,
299
- os .path .join (SWIFTSYNTAX_DIR , "Raw" ): swiftsyntax_raw_destination ,
300
- SWIFTSYNTAXBUILDER_DIR : swiftsyntaxbuilder_destination ,
301
- SWIFTSYNTAXPARSER_DIR : swiftsyntaxparser_destination ,
302
- GENERATESWIFTSYNTAXBUILDER_DIR : generateswiftsyntaxbuilder_destination ,
303
- }
288
+ write_to_temp_directories : bool
289
+ ) -> Dict [str , str ]:
290
+ source_dirs = [
291
+ SWIFTSYNTAX_DIR ,
292
+ os .path .join (SWIFTSYNTAX_DIR , "Raw" ),
293
+ SWIFTSYNTAXBUILDER_DIR ,
294
+ SWIFTSYNTAXPARSER_DIR ,
295
+ GENERATESWIFTSYNTAXBUILDER_DIR ,
296
+ ]
297
+ mapping = {}
298
+ for source_dir in source_dirs :
299
+ if write_to_temp_directories :
300
+ mapping [source_dir ] = tempfile .mkdtemp ()
301
+ else :
302
+ mapping [source_dir ] = os .path .join (source_dir , "gyb_generated" )
303
+ return mapping
304
304
305
305
306
306
def generate_gyb_files (
307
- gyb_exec : str , gyb_dir_mapping : Dict [str , Optional [ str ] ],
307
+ gyb_exec : str , gyb_dir_mapping : Dict [str , str ],
308
308
add_source_locations : bool , verbose : bool ,
309
309
) -> None :
310
310
print ("** Generating gyb Files **" )
@@ -455,11 +455,7 @@ def build(self, product_name: str) -> None:
455
455
456
456
def verify_generated_files (gyb_exec : str , verbose : bool ) -> None :
457
457
gyb_dirs = gyb_dir_mapping (
458
- swiftsyntax_destination = tempfile .mkdtemp (),
459
- swiftsyntax_raw_destination = tempfile .mkdtemp (),
460
- swiftsyntaxbuilder_destination = tempfile .mkdtemp (),
461
- swiftsyntaxparser_destination = tempfile .mkdtemp (),
462
- generateswiftsyntaxbuilder_destination = tempfile .mkdtemp (),
458
+ write_to_temp_directories = True ,
463
459
)
464
460
465
461
generate_gyb_files (
@@ -685,7 +681,7 @@ def generate_source_code_command(args: argparse.Namespace) -> None:
685
681
try :
686
682
generate_gyb_files (
687
683
args .gyb_exec ,
688
- gyb_dir_mapping = gyb_dir_mapping (),
684
+ gyb_dir_mapping = gyb_dir_mapping (write_to_temp_directories = False ),
689
685
add_source_locations = args .add_source_locations ,
690
686
verbose = args .verbose ,
691
687
)
0 commit comments