forked from googlesamples/google-signin-unity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
377 lines (343 loc) · 12.6 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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
/* Copyright (C) 2014 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Top-level build file where you can add configuration options common to all sub-projects/modules.
import groovy.io.FileType
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
project.ext {
// Determine the current OS.
os_name = System.getProperty("os.name").toLowerCase();
os_osx = os_name.contains("mac os x");
os_windows = os_name.contains("windows");
os_linux = os_name.contains("linux");
unity_exe = System.getProperty("UNITY_EXE")
if (unity_exe == null || unity_exe.isEmpty()) {
unity_exe = System.getenv("UNITY_EXE")
}
if (unity_exe == null || unity_exe.isEmpty()) {
if (os_osx) {
unity_exe = '/Applications/Unity/Unity.app/Contents/MacOS/Unity'
} else if (os_windows) {
unity_exe = 'c:\\program files\\unity\\editor\\unity.exe'
} else {
// Fallback to just unity, and expect it on the path.
unity_exe = 'unity'
}
}
git_exe = System.getProperty("GIT_EXE")
if (git_exe == null || git_exe.isEmpty()) {
git_exe = System.getenv("GIT_EXE")
}
if (git_exe == null || git_exe.isEmpty()) {
// Fallback to git and expect it to be on the path.
git_exe = 'git'
}
pluginVersion = "1.0.4"
currentPluginBasename = 'google-signin-plugin'
currentPluginName = (currentPluginBasename + '-' + pluginVersion +
'.unitypackage')
editorDir = "Assets/GoogleSignIn/Editor"
uploadDir = "${buildDir}/GoogleSignInPlugin/${editorDir}/m2repository"
exportPath = file(currentPluginName).absolutePath
samplePath = file('GoogleSignIn-sample.unitypackage').absolutePath
pluginSrcPath = file('GoogleSignInPlugin').absolutePath
pluginProjectPath = file('build/GoogleSignInPlugin').absolutePath
resolverDir = new File('build/jarresolver').absolutePath
jarresolver_uri = System.getProperty("RESOLVER_PACKAGE_URI")
jarresolver_repos = [
'https://github.com/googlesamples/unity-jar-resolver.git'
]
// Set the tag to a specific value if you want to build pinned to a
// specific version of the jar resolver (This is uncommon).
// null indicates HEAD.
jarresolver_tag = null;
}
task clean(type: Delete) {
delete rootProject.buildDir
}
task copy_unity_project() {
dependsOn ':native-googlesignin:uploadArchives'
doFirst {
copy {
from pluginSrcPath
into pluginProjectPath
}
}
}
task copy_jarresolver() {
description = "Clones the jar resolver project."
doFirst {
if (file(resolverDir).exists()) {
delete resolverDir
}
}
doLast {
// Copy the package if the direct path is given.
if (jarresolver_uri != null) {
mkdir("${resolverDir}")
def resolver = new File("${resolverDir}/resolver.unitypackage")
new URL("${jarresolver_uri}").withInputStream {
inputStream -> resolver.withOutputStream { it << inputStream }
}
return
}
// Else, check each one of the repo addresses and stop when successful.
for (repo in jarresolver_repos) {
def result = exec {
executable "${git_exe}"
args "clone", repo, "${resolverDir}"
ignoreExitValue true
}
if (result.exitValue == 0 && jarresolver_tag != null) {
result = exec {
executable "${git_exe}"
args "checkout", "-b", "buildver", "${jarresolver_tag}"
workingDir "${resolverDir}"
}
}
if (result.exitValue == 0) {
println "Downloaded resolver from " + repo
return
}
}
}
}
task import_jarresolver() {
description = "Imports the jar resolver into the project"
dependsOn copy_unity_project, copy_jarresolver
doLast {
def tree = fileTree(resolverDir) {
include "*.unitypackage"
}
def jarresolver_package = tree.getSingleFile()
def argv = [
"-gvh_disable",
"-g.building",
"-buildTarget",
"android",
// This prevents the VersionHandler to preserve the plugin layout
"-batchmode",
"-projectPath", pluginProjectPath,
"-logFile", "build/import_jarresolver.log",
"-importPackage", jarresolver_package,
"-quit"
]
ext.execResult = exec {
executable "${unity_exe}"
args argv
ignoreExitValue true
}
if (ext.execResult.exitValue != 0) {
println "***Error Running Unity:"
def src = file('build/import_jarresolver.log').text
print src
throw new GradleException('error importing jarresolver plugin')
}
}
}
task generate_dependency_xml() {
description "Generate the JarResolver dependency file for the support library"
dependsOn copy_unity_project
doFirst {
def xmlFile = file("${pluginProjectPath}/${editorDir}/GoogleSignInSupportDependencies.xml")
xmlFile << '<?xml version="1.0" encoding="UTF-8" ?>\n'
xmlFile << '<dependencies>\n'
xmlFile << '<!-- Internal library dependency generated at build time. -->\n'
xmlFile << ' <androidPackages>\n'
xmlFile << ' <androidPackage spec="com.google.signin:google-signin-support:'
xmlFile << "${pluginVersion}\">\n"
xmlFile << ' <repositories>\n'
xmlFile << ' <repository>Assets/GoogleSignIn/Editor/m2repository</repository>\n'
xmlFile << ' </repositories>\n'
xmlFile << ' </androidPackage>\n'
xmlFile << ' </androidPackages>\n'
xmlFile << '</dependencies>\n'
}
}
task generate_manifest(dependsOn: [ 'inject_versionIntoMetaFiles']) {
description 'Generate a manifest for the files in the plug-in.'
doLast {
def dir = file("${pluginProjectPath}/Assets")
def list = []
dir.eachFileRecurse(groovy.io.FileType.FILES) { filename ->
def path = filename.path
if (!(path.toLowerCase().endsWith('.meta') ||
path.toLowerCase().endsWith('.txt'))) {
list << filename.path.replace("${pluginProjectPath}/", '')
}
}
def manifest = file("${pluginProjectPath}/${editorDir}/" +
versionedAssetName(currentPluginBasename + '.txt',
"${pluginVersion}"))
manifest.write(list.join('\n') + '\n')
}
}
task copy_manifestMetadata(dependsOn: generate_manifest, type: Copy) {
def manifestBasename = versionedAssetName(currentPluginBasename + '.txt',
null) + '.meta'
description 'Copy .meta file for the plugin manifest.'
from file("${pluginSrcPath}/${editorDir}/" + manifestBasename)
into file("${pluginProjectPath}/${editorDir}/")
rename {
String fn ->
return fn.replace(manifestBasename,
versionedAssetName(currentPluginBasename + '.txt',
"${pluginVersion}") + '.meta')
}
}
task package_plugin () {
description = "Creates and exports the Plugin unity package"
dependsOn generate_manifest, copy_manifestMetadata
doLast {
def tree = fileTree(resolverDir) {
include "*.unitypackage"
}
def jarresolver_package = tree.getSingleFile()
def argv = [
"-gvh_disable",
"-g.building",
"-buildTarget",
"android",
// This prevents the VersionHandler to preserve the plugin layout
"-batchmode",
"-projectPath", pluginProjectPath,
"-logFile", "build/unity.log",
"-importPackage", jarresolver_package,
"-exportPackage",
"Assets/GoogleSignIn",
"Assets/Parse",
"Assets/PlayServicesResolver",
"Assets/Plugins",
"${exportPath}",
"-quit"
]
ext.execResult = exec {
executable "${unity_exe}"
args argv
ignoreExitValue true
}
if (ext.execResult.exitValue != 0) {
println "***Error Running Unity:"
def src = file('build/unity.log').text
print src
throw new GradleException('error exporting plugin')
}
}
}
task package_sample () {
description = "Creates and exports the Google Sign-in Sample"
doLast {
def argv = [
"-gvh_disable",
"-g.building",
// NOTE: This doesn't target Android since we don't want to have
// dependencies on the Jar Resolver as they require the plugin to
// be enabled during the build process which would break the
// versioning process. Compilation is verified when exporting
// the sample projects.
"-batchmode",
"-projectPath", pluginProjectPath,
"-logFile", "build/unity-sample.log",
"-exportPackage",
"Assets/SignInSample",
"${samplePath}",
"-quit"
]
ext.execResult = exec {
executable "${unity_exe}"
args argv
ignoreExitValue true
}
if (ext.execResult.exitValue != 0) {
println "***Error Running Unity:"
def src = file('build/unity-sample.log').text
print src
throw new GradleException('error exporting sample')
}
}
}
task inject_versionIntoMetaFiles() {
description 'Inject the version number into the plugin\'s meta files.'
dependsOn copy_unity_project, generate_dependency_xml, import_jarresolver
doLast {
for (fileobj in fileTree("${pluginProjectPath}")) {
if (fileobj.path.endsWith('.meta')) {
// Skip the manifest files for any previous versions
if (fileobj.path.contains("Editor/${currentPluginBasename}")) {
continue
}
def lines = fileobj.text.split('\n')
def outputLines = []
def added = false
for (line in lines) {
outputLines.add(line)
if (line.contains('labels:')) {
outputLines.add("- gvh_v${pluginVersion}")
added = true
} else if (line.contains('folderAsset:') && line.contains('yes')) {
added = true
}
}
if (!added) {
outputLines.add("labels:\n- gvh_v${pluginVersion}")
}
fileobj.write(outputLines.join('\n') + '\n')
}
}
}
}
// Construct the name of a versioned asset from the source filename and version
// // string.
// // The encoded string takes the form...
// // ${filename}_v${version}_.${extension}
// // where extension is derived from the specified filename.
def versionedAssetName(filename, version) {
def extensionIndex = filename.lastIndexOf('.')
def basename = filename.substring(0, extensionIndex)
def extension = filename.substring(extensionIndex)
// Encode the DLL version and target names into the DLL in the form...
// ${dllname}_t${hypen_separated_target_names}_v${version}.dll
def targetName = basename
if (version != null && !version.isEmpty()) {
targetName += '_v' + version
}
return targetName + extension
}
/*
* This is a top level task that build the Unity plugin.
* It does the following:
* - copy the java/C++ library to the Plugins directory.
* - Import the latest Play Services Resolver plugin
* - Build the Google Sign-In plugin package (requires Unity).
* - Build the Google Sign-In Sample package (requires Unity).
*/
task build_all() {
dependsOn ':native-googlesignin:uploadArchives', copy_jarresolver, package_plugin, package_sample
}