forked from openedx-unsupported/edx-app-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
307 lines (251 loc) · 8.53 KB
/
build.gradle
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
import com.dd.plist.*
import org.edx.builder.TaskHelper
// Dependencies
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.googlecode.plist:dd-plist:1.16'
}
}
apply plugin: 'edxapp'
edx {
platform = IOS
}
// Configuration
def workspace = 'edX.xcworkspace'
def scheme = 'edX'
class IOSHelper {
// Environment Variable Conveniences
// Only valid when our task is invoked by an Xcode build
def getInfoPlistPath() {
def env = System.getenv()
return env['INFOPLIST_PATH']
}
def getBuiltProductsPath() {
def env = System.getenv()
return env['BUILT_PRODUCTS_DIR']
}
def getWrapperName() {
def env = System.getenv()
return env['WRAPPER_NAME']
}
def getBundleIdentifier() {
def env = System.getenv()
return env['PRODUCT_BUNDLE_IDENTIFIER']
}
def getFirebaseInfoPlistPath() {
return builtProductsPath + '/' + wrapperName + '/' + 'GoogleService-Info.plist'
}
def getBuiltInfoPlistPath() {
return builtProductsPath + '/' + infoPlistPath
}
def getBundleConfigPath() {
return builtProductsPath + '/' + wrapperName + '/config.plist'
}
def getFirebaseConfigPath() {
return builtProductsPath + '/' + wrapperName + '/firebase.plist'
}
// Saves our loaded and processed config YAML
// to a Plist in the app bundle
def saveProcessedConfig(config, toPath) {
def plist = [:]
for(c in config) {
plist[c.key] = c.value
}
// Save entire config
PropertyListParser.saveAsXML(NSObject.wrap(plist), new File(toPath))
}
// Modify Info.plist for specific services
def readInfoPlist(plistPath) {
// The configuration library doesn't know how to read
// binary plists so make sure it's an xml one
['plutil', '-convert', 'xml1', plistPath].execute().waitFor()
def plist = PropertyListParser.parse(new File(plistPath)).toJavaObject()
return plist
}
def writeInfoPlist(plist, path) {
PropertyListParser.saveAsXML(NSObject.wrap(plist), new File(path))
// Restore to binary for runtime performance
['plutil', '-convert', 'binary1', path].execute().waitFor()
}
def addURLScheme(scheme, plist) {
def body = [
'CFBundleTypeRole' : 'Editor',
'CFBundleURLSchemes' : [scheme]
]
def existing = plist['CFBundleURLTypes']
if(existing) {
// make sure we don't add it more than once
def found = false
for(entry in existing){
def schemes = entry['CFBundleURLSchemes']
if(schemes && schemes.contains(scheme)){
found = true
break
}
}
if(!found) {
def types = new ArrayList((ArrayList)existing)
types.add(body)
plist['CFBundleURLTypes'] = types
}
}
else {
plist["CFBundleURLTypes"] = [body]
}
}
def addFacebookConfig(config, plist) {
def facebook = config['FACEBOOK'] ?: [:]
def key = facebook['FACEBOOK_APP_ID']
if(!key) {
return
}
plist["FacebookAppID"] = key
def scheme = "fb" + key
addURLScheme(scheme, plist)
}
def addFirebaseKeys(config, plist) {
def firebase = config['FIREBASE'] ?: [:]
plist['BUNDLE_ID'] = bundleIdentifier
def apiKey = firebase['API_KEY']
def clientID = firebase['CLIENT_ID']
def googleAppID = firebase['GOOGLE_APP_ID']
def GCMSenderID = firebase['GCM_SENDER_ID']
if(!apiKey || !clientID || !googleAppID || !GCMSenderID) {
return
}
plist['API_KEY'] = apiKey
plist['CLIENT_ID'] = clientID
plist['GOOGLE_APP_ID'] = googleAppID
plist['GCM_SENDER_ID'] = GCMSenderID
// set optional keys if present in config
def productID = firebase['PRODUCT_ID']
if (productID) {
plist['PROJECT_ID'] = productID
plist['STORAGE_BUCKET'] = productID + '.appspot.com'
plist['DATABASE_URL'] = 'https://' + productID + '.firebaseio.com'
}
def reversedCliendID = firebase['REVERSED_CLIENT_ID']
if (reversedCliendID) {
plist['REVERSED_CLIENT_ID'] = reversedCliendID
}
}
def addFabricConfig(config, plist) {
def fabric = config['FABRIC'] ?: [:]
def key = fabric['FABRIC_KEY']
if(!key) {
return
}
def body = [
'APIKey' : key,
'Kits' : [
[
'KitInfo' : [],
'KitName' : 'Crashlytics'
]
]
]
plist["Fabric"] = body
}
def addGoogleConfig(config, plist) {
def google = config['GOOGLE'] ?: [:]
def key = google['GOOGLE_PLUS_KEY']
if(!key) {
return
}
// Google login schemes are the reverse DNS of the api key
def scheme = key.tokenize('.').reverse().join('.')
addURLScheme(scheme, plist)
}
}
// Tasks
task printBuildEnvironment(type : Exec) {
def arguments = [
'xcodebuild',
'-workspace', workspace,
'-scheme', scheme,
'-showBuildSettings'
]
commandLine arguments
}
task uploadDebuggingSymbols << {
def taskHelper = new TaskHelper()
def config = taskHelper.loadConfig(project)
def fabric = config['FABRIC'] ?: [:]
def key = fabric['FABRIC_KEY']
def secret = fabric['FABRIC_BUILD_SECRET']
def srcroot = System.getenv()['SRCROOT']
if(key && secret && srcroot) {
[srcroot + "/Pods/Fabric/Fabric.framework/run", key, secret].execute().waitFor()
}
}
task applyConfig << {
processDefaultInfoPlist()
processFirebaseInfoPlist()
}
def processDefaultInfoPlist() {
def (config, helper, plist, infoPlistPath, plistPath) = getConfigProcessHelpers(false)
helper.addFacebookConfig(config, plist)
helper.addFabricConfig(config, plist)
helper.addGoogleConfig(config, plist)
saveConfigChanges(helper, plist, infoPlistPath, plistPath)
}
def processFirebaseInfoPlist() {
def (config, helper, plist, infoPlistPath, plistPath) = getConfigProcessHelpers(true)
helper.addFirebaseKeys(config, plist)
saveConfigChanges(helper, plist, infoPlistPath, plistPath)
}
def getConfigProcessHelpers(isFirebase) {
def taskHelper = new TaskHelper()
def config = taskHelper.loadConfig(project)
def helper = new IOSHelper()
def infoPlistPath = helper.builtInfoPlistPath
def plistPath = helper.bundleConfigPath
if (isFirebase) {
plistPath = helper.firebaseConfigPath
infoPlistPath = helper.firebaseInfoPlistPath
}
helper.saveProcessedConfig(config, plistPath)
def plist = helper.readInfoPlist(infoPlistPath)
return [config, helper, plist, infoPlistPath, plistPath]
}
def saveConfigChanges(helper, plist, infoPlistPath, plistPath) {
helper.writeInfoPlist(plist, infoPlistPath)
// double check that the config file actually got made
def check = ["[", "-f", plistPath, "]"].execute()
check.waitFor()
def result = check.exitValue()
assert result == 0
}
task wrapper(type: Wrapper) {
gradleVersion = '4.10.2'
}
def testBuildArguments(workspace, scheme, OS, record) {
def args = [
'xcodebuild', '-workspace', workspace, '-scheme', scheme, '-sdk', 'iphonesimulator', '-destination', 'platform=iOS Simulator,name=iPhone 5s,OS=' + OS, 'test'
]
if(record) {
args += ["OTHER_SWIFT_FLAGS=\$(OTHER_SWIFT_FLAGS) -D RECORD_SNAPSHOTS"]
}
return args
}
def RTLSchemeForScheme(scheme) {
return scheme + '-RTL'
}
def operatingSystems = ["currentOS": "10.0", "previousOS": "9.0"]
def directions = ["LTR": scheme, "RTL": RTLSchemeForScheme(scheme)]
def commands = ["test" : ["record" : false], "recordSnapshots": ["record" : true]]
for(OS in operatingSystems) {
for(direction in directions) {
for(command in commands) {
def record = command.value["record"]
def task = project.task(type: Exec, command.key + direction.key.capitalize() + OS.key.capitalize()) {
commandLine testBuildArguments(workspace, direction.value, OS.value, record)
}
}
}
}
task test(dependsOn: tasks.findAll { task -> task.name.startsWith('test')}) {}
task recordSnapshots(dependsOn: tasks.findAll { task -> task.name.startsWith('recordSnapshots')}) {}