@@ -17,17 +17,47 @@ class Platform(object):
17
17
Abstract representation of a platform Swift can run on.
18
18
"""
19
19
20
- def __init__ (self , name , archs ):
20
+ def __init__ (self , name , archs , sdk_name = None ):
21
21
"""
22
22
Create a platform with the given name and list of architectures.
23
23
"""
24
24
self .name = name
25
25
self .targets = [Target (self , arch ) for arch in archs ]
26
+ # FIXME: Eliminate this argument; apparently the SDK names are
27
+ # internally a private implementation detail of the build script, so we
28
+ # should just make them the same as the platform name.
29
+ self .sdk_name = name .upper () if sdk_name is None else sdk_name
26
30
27
31
# Add a property for each arch.
28
32
for target in self .targets :
29
33
setattr (self , target .arch , target )
30
34
35
+ @property
36
+ def is_darwin (self ):
37
+ """Convenience function for checking if this is a Darwin platform."""
38
+ return isinstance (self , DarwinPlatform )
39
+
40
+ @property
41
+ def supports_benchmark (self ):
42
+ # By default, we don't support benchmarks on most platforms.
43
+ return False
44
+
45
+
46
+ class DarwinPlatform (Platform ):
47
+ def __init__ (self , name , archs , sdk_name = None , is_simulator = False ):
48
+ super (DarwinPlatform , self ).__init__ (name , archs , sdk_name )
49
+ self .is_simulator = is_simulator
50
+
51
+ @property
52
+ def is_embedded (self ):
53
+ """Check if this is a Darwin platform for embedded devices."""
54
+ return self .name != "macosx"
55
+
56
+ @property
57
+ def supports_benchmark (self ):
58
+ # By default, on Darwin we support benchmarks.
59
+ return True
60
+
31
61
32
62
class Target (object ):
33
63
"""
@@ -37,23 +67,38 @@ class Target(object):
37
67
def __init__ (self , platform , arch ):
38
68
self .platform = platform
39
69
self .arch = arch
70
+ # Delegate to the platform, this is usually not arch specific.
71
+ self .supports_benchmark = self .platform .supports_benchmark
40
72
41
73
@property
42
74
def name (self ):
43
75
return "{}-{}" .format (self .platform .name , self .arch )
44
76
45
77
46
78
class StdlibDeploymentTarget (object ):
47
- OSX = Platform ("macosx" , archs = ["x86_64" ])
48
-
49
- iOS = Platform ("iphoneos" , archs = ["armv7" , "armv7s" , "arm64" ])
50
- iOSSimulator = Platform ("iphonesimulator" , archs = ["i386" , "x86_64" ])
51
-
52
- AppleTV = Platform ("appletvos" , archs = ["arm64" ])
53
- AppleTVSimulator = Platform ("appletvsimulator" , archs = ["x86_64" ])
54
-
55
- AppleWatch = Platform ("watchos" , archs = ["armv7k" ])
56
- AppleWatchSimulator = Platform ("watchsimulator" , archs = ["i386" ])
79
+ OSX = DarwinPlatform ("macosx" , archs = ["x86_64" ],
80
+ sdk_name = "OSX" )
81
+
82
+ iOS = DarwinPlatform ("iphoneos" , archs = ["armv7" , "armv7s" , "arm64" ],
83
+ sdk_name = "IOS" )
84
+ iOSSimulator = DarwinPlatform ("iphonesimulator" , archs = ["i386" , "x86_64" ],
85
+ sdk_name = "IOS_SIMULATOR" ,
86
+ is_simulator = True )
87
+
88
+ # Never build/test benchmarks on iOS armv7s.
89
+ iOS .armv7s .supports_benchmark = False
90
+
91
+ AppleTV = DarwinPlatform ("appletvos" , archs = ["arm64" ],
92
+ sdk_name = "TVOS" )
93
+ AppleTVSimulator = DarwinPlatform ("appletvsimulator" , archs = ["x86_64" ],
94
+ sdk_name = "TVOS_SIMULATOR" ,
95
+ is_simulator = True )
96
+
97
+ AppleWatch = DarwinPlatform ("watchos" , archs = ["armv7k" ],
98
+ sdk_name = "WATCHOS" )
99
+ AppleWatchSimulator = DarwinPlatform ("watchsimulator" , archs = ["i386" ],
100
+ sdk_name = "WATCHOS_SIMULATOR" ,
101
+ is_simulator = True )
57
102
58
103
Linux = Platform ("linux" , archs = [
59
104
"x86_64" ,
@@ -68,6 +113,24 @@ class StdlibDeploymentTarget(object):
68
113
69
114
Cygwin = Platform ("cygwin" , archs = ["x86_64" ])
70
115
116
+ Android = Platform ("android" , archs = ["armv7" ])
117
+
118
+ # The list of known platforms.
119
+ known_platforms = [
120
+ OSX ,
121
+ iOS , iOSSimulator ,
122
+ AppleTV , AppleTVSimulator ,
123
+ AppleWatch , AppleWatchSimulator ,
124
+ Linux ,
125
+ FreeBSD ,
126
+ Cygwin ,
127
+ Android ]
128
+
129
+ # Cache of targets by name.
130
+ _targets_by_name = dict ((target .name , target )
131
+ for platform in known_platforms
132
+ for target in platform .targets )
133
+
71
134
@staticmethod
72
135
def host_target ():
73
136
"""
@@ -135,6 +198,10 @@ def default_stdlib_deployment_targets():
135
198
# All other machines only configure their host stdlib by default.
136
199
return [host_target ]
137
200
201
+ @classmethod
202
+ def get_target_for_name (klass , name ):
203
+ return klass ._targets_by_name .get (name )
204
+
138
205
139
206
def install_prefix ():
140
207
"""
0 commit comments