@@ -33,13 +33,14 @@ import argparse
33
33
import errno
34
34
import json
35
35
import os
36
+ import pipes
36
37
import platform
38
+ import re
37
39
import shlex
40
+ import shutil
38
41
import subprocess
39
42
import sys
40
43
import tempfile
41
- import pipes
42
- import shutil
43
44
44
45
###
45
46
@@ -179,24 +180,48 @@ class Target(object):
179
180
str (bool (self .is_library )).lower ()), file = output )
180
181
print (file = output )
181
182
183
+ # currently only returns the targets parsed from the manifest
184
+ 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 )
187
+ manifest_data = open (os .path .join (g_project_root , "Package.swift" )).read ()
188
+
189
+ def convert (match ):
190
+ name = match .group (1 )
191
+ deps = eval (match .group (2 ))
192
+ return Target (name , deps )
193
+ targets = map (convert , pattern .finditer (manifest_data ))
194
+
195
+ # substitute strings for Target objects
196
+ for target in targets :
197
+ def convert (targetName ):
198
+ try :
199
+ return next (a for a in targets if a .name == targetName )
200
+ except StopIteration :
201
+ # this target is not explicit in the manifest: it is an implicit target
202
+ b = Target (targetName )
203
+ targets .append (b )
204
+ return b
205
+ target .dependencies = map (convert , target .dependencies )
206
+
207
+ # fill dependency graph and set dependencies back to strings
208
+ def convert (target ):
209
+ myset = set ()
210
+ def recurse (root ):
211
+ deps = []
212
+ for dep in root .dependencies :
213
+ if dep .name not in myset :
214
+ myset .add (dep .name )
215
+ deps += recurse (dep ) + [dep .name ]
216
+ return deps
217
+ # `reversed` because Linux link order must be reverse-topological
218
+ return Target (target .name , reversed (recurse (target )))
219
+ return map (convert , targets )
220
+
182
221
# Hard-coded target definition.
183
222
g_project_root = os .path .dirname (os .path .dirname (os .path .abspath (__file__ )))
184
223
g_source_root = os .path .join (g_project_root , "Sources" )
185
- targets = [
186
- Target ('libc' ),
187
- Target ('POSIX' , dependencies = ["libc" ]),
188
- Target ('Utility' , dependencies = ["POSIX" , "libc" ]),
189
- Target ('PackageDescription' ),
190
- Target ('Xcodeproj' , dependencies = ["PackageType" , "Utility" , "POSIX" , "libc" ]),
191
- Target ('Multitool' , dependencies = ["PackageType" , "Utility" , "POSIX" , "libc" ]),
192
- Target ('PackageType' , dependencies = ["PackageDescription" , "Utility" , "POSIX" , "libc" ]),
193
- Target ('Transmute' , dependencies = ["PackageType" , "PackageDescription" , "Utility" , "POSIX" , "libc" ]),
194
- Target ('ManifestParser' , dependencies = ["PackageType" , "Utility" , "PackageDescription" , "POSIX" , "libc" ]),
195
- Target ('Get' , dependencies = ["ManifestParser" , "PackageDescription" , "PackageType" , "Utility" , "POSIX" , "libc" ]),
196
- Target ('Build' , dependencies = ["PackageType" , "Utility" , "PackageDescription" , "POSIX" , "libc" ]),
197
- Target ('swift-build' , dependencies = ["Xcodeproj" , "Transmute" , "Multitool" , "Build" , "Get" , "ManifestParser" , "PackageDescription" , "PackageType" , "Utility" , "POSIX" , "libc" ]),
198
- Target ('swift-test' , dependencies = ["Multitool" , "PackageType" , "PackageDescription" , "Utility" , "POSIX" , "libc" ]),
199
- ]
224
+ targets = parse_manifest ()
200
225
target_map = dict ((t .name , t ) for t in targets )
201
226
202
227
def create_bootstrap_files (sandbox_path , args ):
0 commit comments