@@ -42,17 +42,18 @@ import subprocess
42
42
import sys
43
43
import tempfile
44
44
45
- ###
46
45
47
46
def note (message ):
48
47
print ("%s: note: %s" % (os .path .basename (sys .argv [0 ]), message ))
49
48
sys .stdout .flush ()
50
49
50
+
51
51
def error (message ):
52
52
print ("%s: error: %s" % (os .path .basename (sys .argv [0 ]), message ))
53
53
sys .stdout .flush ()
54
54
raise SystemExit (1 )
55
55
56
+
56
57
def mkdir_p (path ):
57
58
"""
58
59
mkdir_p(path)
@@ -67,6 +68,7 @@ def mkdir_p(path):
67
68
if e .errno != errno .EEXIST :
68
69
raise
69
70
71
+
70
72
# FIXME: Consider eliminating this once the build task format supports node
71
73
# hashing.
72
74
def write_file_if_changed (path , data ):
@@ -94,9 +96,12 @@ g_num_cpus = os.sysconf("SC_NPROCESSORS_ONLN")
94
96
g_default_sysroot = None
95
97
if platform .system () == 'Darwin' :
96
98
g_platform_path = subprocess .check_output (
97
- ["xcrun" , "--sdk" , "macosx" , "--show-sdk-platform-path" ], universal_newlines = True ).strip ()
99
+ ["xcrun" , "--sdk" , "macosx" , "--show-sdk-platform-path" ],
100
+ universal_newlines = True ).strip ()
98
101
g_default_sysroot = subprocess .check_output (
99
- ["xcrun" , "--sdk" , "macosx" , "--show-sdk-path" ], universal_newlines = True ).strip ()
102
+ ["xcrun" , "--sdk" , "macosx" , "--show-sdk-path" ],
103
+ universal_newlines = True ).strip ()
104
+
100
105
101
106
class Target (object ):
102
107
@property
@@ -168,22 +173,27 @@ class Target(object):
168
173
print (" outputs: %s" % json .dumps (
169
174
[compile_swift_node , module_path ] + swift_objects ), file = output )
170
175
print (" module-name: %s" % json .dumps (module_name ), file = output )
171
- print (" module-output-path: %s" % json .dumps (module_path ), file = output )
172
- print ( " sources: %s" % json . dumps (
173
- self .swift_sources ), file = output )
176
+ print (" module-output-path: %s" % json .dumps (module_path ),
177
+ file = output )
178
+ print ( " sources: %s" % json . dumps ( self .swift_sources ), file = output )
174
179
print (" objects: %s" % json .dumps (swift_objects ), file = output )
175
180
print (" import-paths: %s" % json .dumps (
176
181
[module_dir ]), file = output )
177
- print (" other-args: %s" % json .dumps (' ' .join (other_args )), file = output )
182
+ print (" other-args: %s" % json .dumps (' ' .join (other_args )),
183
+ file = output )
178
184
print (" temps-path: %s" % json .dumps (target_build_dir ), file = output )
179
185
print (" is-library: %s" % json .dumps (
180
186
str (bool (self .is_library )).lower ()), file = output )
181
187
print (file = output )
182
188
189
+
183
190
# currently only returns the targets parsed from the manifest
184
191
def parse_manifest ():
185
- # we have a *very* strict format for our manifest to make parsing more robust
186
- pattern = re .compile (r'Target\(.*?name: "(.*?)",\n *dependencies: (\[.*?\])\)' , re .DOTALL | re .MULTILINE )
192
+ # we have a *very* strict format for our manifest to make parsing more
193
+ # robust
194
+ pattern = re .compile (
195
+ r'Target\(.*?name: "(.*?)",\n *dependencies: (\[.*?\])\)' ,
196
+ re .DOTALL | re .MULTILINE )
187
197
manifest_data = open (os .path .join (g_project_root , "Package.swift" )).read ()
188
198
189
199
def convert (match ):
@@ -198,7 +208,8 @@ def parse_manifest():
198
208
try :
199
209
return next (a for a in targets if a .name == targetName )
200
210
except StopIteration :
201
- # this target is not explicit in the manifest: it is an implicit target
211
+ # this target is not explicit in the manifest: it is an
212
+ # implicit target
202
213
b = Target (targetName )
203
214
targets .append (b )
204
215
return b
@@ -207,6 +218,7 @@ def parse_manifest():
207
218
# fill dependency graph and set dependencies back to strings
208
219
def convert (target ):
209
220
myset = set ()
221
+
210
222
def recurse (root ):
211
223
deps = []
212
224
for dep in root .dependencies :
@@ -224,6 +236,7 @@ g_source_root = os.path.join(g_project_root, "Sources")
224
236
targets = parse_manifest ()
225
237
target_map = dict ((t .name , t ) for t in targets )
226
238
239
+
227
240
def create_bootstrap_files (sandbox_path , args ):
228
241
# Write out the build file.
229
242
output = StringIO ()
@@ -284,7 +297,8 @@ def create_bootstrap_files(sandbox_path, args):
284
297
print (" %s:" % json .dumps (predecessor_node ), file = output )
285
298
print (" tool: phony" , file = output )
286
299
print (" inputs: %s" % json .dumps (
287
- [target_map [name ].virtual_node for name in target .dependencies ]), file = output )
300
+ [target_map [name ].virtual_node for name in target .dependencies ]),
301
+ file = output )
288
302
print (" outputs: %s" % json .dumps ([predecessor_node ]), file = output )
289
303
print (file = output )
290
304
@@ -307,7 +321,8 @@ def create_bootstrap_files(sandbox_path, args):
307
321
else :
308
322
link_output_path = os .path .join (bin_dir , target .name )
309
323
310
- link_command = [args .swiftc_path , '-o' , pipes .quote (link_output_path )]
324
+ link_command = [args .swiftc_path ,
325
+ '-o' , pipes .quote (link_output_path )]
311
326
if args .sysroot :
312
327
link_command .extend (["-sdk" , args .sysroot ])
313
328
if platform .system () == 'Darwin' :
@@ -325,7 +340,10 @@ def create_bootstrap_files(sandbox_path, args):
325
340
# Write out the link command.
326
341
print (" %s:" % json .dumps (target .linked_virtual_node ), file = output )
327
342
print (" tool: shell" , file = output )
328
- print (" description: Link %s" % (target .name if target .is_library else link_output_path ,), file = output )
343
+ if target .is_library :
344
+ print (" description: Link %s" % target .name , file = output )
345
+ else :
346
+ print (" description: Link %s" % link_output_path , file = output )
329
347
print (" inputs: %s" % json .dumps (
330
348
link_input_nodes + objects + linked_libraries ), file = output )
331
349
print (" outputs: %s" % json .dumps (
@@ -338,13 +356,15 @@ def create_bootstrap_files(sandbox_path, args):
338
356
print (" tool: phony" , file = output )
339
357
print (" inputs: %s" % json .dumps (
340
358
[target .linked_virtual_node ]), file = output )
341
- print (" outputs: %s" % json .dumps ([target .virtual_node ]), file = output )
359
+ print (" outputs: %s" % json .dumps ([target .virtual_node ]),
360
+ file = output )
342
361
print (file = output )
343
362
344
363
# Write the output file.
345
364
write_file_if_changed (os .path .join (sandbox_path , "build.swift-build" ),
346
365
output .getvalue ())
347
366
367
+
348
368
def process_runtime_libraries (build_path , args , bootstrap = False ):
349
369
if bootstrap :
350
370
module_input_path = os .path .join (
@@ -391,7 +411,8 @@ def process_runtime_libraries(build_path, args, bootstrap=False):
391
411
# error.
392
412
tf = tempfile .NamedTemporaryFile (suffix = ".swift" )
393
413
cmds = subprocess .check_output (
394
- cmd + [tf .name , "-###" ], universal_newlines = True ).strip ().split ("\n " )
414
+ cmd + [tf .name , "-###" ],
415
+ universal_newlines = True ).strip ().split ("\n " )
395
416
396
417
# Get the link command 'swiftc' used.
397
418
link_cmd = shlex .split (cmds [- 1 ])
@@ -408,10 +429,12 @@ def process_runtime_libraries(build_path, args, bootstrap=False):
408
429
raise SystemExit ("unable to understand 'swiftc' driver commands" )
409
430
del link_cmd [idx - 1 ]
410
431
cmd = [arg for arg in link_cmd
411
- if arg .endswith ("swift_begin.o" ) or arg .endswith ("swift_end.o" ) or (not arg .endswith (".o" ) and not arg .endswith (".autolink" ))]
432
+ if arg .endswith (("swift_begin.o" , "swift_end.o" )) or
433
+ (not arg .endswith ((".o" , ".autolink" )))]
412
434
subprocess .check_call (cmd )
413
435
return (runtime_module_path , runtime_lib_path )
414
436
437
+
415
438
def get_swift_build_tool_path ():
416
439
# Search for a 'swift-build-tool' to use.
417
440
@@ -428,7 +451,8 @@ def get_swift_build_tool_path():
428
451
429
452
# Next, search for it in PATH.
430
453
try :
431
- return subprocess .check_output (["which" , "swift-build-tool" ], universal_newlines = True ).strip ()
454
+ return subprocess .check_output (["which" , "swift-build-tool" ],
455
+ universal_newlines = True ).strip ()
432
456
except :
433
457
pass
434
458
@@ -446,6 +470,7 @@ def get_swift_build_tool_path():
446
470
# If all else failed, report an error.
447
471
error ("unable to find 'swift-build-tool' tool for bootstrap build" )
448
472
473
+
449
474
def main ():
450
475
parser = argparse .ArgumentParser (
451
476
usage = "%(prog)s [options] [clean|all|test|install]" ,
@@ -517,9 +542,11 @@ def main():
517
542
args .sbt_path = os .path .abspath (
518
543
args .sbt_path or get_swift_build_tool_path ())
519
544
520
- # Due to bug in Xcode where SWIFT_EXEC is not set correctly by downloadable toolchain
545
+ # Due to bug in Xcode where SWIFT_EXEC is not set correctly by downloadable
546
+ # toolchain
521
547
if os .getenv ("XCODE_DEFAULT_TOOLCHAIN_OVERRIDE" ):
522
- args .swiftc = os .path .join (os .getenv ("XCODE_DEFAULT_TOOLCHAIN_OVERRIDE" ), "usr/bin/swiftc" )
548
+ args .swiftc = os .path .join (
549
+ os .getenv ("XCODE_DEFAULT_TOOLCHAIN_OVERRIDE" ), "usr/bin/swiftc" )
523
550
524
551
# Create or update the bootstrap files.
525
552
create_bootstrap_files (sandbox_path , args )
@@ -561,7 +588,7 @@ def main():
561
588
if args .sysroot :
562
589
env_cmd .append ("SYSROOT=" + args .sysroot )
563
590
564
- # We need to embed an RPATH so swift-{build,test} can find the core
591
+ # We need to embed an RPATH so swift-{build,test} can find the core
565
592
# libraries.
566
593
if platform .system () == 'Linux' :
567
594
embed_rpath = "$ORIGIN/../lib/swift/linux"
0 commit comments