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