Skip to content

Commit 7174b3e

Browse files
committed
Simplify a few parameters in gyb-generation of build-script.py
1 parent 68cd96e commit 7174b3e

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

build-script.py

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -191,16 +191,13 @@ def generate_single_gyb_file(
191191
# `sources_dir/gyb_generated`.
192192
def generate_gyb_files_helper(
193193
sources_dir: str,
194-
destination_dir: Optional[str],
194+
destination_dir: str,
195195
gyb_exec: str,
196196
add_source_locations: bool,
197197
verbose: bool,
198198
) -> None:
199199
temp_files_dir = tempfile.gettempdir()
200200
make_dir_if_needed(temp_files_dir)
201-
202-
if destination_dir is None:
203-
destination_dir = os.path.join(sources_dir, "gyb_generated")
204201
make_dir_if_needed(destination_dir)
205202

206203
# Clear any *.swift files that are relics from the previous run.
@@ -288,23 +285,26 @@ def generate_syntax_node_template_gyb_files(
288285
# Maps directories containing .gyb files to the directories the generated files should
289286
# live in.
290287
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
304304

305305

306306
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],
308308
add_source_locations: bool, verbose: bool,
309309
) -> None:
310310
print("** Generating gyb Files **")
@@ -455,11 +455,7 @@ def build(self, product_name: str) -> None:
455455

456456
def verify_generated_files(gyb_exec: str, verbose: bool) -> None:
457457
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,
463459
)
464460

465461
generate_gyb_files(
@@ -685,7 +681,7 @@ def generate_source_code_command(args: argparse.Namespace) -> None:
685681
try:
686682
generate_gyb_files(
687683
args.gyb_exec,
688-
gyb_dir_mapping=gyb_dir_mapping(),
684+
gyb_dir_mapping=gyb_dir_mapping(write_to_temp_directories=False),
689685
add_source_locations=args.add_source_locations,
690686
verbose=args.verbose,
691687
)

0 commit comments

Comments
 (0)