-
-
Notifications
You must be signed in to change notification settings - Fork 508
/
Product.swift
192 lines (180 loc) · 5.31 KB
/
Product.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import Foundation
import xcodeproj
enum Product: String, CustomStringConvertible, CaseIterable {
case app
case staticLibrary = "static_library"
case dynamicLibrary = "dynamic_library"
case framework
case staticFramework
case unitTests = "unit_tests"
case uiTests = "ui_tests"
// case appExtension = "app_extension"
// case watchApp = "watch_app"
// case watch2App = "watch_2_app"
// case watchExtension = "watch_extension"
// case watch2Extension = "watch_2_extension"
// case tvExtension = "tv_extension"
// case messagesApplication = "messages_application"
// case messagesExtension = "messages_extension"
// case stickerPack = "sticker_pack"
var caseValue: String {
switch self {
case .app:
return "app"
case .staticLibrary:
return "staticLibrary"
case .dynamicLibrary:
return "dynamicLibrary"
case .framework:
return "framework"
case .staticFramework:
return "staticFramework"
case .unitTests:
return "unitTests"
case .uiTests:
return "uiTests"
// case .appExtension:
// return "appExtension"
// case .watchApp:
// return "watchApp"
// case .watch2App:
// return "watch2App"
// case .watchExtension:
// return "watchExtension"
// case .watch2Extension:
// return "watch2Extension"
// case .tvExtension:
// return "tvExtension"
// case .messagesApplication:
// return "messagesApplication"
// case .messagesExtension:
// return "messagesExtension"
// case .stickerPack:
// return "stickerPack"
}
}
var description: String {
switch self {
case .app:
return "application"
case .staticLibrary:
return "static library"
case .dynamicLibrary:
return "dynamic library"
case .framework:
return "framework"
case .staticFramework:
return "staticFramework"
case .unitTests:
return "unit tests"
case .uiTests:
return "ui tests"
// case .appExtension:
// return "app extension"
// case .watchApp:
// return "watch application"
// case .watch2App:
// return "watch 2 application"
// case .watchExtension:
// return "watch extension"
// case .watch2Extension:
// return "watch 2 extension"
// case .tvExtension:
// return "tv extension"
// case .messagesApplication:
// return "iMessage application"
// case .messagesExtension:
// return "iMessage extension"
// case .stickerPack:
// return "stickers pack"
}
}
/// Returns true if the target can be ran.
var runnable: Bool {
switch self {
case .app:
return true
default:
return false
}
}
/// Returns true if the product is a tests bundle.
var testsBundle: Bool {
return self == .uiTests || self == .unitTests
}
static func forPlatform(_ platform: Platform) -> Set<Product> {
var base: [Product] = [
.app,
.staticLibrary,
.dynamicLibrary,
.framework,
]
if platform == .iOS {
// base.append(.appExtension)
// base.append(.stickerPack)
// base.append(.messagesApplication)
// base.append(.messagesExtension)
}
if platform == .tvOS {
// base.append(.tvExtension)
}
if platform == .macOS ||
platform == .tvOS ||
platform == .iOS {
base.append(.unitTests)
base.append(.uiTests)
}
// if platform == .watchOS {
// base.append(contentsOf: [
// .watchApp,
// .watch2App,
// .watchExtension,
// .watch2Extension,
// ])
// }
return Set(base)
}
}
extension Product {
var xcodeValue: PBXProductType {
switch self {
case .app:
return .application
case .staticLibrary:
return .staticLibrary
case .dynamicLibrary:
return .dynamicLibrary
case .framework:
return .framework
case .staticFramework:
return .framework
case .unitTests:
return .unitTestBundle
case .uiTests:
return .uiTestBundle
// case .appExtension:
// return .appExtension
// case .watchApp:
// return .watchApp
// case .watch2App:
// return .watch2App
// case .watchExtension:
// return .watchExtension
// case .watch2Extension:
// return .watch2Extension
// case .tvExtension:
// return .tvExtension
// case .messagesApplication:
// return .messagesApplication
// case .messagesExtension:
// return .messagesExtension
// case .stickerPack:
// return .stickerPack
}
}
}
extension Product {
var isStatic: Bool {
return [.staticLibrary, .staticFramework].contains(self)
}
}