forked from openedx-unsupported/edx-app-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
240 lines (193 loc) · 6.19 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
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 getBuiltInfoPlistPath() {
return builtProductsPath + '/' + infoPlistPath
}
def getBundleConfigPath() {
return builtProductsPath + '/' + wrapperName + '/config.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() {
// The configuration library doesn't know how to read
// binary plists so make sure it's an xml one
['plutil', '-convert', 'xml1', builtInfoPlistPath].execute().waitFor()
def plist = PropertyListParser.parse(new File(builtInfoPlistPath)).toJavaObject()
return plist
}
def writeInfoPlist(plist) {
PropertyListParser.saveAsXML(NSObject.wrap(plist), new File(builtInfoPlistPath))
// Restore to binary for runtime performance
['plutil', '-convert', 'binary1', builtInfoPlistPath].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 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 << {
def taskHelper = new TaskHelper()
def config = taskHelper.loadConfig(project)
def helper = new IOSHelper()
// Save all keys to config.plist
helper.saveProcessedConfig(config, helper.bundleConfigPath)
// Save specific fields to Info.plist
def plist = helper.readInfoPlist()
helper.addFacebookConfig(config, plist)
helper.addFabricConfig(config, plist)
helper.addGoogleConfig(config, plist)
helper.writeInfoPlist(plist)
// double check that the config file actually got made
def check = ["[", "-f", helper.bundleConfigPath, "]"].execute()
check.waitFor()
def result = check.exitValue()
assert result == 0
}
task wrapper(type: Wrapper) {
gradleVersion = '2.2.1'
}
def testBuildArguments(workspace, scheme) {
return [
'xcodebuild', '-workspace', workspace, '-scheme', scheme, '-sdk', 'iphonesimulator', '-destination', 'platform=iOS Simulator,name=iPhone 6s,OS=9.0','build', 'test'
]
}
def RTLSchemeForScheme(scheme) {
return scheme + '-RTL'
}
def recordSnapshotsBuildArguments(workspace, scheme) {
return testBuildArguments(workspace, scheme) + "OTHER_SWIFT_FLAGS=\$(OTHER_SWIFT_FLAGS) -D RECORD_SNAPSHOTS"
}
task testDefault(type : Exec) {
commandLine testBuildArguments(workspace, scheme)
}
task testRTL(type : Exec) {
commandLine testBuildArguments(workspace, RTLSchemeForScheme(scheme))
}
task recordSnapshotsDefault(type : Exec) {
commandLine recordSnapshotsBuildArguments(workspace, scheme)
}
task recordSnapshotsRTL(type : Exec) {
commandLine recordSnapshotsBuildArguments(workspace, RTLSchemeForScheme(scheme))
}
task recordSnapshots(dependsOn : [recordSnapshotsDefault, recordSnapshotsRTL]) { }
task test(dependsOn : [testDefault, testRTL]) { }