Skip to content

Commit 920af41

Browse files
committed
[Build Script Helper] Explicitly setup environment variables for toolchain executables
If a toolchain is specified, set the search environment variable for each tool executable the driver cares about. The driver will then use this environment variable use to find the tool.
1 parent 6b84f8b commit 920af41

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

Utilities/build-script-helper.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
import subprocess
1010
import sys
1111

12+
driver_tools = ['swift', 'swift-frontend', 'ld', 'libtool', 'clang',
13+
'swift-autolink-extract', 'lldb', 'dwarfdump', 'swift-help']
14+
1215
def swiftpm(action, swift_exec, swiftpm_args, env=None):
1316
cmd = [swift_exec, action] + swiftpm_args
1417
print(' '.join(cmd))
@@ -91,9 +94,11 @@ def should_test_parallel():
9194
return True
9295

9396

94-
def handle_invocation(swift_exec, swift_frontend_exec, args):
97+
def handle_invocation(toolchain_bin, args):
9598
swiftpm_args = get_swiftpm_options(args)
9699

100+
swift_exec = os.path.join(toolchain_bin, 'swift')
101+
97102
env = os.environ
98103
# Use local dependencies (i.e. checked out next to swift-driver).
99104
if not args.no_local_deps:
@@ -108,7 +113,8 @@ def handle_invocation(swift_exec, swift_frontend_exec, args):
108113
if args.action == 'build':
109114
swiftpm('build', swift_exec, swiftpm_args, env)
110115
elif args.action == 'test':
111-
env['SWIFT_DRIVER_SWIFT_FRONTEND_EXEC'] = '%s' % (swift_frontend_exec)
116+
for tool in driver_tools:
117+
env['SWIFT_DRIVER_' + tool.upper().replace('-','_') + '_EXEC'] = '%s' % (os.path.join(toolchain_bin, tool))
112118
env['SWIFT_EXEC'] = '%sc' % (swift_exec)
113119
test_args = swiftpm_args
114120
if should_test_parallel():
@@ -151,13 +157,11 @@ def add_common_args(parser):
151157
args.toolchain = os.path.abspath(args.toolchain)
152158

153159
if args.toolchain:
154-
swift_exec = os.path.join(args.toolchain, 'bin', 'swift')
155-
swift_frontend_exec = os.path.join(args.toolchain, 'bin', 'swift-frontend')
160+
toolchain_bin = os.path.join(args.toolchain, 'bin')
156161
else:
157-
swift_exec = 'swift'
158-
swift_frontend_exec = 'swift-frontend'
162+
toolchain_bin = ''
159163

160-
handle_invocation(swift_exec, swift_frontend_exec, args)
164+
handle_invocation(toolchain_bin, args)
161165

162166
if __name__ == '__main__':
163167
main()

0 commit comments

Comments
 (0)