Skip to content

[build-script.py] Provide an option to pass a custom path to the gyb tool #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions build-script.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

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

Expand Down Expand Up @@ -84,16 +83,16 @@ def realpath(path):

## Generating gyb files

def check_gyb_exec():
if not os.path.exists(GYB_EXEC):
def check_gyb_exec(gyb_exec):
if not os.path.exists(gyb_exec):
fatal_error('''
Error: Could not find gyb.
Looking at '%s'.

Make sure you have the main swift repo checked out next to the swift-syntax
repository.
Refer to README.md for more information.
''' % GYB_EXEC)
''' % gyb_exec)


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


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

# Generate the new file
check_call([GYB_EXEC] +
check_call([gyb_exec] +
[gyb_file] +
['-o', temp_files_dir + '/' + output_file_name] +
line_directive_flags +
Expand All @@ -127,10 +126,10 @@ def generate_single_gyb_file(gyb_file, output_file_name, destination,
[destination + '/' + output_file_name],
verbose=verbose)

def generate_gyb_files(verbose, add_source_locations, destination=None):
def generate_gyb_files(gyb_exec, verbose, add_source_locations, destination=None):
print('** Generating gyb Files **')

check_gyb_exec()
check_gyb_exec(gyb_exec)
check_rsync()

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

generate_single_gyb_file(swiftsyntax_sources_dir + '/' + gyb_file,
generate_single_gyb_file(gyb_exec,
swiftsyntax_sources_dir + '/' + gyb_file,
output_file_name, destination,
temp_files_dir, add_source_locations,
additional_gyb_flags=[],
Expand All @@ -186,7 +186,7 @@ def generate_gyb_files(verbose, add_source_locations, destination=None):

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

generate_single_gyb_file(gyb_file, output_file_name,
generate_single_gyb_file(gyb_exec, gyb_file, output_file_name,
template_destination, temp_files_dir,
add_source_locations,
additional_gyb_flags=[
Expand Down Expand Up @@ -246,11 +246,11 @@ def build(self, product_name, module_group_path=''):


## Testing
def verify_generated_files(verbose):
def verify_generated_files(gyb_exec, verbose):
user_generated_dir = os.path.join(PACKAGE_DIR, 'Sources', 'SwiftSyntax',
'gyb_generated')
self_generated_dir = tempfile.mkdtemp()
generate_gyb_files(verbose=verbose,
generate_gyb_files(gyb_exec, verbose=verbose,
add_source_locations=False,
destination=self_generated_dir)

Expand Down Expand Up @@ -438,6 +438,8 @@ def main():
section for arguments that need to be specified for this.
''')

default_gyb_exec = WORKSPACE_DIR + '/swift/utils/gyb'

basic_group = parser.add_argument_group('Basic')

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

try:
if not args.verify_generated_files:
generate_gyb_files(verbose=args.verbose,
generate_gyb_files(args.gyb_exec, verbose=args.verbose,
add_source_locations=args.add_source_locations)
# Skip the rest of the build if we should perform degyb only
if args.degyb_only:
Expand All @@ -546,7 +551,7 @@ def main():

if args.verify_generated_files:
try:
success = verify_generated_files(verbose=args.verbose)
success = verify_generated_files(args.gyb_exec, verbose=args.verbose)
except subprocess.CalledProcessError as e:
printerr('FAIL: Gyb-generated files committed to repository do '
'not match generated ones. Please re-generate the '
Expand Down