Skip to content

Commit f407cdf

Browse files
committed
[swift_build_support.targets] Add some additional metadata.
- This adds several platform/target properties used to configure the default behavior for a build. - This also adds an API to find a target from a name.
1 parent 6df6ae7 commit f407cdf

File tree

1 file changed

+78
-11
lines changed
  • utils/swift_build_support/swift_build_support

1 file changed

+78
-11
lines changed

utils/swift_build_support/swift_build_support/targets.py

Lines changed: 78 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,47 @@ class Platform(object):
1717
Abstract representation of a platform Swift can run on.
1818
"""
1919

20-
def __init__(self, name, archs):
20+
def __init__(self, name, archs, sdk_name=None):
2121
"""
2222
Create a platform with the given name and list of architectures.
2323
"""
2424
self.name = name
2525
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
2630

2731
# Add a property for each arch.
2832
for target in self.targets:
2933
setattr(self, target.arch, target)
3034

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+
3161

3262
class Target(object):
3363
"""
@@ -37,23 +67,38 @@ class Target(object):
3767
def __init__(self, platform, arch):
3868
self.platform = platform
3969
self.arch = arch
70+
# Delegate to the platform, this is usually not arch specific.
71+
self.supports_benchmark = self.platform.supports_benchmark
4072

4173
@property
4274
def name(self):
4375
return "{}-{}".format(self.platform.name, self.arch)
4476

4577

4678
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)
57102

58103
Linux = Platform("linux", archs=[
59104
"x86_64",
@@ -68,6 +113,24 @@ class StdlibDeploymentTarget(object):
68113

69114
Cygwin = Platform("cygwin", archs=["x86_64"])
70115

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+
71134
@staticmethod
72135
def host_target():
73136
"""
@@ -135,6 +198,10 @@ def default_stdlib_deployment_targets():
135198
# All other machines only configure their host stdlib by default.
136199
return [host_target]
137200

201+
@classmethod
202+
def get_target_for_name(klass, name):
203+
return klass._targets_by_name.get(name)
204+
138205

139206
def install_prefix():
140207
"""

0 commit comments

Comments
 (0)