Skip to content

Commit 14fbbbb

Browse files
authored
Merge pull request swiftlang#107 from nkcsgexi/module-grou-swift-syntax
build-script: ensure module group is used only when building SwiftSyntax library.
2 parents 4e09ab4 + fba6e14 commit 14fbbbb

File tree

1 file changed

+35
-34
lines changed

1 file changed

+35
-34
lines changed

build-script.py

+35-34
Original file line numberDiff line numberDiff line change
@@ -190,43 +190,40 @@ def get_swiftpm_invocation(spm_exec, build_dir, parser_header_dir,
190190

191191
# To speed up compilation.
192192
swiftpm_call.extend(['-Xswiftc', '-enforce-exclusivity=unchecked'])
193-
194-
# To build the group information into the module documentation file
195-
# swiftpm_call.extend(['-Xswiftc', '-Xfrontend', '-Xswiftc', '-group-info-path'])
196-
# swiftpm_call.extend(['-Xswiftc', '-Xfrontend', '-Xswiftc', GROUP_INFO_PATH])
197-
198193
return swiftpm_call
199194

200-
def build_swiftsyntax(swift_build_exec, swiftc_exec, build_dir,
201-
parser_header_dir, parser_lib_dir,
202-
build_test_util, release,
203-
verbose, disable_sandbox=False):
204-
print('** Building SwiftSyntax **')
205-
206-
swiftpm_call = get_swiftpm_invocation(spm_exec=swift_build_exec,
207-
build_dir=build_dir,
208-
parser_header_dir=parser_header_dir,
209-
parser_lib_dir=parser_lib_dir,
210-
release=release)
211-
swiftpm_call.extend(['--product', 'SwiftSyntax'])
212-
213-
if disable_sandbox:
214-
swiftpm_call.append('--disable-sandbox')
215-
216-
# Only build lit-test-helper if we are planning to run tests
217-
if build_test_util:
218-
swiftpm_call.extend(['--product', 'lit-test-helper'])
219-
220-
if verbose:
221-
swiftpm_call.extend(['--verbose'])
222-
_environ = dict(os.environ)
223-
_environ['SWIFT_EXEC'] = swiftc_exec
224-
_environ['SWIFT_SYNTAX_BUILD_SCRIPT'] = ''
225-
check_call(swiftpm_call, env=_environ, verbose=verbose)
195+
class Builder(object):
196+
def __init__(self, swift_build_exec, swiftc_exec, build_dir,
197+
parser_header_dir, parser_lib_dir,
198+
release, verbose, disable_sandbox=False):
199+
self.swiftpm_call = get_swiftpm_invocation(spm_exec=swift_build_exec,
200+
build_dir=build_dir,
201+
parser_header_dir=parser_header_dir,
202+
parser_lib_dir=parser_lib_dir,
203+
release=release)
204+
if disable_sandbox:
205+
self.swiftpm_call.append('--disable-sandbox')
206+
if verbose:
207+
self.swiftpm_call.extend(['--verbose'])
208+
self.verbose = verbose
209+
self._environ = dict(os.environ)
210+
self._environ['SWIFT_EXEC'] = swiftc_exec
211+
self._environ['SWIFT_SYNTAX_BUILD_SCRIPT'] = ''
212+
213+
def build(self, product_name, module_group_path=''):
214+
print('** Building ' + product_name + ' **')
215+
command = list(self.swiftpm_call)
216+
command.extend(['--product', product_name])
217+
218+
# To build the group information into the module documentation file
219+
if module_group_path:
220+
command.extend(['-Xswiftc', '-Xfrontend', '-Xswiftc', '-group-info-path'])
221+
command.extend(['-Xswiftc', '-Xfrontend', '-Xswiftc', module_group_path])
222+
223+
check_call(command, env=self._environ, verbose=self.verbose)
226224

227225

228226
## Testing
229-
230227
def run_tests(swift_test_exec, build_dir, parser_header_dir, parser_lib_dir,
231228
release, swift_build_exec, filecheck_exec, swiftc_exec, verbose):
232229
print('** Running SwiftSyntax Tests **')
@@ -541,15 +538,19 @@ def main():
541538
sys.exit(0)
542539

543540
try:
544-
build_swiftsyntax(swift_build_exec=args.swift_build_exec,
541+
builder = Builder(swift_build_exec=args.swift_build_exec,
545542
swiftc_exec=args.swiftc_exec,
546543
build_dir=args.build_dir,
547544
parser_header_dir=args.syntax_parser_header_dir,
548545
parser_lib_dir=args.syntax_parser_lib_dir,
549-
build_test_util=args.test,
550546
release=args.release,
551547
verbose=args.verbose,
552548
disable_sandbox=args.disable_sandbox)
549+
builder.build('SwiftSyntax', module_group_path=GROUP_INFO_PATH)
550+
551+
# Only build lit-test-helper if we are planning to run tests
552+
if args.test:
553+
builder.build('lit-test-helper')
553554
except subprocess.CalledProcessError as e:
554555
printerr('Error: Building SwiftSyntax failed')
555556
printerr('Executing: %s' % ' '.join(e.cmd))

0 commit comments

Comments
 (0)