Skip to content

Commit 3dfd080

Browse files
authored
Merge pull request #205 from artemcm/BuildScriptTools
[Build Script Helper] Improvements to build with a specified toolchain
2 parents 70864a4 + 0f55d19 commit 3dfd080

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

Utilities/build-script-helper.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,19 @@
99
import subprocess
1010
import sys
1111

12-
driver_tools = ['swift', 'swift-frontend', 'ld', 'libtool', 'clang',
13-
'swift-autolink-extract', 'lldb', 'dwarfdump', 'swift-help']
12+
# Tools constructed as a part of the a development build toolchain
13+
driver_toolchain_tools = ['swift', 'swift-frontend', 'clang', 'swift-help']
14+
15+
def call_output(cmd, cwd=None, stderr=False, verbose=False):
16+
"""Calls a subprocess for its return data."""
17+
if verbose:
18+
print(' '.join(cmd))
19+
try:
20+
return subprocess.check_output(cmd, cwd=cwd, stderr=stderr, universal_newlines=True).strip()
21+
except Exception as e:
22+
if not verbose:
23+
print(' '.join(cmd))
24+
error(str(e))
1425

1526
def swiftpm(action, swift_exec, swiftpm_args, env=None):
1627
cmd = [swift_exec, action] + swiftpm_args
@@ -107,13 +118,16 @@ def handle_invocation(toolchain_bin, args):
107118
if args.ninja_bin:
108119
env['NINJA_BIN'] = args.ninja_bin
109120

121+
if args.sysroot:
122+
env['SDKROOT'] = args.sysroot
123+
110124
print('Cleaning ' + args.build_path)
111125
shutil.rmtree(args.build_path, ignore_errors=True)
112126

113127
if args.action == 'build':
114128
swiftpm('build', swift_exec, swiftpm_args, env)
115129
elif args.action == 'test':
116-
for tool in driver_tools:
130+
for tool in driver_toolchain_tools:
117131
env['SWIFT_DRIVER_' + tool.upper().replace('-','_') + '_EXEC'] = '%s' % (os.path.join(toolchain_bin, tool))
118132
env['SWIFT_EXEC'] = '%sc' % (swift_exec)
119133
test_args = swiftpm_args
@@ -156,6 +170,11 @@ def add_common_args(parser):
156170
args.build_path = os.path.abspath(args.build_path)
157171
args.toolchain = os.path.abspath(args.toolchain)
158172

173+
if platform.system() == 'Darwin':
174+
args.sysroot = call_output(["xcrun", "--sdk", "macosx", "--show-sdk-path"], verbose=args.verbose)
175+
else:
176+
args.sysroot = None
177+
159178
if args.toolchain:
160179
toolchain_bin = os.path.join(args.toolchain, 'bin')
161180
else:

0 commit comments

Comments
 (0)