@@ -45,92 +45,100 @@ project.ext {
45
45
' may fail.' )
46
46
}
47
47
48
- // Get the path to the Unity DLLs.
49
- // Unity DLLs are referenced by the plug-in and therefore required by the
50
- // build process.
51
- unity_dll_path = System . getProperty(" UNITY_DLL_PATH" )
52
- unity_dll_path_file = (unity_dll_path == null ||
53
- unity_dll_path. isEmpty()) ?
54
- null : new File (unity_dll_path);
55
- if ((unity_dll_path_file == null || ! unity_dll_path_file. exists()) &&
56
- unity_exe_found) {
57
- if (os_osx) {
58
- // Search paths relative to the Unity binary for the Managed
59
- // directory.
60
- for (path in [' ../Frameworks/Managed' , ' ../Managed' ]) {
61
- unity_dll_path_file = new File (new File (unity_exe). getParentFile(),
62
- path)
63
- if (unity_dll_path_file. exists()) break ;
48
+ // find the unity root directory by working up from the executable.
49
+ // not, perfect, but pretty close, work up the tree until the
50
+ // name starts with unity.
51
+ unity_root = (new File (unity_exe)). getParentFile(). getParentFile();
52
+ while (! unity_root. name. toLowerCase(). startsWith(" unity" )) {
53
+ if (unity_root. getParentFile() != null ) {
54
+ unity_root = unity_root. getParentFile();
55
+ } else {
56
+ break ;
64
57
}
65
- } else if (os_windows || os_linux) {
66
- // ${unity_exe}/../Data/Managed/Unity{Engine,Editor}.dll
67
- unity_dll_path_file = new File (
68
- (new File (unity_exe)). getParentFile(),
69
- ' Data' + File . separator + ' Managed' )
70
- }
71
- if (unity_dll_path_file != null && unity_dll_path_file. exists()) {
72
- unity_dll_path = unity_dll_path_file. getPath()
73
- }
74
58
}
75
- if (unity_dll_path_file == null || ! unity_dll_path_file. exists()) {
76
- logger. error(' Unity DLLs not found, plug-in build will fail.' )
59
+
60
+ logger. info( " Unity root is $unity_root " )
61
+
62
+ // find unity engine dll
63
+ unity_dll_path = findUnityPath(" UNITY_DLL_PATH" , true ,
64
+ fileTree(dir : unity_root). matching {
65
+ include ' **/Managed/UnityEngine.dll' });
66
+
67
+ if (unity_dll_path == null || ! unity_dll_path. exists()) {
68
+ logger. warn(' Unity Editor and Runtime DLLs not found, compilation may fail!' )
69
+ } else {
70
+ logger. info(" Unity Engine DLL path is $unity_dll_path " )
77
71
}
78
72
79
- unity_playback_engines_dll_path = System . getProperty(
80
- " UNITY_PLAYBACK_ENGINES_DLL_PATH" )
81
- unity_playback_engines_dll_path_file = (
82
- unity_playback_engines_dll_path == null ||
83
- unity_playback_engines_dll_path. isEmpty()) ? null : (
84
- new File (unity_playback_engines_dll_path))
85
- if ((unity_playback_engines_dll_path_file == null ||
86
- ! unity_playback_engines_dll_path_file. exists()) &&
87
- unity_exe_found) {
88
- if (os_osx) {
89
- // ${unity_exe}/../../../../PlaybackEngines
90
- unity_playback_engines_dll_path_file = new File (
91
- (new File (unity_exe))
92
- .getParentFile()
93
- .getParentFile()
94
- .getParentFile()
95
- .getParentFile(),
96
- ' PlaybackEngines' )
97
- println unity_playback_engines_dll_path_file. getPath()
98
- } else if (os_windows) {
99
- // ${unity_exe}/../Data/PlaybackEngines
100
- unity_playback_engines_dll_path_file = new File (
101
- (new File (unity_exe)). getParentFile(),
102
- ' Data' + File . separator + ' PlaybackEngines' )
103
- }
104
- if (unity_playback_engines_dll_path_file != null &&
105
- unity_playback_engines_dll_path_file. exists()) {
106
- unity_playback_engines_dll_path =
107
- unity_playback_engines_dll_path_file. getPath()
108
- }
73
+ // ios runtime dll. This is with the playback engine, so the
74
+ // structure is different for MacOS and the others.
75
+ unity_ios_dll_path = findUnityPath(" UNITY_IOS_PLAYBACK_PATH" , true ,
76
+ os_osx ?
77
+ fileTree(dir : unity_root. parentFile). matching {
78
+ include ' **/PlaybackEngines/iOSSupport/UnityEditor.iOS.Extensions.dll'
79
+ } :
80
+ fileTree(dir : unity_root). matching {
81
+ include ' **/PlaybackEngines/iOSSupport/UnityEditor.iOS.Extensions.dll'
82
+ })
83
+
84
+ if (unity_ios_dll_path == null || ! unity_ios_dll_path. exists()) {
85
+ logger. warn(' Unity iOS Playback engine not found, compilation may fail!' )
86
+ } else {
87
+ logger. info(" Unity iOS Playback engine is $unity_ios_dll_path " )
109
88
}
110
- if (unity_playback_engines_dll_path_file == null ||
111
- ! unity_playback_engines_dll_path_file. exists()) {
112
- logger. error(' Unity Playback Engine DLLs not found, iOS plug-in build ' +
113
- ' will fail.' )
89
+
90
+
91
+ // find the NUnit framework dll.
92
+ unity_nunit_dll_path = findUnityPath(" UNITY_NUNIT_PATH" , true ,
93
+ fileTree(dir : unity_root). matching {
94
+ include ' **/nunit.framework.dll'
95
+ })
96
+
97
+ if (unity_nunit_dll_path == null || ! unity_nunit_dll_path. exists()) {
98
+ logger. warn(' Unity NUnit framework not found, compilation may fail!' )
99
+ } else {
100
+ logger. info(" Unity NUnity framework found in $unity_nunit_dll_path " )
114
101
}
115
102
116
- // Mono's xbuild tool is required to build the managed DLLs in the plug-in.
117
- xbuild_exe = System . getProperty(" XBUILD_EXE" )
118
- if (xbuild_exe == null || xbuild_exe. isEmpty()) {
119
- xbuild_exe = System . getenv(" XBUILD_EXE" )
103
+ // xbuild is used to build the dlls.
104
+ if (os_windows) {
105
+ xbuild_exe = findUnityPath(" XBUILD_EXE" , false ,
106
+ fileTree(dir : unity_root). matching { include ' **/Mono/bin/xbuild.bat' })
107
+ } else if (os_osx || os_linux) {
108
+ xbuild_exe = findUnityPath(" XBUILD_EXE" , false ,
109
+ fileTree(dir : unity_root). matching { include ' **/xbuild' })
120
110
}
121
- if (xbuild_exe == null || xbuild_exe. isEmpty()) {
122
- xbuild_exe = ' xbuild'
111
+ if (xbuild_exe == null || ! xbuild_exe. exists()) {
112
+ logger. warn(" xbuild command not found, compilation may fail." )
113
+ xbuild_exe = null
114
+ } else {
115
+ logger. info(" xbuild found at $xbuild_exe " )
116
+ }
117
+
118
+ // nunit-console is used to run tests.
119
+ if (os_windows) {
120
+ nunit_console_exe = findUnityPath(" NUNIT_CONSOLE_EXE" , false ,
121
+ fileTree(dir : unity_root). matching { include ' **/Mono/bin/nunut-console2.bat' })
122
+ } else if (os_osx) {
123
+ nunit_console_exe = findUnityPath(" NUNIT_CONSOLE_EXE" , false ,
124
+ fileTree(dir : unity_root). matching { include ' **/nunit-console2' })
125
+ } else if (os_linux) {
126
+ nunit_console_exe = findUnityPath(" NUNIT_CONSOLE_EXE" , false ,
127
+ fileTree(dir : unity_root). matching { include ' **/nunit-console' })
123
128
}
124
- if (! (new File (xbuild_exe)). exists()) {
125
- logger. warn(' xbuild not found, plug-in build may fail.' )
129
+ if (nunit_console_exe == null || ! nunit_console_exe. exists()) {
130
+ logger. warn(" nunit_console command not found, compilation may fail." )
131
+ nunit_console_exe = null
132
+ } else {
133
+ logger. info(" nunit_console found at $nunit_console_exe " )
126
134
}
127
135
128
136
pluginSrc = file(' plugin' ). absolutePath
129
137
pluginProj = file(' build/PluginSrc' ). absolutePath
130
138
buildPath = file(' build' ). absolutePath
131
139
exportPath = file(' build/plugin.unitypackage' ). absolutePath
132
140
dllDir = ' Assets/PlayServicesResolver/Editor'
133
- pluginVersion = ' 1.2.1 .0'
141
+ pluginVersion = ' 1.2.6 .0'
134
142
currentPluginPath = file(' .' ). absolutePath
135
143
currentPluginBasename = ' play-services-resolver'
136
144
currentPluginName = (currentPluginBasename + ' -' + pluginVersion +
@@ -140,27 +148,52 @@ project.ext {
140
148
task compile_resolverTests (type : Exec ) {
141
149
description ' Compile the tests for the Mono framework component.'
142
150
workingDir ' source'
143
- commandLine " ${ xbuild_exe} " , ' /target:JarResolverTests'
144
- ext. remoteTaskPhase = ' prebuild'
151
+ commandLine " ${ xbuild_exe} " , ' /target:JarResolverTests' ,
152
+ " /property:NUnityHintPath=$unity_nunit_dll_path . absolutePath "
153
+ ext. remoteTaskPhase = ' build'
145
154
}
146
155
147
156
task test_resolverLib (type : Exec , dependsOn : compile_resolverTests) {
148
157
description ' Runs the tests.'
149
158
workingDir ' source'
150
- commandLine " nunit-console " ,
159
+ commandLine " $n unit_console_exe " ,
151
160
" JarResolverTests/bin/Debug/JarResolverTests.dll"
152
- ext. remoteTaskPhase = ' prebuild '
161
+ ext. remoteTaskPhase = ' build '
153
162
}
154
163
155
- task copy_unityDlls (type : Copy ) {
156
- description ' Copy Unity DLLs required to build managed DLLs in the plugin.'
157
- from files(new File (project. ext. unity_dll_path_file, ' UnityEngine.dll' ),
158
- new File (project. ext. unity_dll_path_file, ' UnityEditor.dll' ),
159
- new File ((File )project. ext. unity_playback_engines_dll_path_file,
160
- ' iOSSupport' + File . separator +
161
- ' UnityEditor.iOS.Extensions.Xcode.dll' ))
162
- into ' unity_dlls'
163
- ext. remoteTaskPhase = ' prebuild'
164
+ // / find paths within the Unity file tree used for building.
165
+ def findUnityPath (propertyKey , wantDirectory , fileTree ) {
166
+
167
+ def propValue;
168
+ def fileValue;
169
+
170
+ propValue = System . getProperty(propertyKey)
171
+ if (propValue == null || propValue. isEmpty()) {
172
+ propValue = System . getenv(propertyKey)
173
+ }
174
+ // convert string to file object
175
+ if (propValue != null ) {
176
+ fileValue = file(propValue)
177
+ } else {
178
+ fileValue = null
179
+ }
180
+
181
+ if (fileValue == null || ! fileValue. exists()) {
182
+ // take the shortest path location.
183
+ fileValue = null
184
+ fileTree. files. each { p ->
185
+ if (fileValue == null ||
186
+ fileValue. absolutePath. length() > p. absolutePath. length()) {
187
+ fileValue = p;
188
+ }
189
+ }
190
+ }
191
+
192
+ if (wantDirectory) {
193
+ return fileValue != null ? fileValue. parentFile : null ;
194
+ } else {
195
+ return fileValue
196
+ }
164
197
}
165
198
166
199
// Construct the name of a versioned asset from the source filename and version
@@ -190,11 +223,15 @@ def build_pluginDll(projectName, assemblyDllBasename) {
190
223
191
224
def compileTask = tasks. create(name : " compile_" + projectName,
192
225
type : Exec ,
193
- description : ' Compile ' + projectName,
194
- dependsOn : [copy_unityDlls] )
226
+ description : ' Compile ' + projectName
227
+ )
195
228
compileTask. workingDir(' source' )
196
- compileTask. commandLine([" ${ xbuild_exe} " , " /target:" + projectName])
197
- compileTask. ext. remoteTaskPhase = " prebuild"
229
+ compileTask. commandLine([" ${ xbuild_exe} " , " /target:" + projectName,
230
+ " /property:UnityHintPath=$unity_dll_path . absolutePath " ,
231
+ " /property:UnityIosPath=$unity_ios_dll_path . absolutePath "
232
+ ])
233
+
234
+ compileTask. ext. remoteTaskPhase = " build"
198
235
def assemblyDllSource = file(" source/" + projectName + " /bin/Debug/" +
199
236
assemblyDllBasename)
200
237
@@ -218,7 +255,7 @@ def build_pluginDll(projectName, assemblyDllBasename) {
218
255
}
219
256
return fn
220
257
})
221
- copyTask. ext. remoteTaskPhase = " prebuild "
258
+ copyTask. ext. remoteTaskPhase = " build "
222
259
}
223
260
224
261
build_pluginDll(" PlayServicesResolver" , " Google.JarResolver.dll" )
@@ -249,15 +286,15 @@ task copy_pluginTemplate(type: Copy, dependsOn: update_metadataForVersion) {
249
286
into " ${ pluginProj} "
250
287
exclude ' **/*.dll.*' , ' **/*.txt.meta'
251
288
duplicatesStrategy ' include'
252
- ext. remoteTaskPhase = ' prebuild '
289
+ ext. remoteTaskPhase = ' build '
253
290
}
254
291
255
292
task inject_versionIntoMetaFiles (dependsOn : [copy_pluginTemplate,
256
293
' copy_PlayServicesResolver' ,
257
294
' copy_VersionHandler' ,
258
295
' copy_IOSResolver' ]) {
259
296
description ' Inject the version number into the plugin\' s meta files.'
260
- ext. remoteTaskPhase = ' prebuild '
297
+ ext. remoteTaskPhase = ' build '
261
298
doLast {
262
299
for (fileobj in fileTree(" ${ pluginProj} " )) {
263
300
if (fileobj. path. endsWith(' .meta' )) {
@@ -309,7 +346,7 @@ task generate_manifest(dependsOn: ['copy_manifestMetadata',
309
346
" ${ pluginVersion} " ))
310
347
manifest. write(list. join(' \n ' ) + ' \n ' )
311
348
}
312
- ext. remoteTaskPhase = ' prebuild '
349
+ ext. remoteTaskPhase = ' build '
313
350
}
314
351
315
352
task export_package (dependsOn : ' generate_manifest' ) {
@@ -333,9 +370,11 @@ task export_package(dependsOn: 'generate_manifest') {
333
370
}
334
371
}
335
372
ext. remoteTaskPhase = ' build'
373
+
374
+ dependsOn test_resolverLib
336
375
}
337
376
338
- task copy_plugin (dependsOn : ' export_package ' ) {
377
+ task copy_plugin () {
339
378
description ' Copy plugin to the current-build directory'
340
379
doFirst {
341
380
// If the version number has been bumped delete the exploded directory.
@@ -368,6 +407,20 @@ task build_unityPackage(dependsOn: 'copy_plugin') {
368
407
}
369
408
}
370
409
410
+ task clean () {
411
+ doFirst {
412
+ delete ' build'
413
+ file(" source" ). listFiles(). each { f ->
414
+ if (file(" $f /obj" ). exists()) {
415
+ delete " $f /obj"
416
+ }
417
+ if (file(" $f /bin" ). exists()) {
418
+ delete " $f /bin"
419
+ }
420
+ }
421
+ }
422
+ }
423
+
371
424
defaultTasks = [' prebuild' , ' build' , ' postbuild' ]
372
425
for (phase in defaultTasks) {
373
426
if (! tasks. findByName(phase)) {
0 commit comments