Skip to content

Commit 7ad8cf7

Browse files
committed
[build-script.py] Provide an option to pass a custom path to the gyb tool
1 parent 946caf4 commit 7ad8cf7

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

build-script.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
INCR_TRANSFER_ROUNDTRIP_EXEC = \
1717
WORKSPACE_DIR + '/swift/utils/incrparse/incr_transfer_round_trip.py'
18-
GYB_EXEC = WORKSPACE_DIR + '/swift/utils/gyb'
1918
LIT_EXEC = WORKSPACE_DIR + '/llvm-project/llvm/utils/lit/lit.py'
2019
GROUP_INFO_PATH = PACKAGE_DIR + '/utils/group.json'
2120

@@ -84,16 +83,16 @@ def realpath(path):
8483

8584
## Generating gyb files
8685

87-
def check_gyb_exec():
88-
if not os.path.exists(GYB_EXEC):
86+
def check_gyb_exec(gyb_exec):
87+
if not os.path.exists(gyb_exec):
8988
fatal_error('''
9089
Error: Could not find gyb.
9190
Looking at '%s'.
9291
9392
Make sure you have the main swift repo checked out next to the swift-syntax
9493
repository.
9594
Refer to README.md for more information.
96-
''' % GYB_EXEC)
95+
''' % gyb_exec)
9796

9897

9998
def check_rsync():
@@ -102,7 +101,7 @@ def check_rsync():
102101
fatal_error('Error: Could not find rsync.')
103102

104103

105-
def generate_single_gyb_file(gyb_file, output_file_name, destination,
104+
def generate_single_gyb_file(gyb_exec, gyb_file, output_file_name, destination,
106105
temp_files_dir, add_source_locations,
107106
additional_gyb_flags, verbose):
108107
# Source locations are added by default by gyb, and cleared by passing
@@ -112,7 +111,7 @@ def generate_single_gyb_file(gyb_file, output_file_name, destination,
112111
else ['--line-directive=']
113112

114113
# Generate the new file
115-
check_call([GYB_EXEC] +
114+
check_call([gyb_exec] +
116115
[gyb_file] +
117116
['-o', temp_files_dir + '/' + output_file_name] +
118117
line_directive_flags +
@@ -127,10 +126,10 @@ def generate_single_gyb_file(gyb_file, output_file_name, destination,
127126
[destination + '/' + output_file_name],
128127
verbose=verbose)
129128

130-
def generate_gyb_files(verbose, add_source_locations, destination=None):
129+
def generate_gyb_files(gyb_exec, verbose, add_source_locations, destination=None):
131130
print('** Generating gyb Files **')
132131

133-
check_gyb_exec()
132+
check_gyb_exec(gyb_exec)
134133
check_rsync()
135134

136135
swiftsyntax_sources_dir = os.path.join(PACKAGE_DIR, 'Sources',
@@ -175,7 +174,8 @@ def generate_gyb_files(verbose, add_source_locations, destination=None):
175174
# Slice off the '.gyb' to get the name for the output file
176175
output_file_name = gyb_file[:-4]
177176

178-
generate_single_gyb_file(swiftsyntax_sources_dir + '/' + gyb_file,
177+
generate_single_gyb_file(gyb_exec,
178+
swiftsyntax_sources_dir + '/' + gyb_file,
179179
output_file_name, destination,
180180
temp_files_dir, add_source_locations,
181181
additional_gyb_flags=[],
@@ -186,7 +186,7 @@ def generate_gyb_files(verbose, add_source_locations, destination=None):
186186

187187
gyb_file = swiftsyntax_sources_dir + '/SyntaxNodes.swift.gyb.template'
188188

189-
generate_single_gyb_file(gyb_file, output_file_name,
189+
generate_single_gyb_file(gyb_exec, gyb_file, output_file_name,
190190
template_destination, temp_files_dir,
191191
add_source_locations,
192192
additional_gyb_flags=[
@@ -246,11 +246,11 @@ def build(self, product_name, module_group_path=''):
246246

247247

248248
## Testing
249-
def verify_generated_files(verbose):
249+
def verify_generated_files(gyb_exec, verbose):
250250
user_generated_dir = os.path.join(PACKAGE_DIR, 'Sources', 'SwiftSyntax',
251251
'gyb_generated')
252252
self_generated_dir = tempfile.mkdtemp()
253-
generate_gyb_files(verbose=verbose,
253+
generate_gyb_files(gyb_exec, verbose=verbose,
254254
add_source_locations=False,
255255
destination=self_generated_dir)
256256

@@ -438,6 +438,8 @@ def main():
438438
section for arguments that need to be specified for this.
439439
''')
440440

441+
default_gyb_exec = WORKSPACE_DIR + '/swift/utils/gyb'
442+
441443
basic_group = parser.add_argument_group('Basic')
442444

443445
basic_group.add_argument('--build-dir', default=None, help='''
@@ -507,6 +509,9 @@ def main():
507509
Path to the FileCheck executable that was built as part of the LLVM
508510
repository. If not specified, it will be looked up from PATH.
509511
''')
512+
testing_group.add_argument('--gyb-exec', default=default_gyb_exec, help='''
513+
Path to the gyb tool. (default: '%s').
514+
''' % (default_gyb_exec) )
510515
testing_group.add_argument('--verify-generated-files', action='store_true',
511516
help='''
512517
Instead of generating files using gyb, verify that the files which
@@ -533,7 +538,7 @@ def main():
533538

534539
try:
535540
if not args.verify_generated_files:
536-
generate_gyb_files(verbose=args.verbose,
541+
generate_gyb_files(args.gyb_exec, verbose=args.verbose,
537542
add_source_locations=args.add_source_locations)
538543
# Skip the rest of the build if we should perform degyb only
539544
if args.degyb_only:
@@ -546,7 +551,7 @@ def main():
546551

547552
if args.verify_generated_files:
548553
try:
549-
success = verify_generated_files(verbose=args.verbose)
554+
success = verify_generated_files(args.gyb_exec, verbose=args.verbose)
550555
except subprocess.CalledProcessError as e:
551556
printerr('FAIL: Gyb-generated files committed to repository do '
552557
'not match generated ones. Please re-generate the '

0 commit comments

Comments
 (0)