-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.swift
executable file
·136 lines (114 loc) · 3.61 KB
/
build.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env swift
import Foundation
// Usage: build.swift platforms
func execute(commandPath: String, arguments: [String]) throws {
let task = Process()
task.launchPath = commandPath
task.arguments = arguments
print("Launching command: \(commandPath) \(arguments.joined(separator: " "))")
task.launch()
task.waitUntilExit()
guard task.terminationStatus == 0 else {
throw TaskError.code(task.terminationStatus)
}
}
enum TaskError: Error {
case code(Int32)
}
enum Platform: String, CaseIterable, CustomStringConvertible {
case iOS_12
case iOS_13
case tvOS_12
case tvOS_13
case macOS_10_15
case watchOS_5
case watchOS_6
var destination: String {
switch self {
case .iOS_12:
return "platform=iOS Simulator,OS=12.2,name=iPad Pro (12.9-inch) (3rd generation)"
case .iOS_13:
return "platform=iOS Simulator,OS=13.2.2,name=iPad Pro (12.9-inch) (3rd generation)"
case .tvOS_12:
return "platform=tvOS Simulator,OS=12.2,name=Apple TV"
case .tvOS_13:
return "platform=tvOS Simulator,OS=13.2,name=Apple TV"
case .macOS_10_15:
return "platform=OS X"
case .watchOS_5:
return "OS=5.2,name=Apple Watch Series 4 - 44mm"
case .watchOS_6:
return "OS=6.1,name=Apple Watch Series 4 - 44mm"
}
}
var sdk: String {
switch self {
case .iOS_12,
.iOS_13:
return "iphonesimulator"
case .tvOS_12,
.tvOS_13:
return "appletvsimulator"
case .macOS_10_15:
return "macosx10.15"
case .watchOS_5,
.watchOS_6:
return "watchsimulator"
}
}
var shouldTest: Bool {
switch self {
case .iOS_12,
.iOS_13,
.tvOS_12,
.tvOS_13,
.macOS_10_15:
return true
case .watchOS_5,
.watchOS_6:
// watchOS does not support unit testing (yet?).
return false
}
}
var derivedDataPath: String {
".build/derivedData/" + description
}
var description: String {
rawValue
}
}
guard CommandLine.arguments.count > 1 else {
print("Usage: build.swift platforms")
throw TaskError.code(1)
}
try execute(commandPath: "/usr/bin/swift", arguments: ["package", "generate-xcodeproj", "--output=generated/"])
let rawPlatforms = CommandLine.arguments[1].components(separatedBy: ",")
for rawPlatform in rawPlatforms {
guard let platform = Platform(rawValue: rawPlatform) else {
print("Received unknown platform type \(rawPlatform)")
print("Possible platform types are: \(Platform.allCases)")
throw TaskError.code(1)
}
var xcodeBuildArguments = [
"-project", "generated/CacheAdvance.xcodeproj",
"-scheme", "CacheAdvance-Package",
"-sdk", platform.sdk,
"-configuration", "Release",
"-derivedDataPath", platform.derivedDataPath,
"-PBXBuildsContinueAfterErrors=0",
"OTHER_CFLAGS='-DGENERATED_XCODE_PROJECT'",
]
if !platform.destination.isEmpty {
xcodeBuildArguments.append("-destination")
xcodeBuildArguments.append(platform.destination)
}
if platform.shouldTest {
xcodeBuildArguments.append("-enableCodeCoverage")
xcodeBuildArguments.append("YES")
}
xcodeBuildArguments.append("build")
if platform.shouldTest {
xcodeBuildArguments.append("test")
}
try execute(commandPath: "/usr/bin/xcodebuild", arguments: xcodeBuildArguments)
}