@@ -45,84 +45,74 @@ 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
- }
75
- if (unity_dll_path_file == null || ! unity_dll_path_file. exists()) {
76
- logger. error(' Unity DLLs not found, plug-in build will fail.' )
77
58
}
78
59
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
- }
109
- }
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.' )
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 " )
114
71
}
115
72
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" )
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 " )
120
88
}
121
- if (xbuild_exe == null || xbuild_exe. isEmpty()) {
122
- xbuild_exe = ' xbuild'
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 " )
123
101
}
124
- if (! (new File (xbuild_exe)). exists()) {
125
- logger. warn(' xbuild not found, plug-in build may fail.' )
102
+
103
+
104
+ // xbuild is used to build the dlls.
105
+ xbuild_exe = findUnityPath(" XBUILD_EXE" , false ,
106
+ os_windows ?
107
+ fileTree(dir : unity_root). matching { include ' **/Mono/bin/xbuild.bat' }
108
+ :
109
+ fileTree(dir : unity_root). matching { include ' **/Mono/bin/xbuild' }
110
+ )
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 " )
126
116
}
127
117
128
118
pluginSrc = file(' plugin' ). absolutePath
@@ -140,27 +130,52 @@ project.ext {
140
130
task compile_resolverTests (type : Exec ) {
141
131
description ' Compile the tests for the Mono framework component.'
142
132
workingDir ' source'
143
- commandLine " ${ xbuild_exe} " , ' /target:JarResolverTests'
144
- ext. remoteTaskPhase = ' prebuild'
133
+ commandLine " ${ xbuild_exe} " , ' /target:JarResolverTests' ,
134
+ " /property:NUnityHintPath=$unity_nunit_dll_path . absolutePath "
135
+ ext. remoteTaskPhase = ' build'
145
136
}
146
137
147
138
task test_resolverLib (type : Exec , dependsOn : compile_resolverTests) {
148
139
description ' Runs the tests.'
149
140
workingDir ' source'
150
141
commandLine " nunit-console" ,
151
142
" JarResolverTests/bin/Debug/JarResolverTests.dll"
152
- ext. remoteTaskPhase = ' prebuild '
143
+ ext. remoteTaskPhase = ' build '
153
144
}
154
145
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'
146
+ // / find paths within the Unity file tree used for building.
147
+ def findUnityPath (propertyKey , wantDirectory , fileTree ) {
148
+
149
+ def propValue;
150
+ def fileValue;
151
+
152
+ propValue = System . getProperty(propertyKey)
153
+ if (propValue == null || propValue. isEmpty()) {
154
+ propValue = System . getenv(propertyKey)
155
+ }
156
+ // convert string to file object
157
+ if (propValue != null ) {
158
+ fileValue = file(propValue)
159
+ } else {
160
+ fileValue = null
161
+ }
162
+
163
+ if (fileValue == null || ! fileValue. exists()) {
164
+ // take the shortest path location.
165
+ fileValue = null
166
+ fileTree. files. each { p ->
167
+ if (fileValue == null ||
168
+ fileValue. absolutePath. length() > p. absolutePath. length()) {
169
+ fileValue = p;
170
+ }
171
+ }
172
+ }
173
+
174
+ if (wantDirectory) {
175
+ return fileValue != null ? fileValue. parentFile : null ;
176
+ } else {
177
+ return fileValue
178
+ }
164
179
}
165
180
166
181
// Construct the name of a versioned asset from the source filename and version
@@ -190,11 +205,15 @@ def build_pluginDll(projectName, assemblyDllBasename) {
190
205
191
206
def compileTask = tasks. create(name : " compile_" + projectName,
192
207
type : Exec ,
193
- description : ' Compile ' + projectName,
194
- dependsOn : [copy_unityDlls] )
208
+ description : ' Compile ' + projectName
209
+ )
195
210
compileTask. workingDir(' source' )
196
- compileTask. commandLine([" ${ xbuild_exe} " , " /target:" + projectName])
197
- compileTask. ext. remoteTaskPhase = " prebuild"
211
+ compileTask. commandLine([" ${ xbuild_exe} " , " /target:" + projectName,
212
+ " /property:UnityHintPath=$unity_dll_path . absolutePath " ,
213
+ " /property:UnityIosPath=$unity_ios_dll_path . absolutePath "
214
+ ])
215
+
216
+ compileTask. ext. remoteTaskPhase = " build"
198
217
def assemblyDllSource = file(" source/" + projectName + " /bin/Debug/" +
199
218
assemblyDllBasename)
200
219
@@ -218,7 +237,7 @@ def build_pluginDll(projectName, assemblyDllBasename) {
218
237
}
219
238
return fn
220
239
})
221
- copyTask. ext. remoteTaskPhase = " prebuild "
240
+ copyTask. ext. remoteTaskPhase = " build "
222
241
}
223
242
224
243
build_pluginDll(" PlayServicesResolver" , " Google.JarResolver.dll" )
@@ -249,15 +268,15 @@ task copy_pluginTemplate(type: Copy, dependsOn: update_metadataForVersion) {
249
268
into " ${ pluginProj} "
250
269
exclude ' **/*.dll.*' , ' **/*.txt.meta'
251
270
duplicatesStrategy ' include'
252
- ext. remoteTaskPhase = ' prebuild '
271
+ ext. remoteTaskPhase = ' build '
253
272
}
254
273
255
274
task inject_versionIntoMetaFiles (dependsOn : [copy_pluginTemplate,
256
275
' copy_PlayServicesResolver' ,
257
276
' copy_VersionHandler' ,
258
277
' copy_IOSResolver' ]) {
259
278
description ' Inject the version number into the plugin\' s meta files.'
260
- ext. remoteTaskPhase = ' prebuild '
279
+ ext. remoteTaskPhase = ' build '
261
280
doLast {
262
281
for (fileobj in fileTree(" ${ pluginProj} " )) {
263
282
if (fileobj. path. endsWith(' .meta' )) {
@@ -309,7 +328,7 @@ task generate_manifest(dependsOn: ['copy_manifestMetadata',
309
328
" ${ pluginVersion} " ))
310
329
manifest. write(list. join(' \n ' ) + ' \n ' )
311
330
}
312
- ext. remoteTaskPhase = ' prebuild '
331
+ ext. remoteTaskPhase = ' build '
313
332
}
314
333
315
334
task export_package (dependsOn : ' generate_manifest' ) {
@@ -335,7 +354,7 @@ task export_package(dependsOn: 'generate_manifest') {
335
354
ext. remoteTaskPhase = ' build'
336
355
}
337
356
338
- task copy_plugin (dependsOn : ' export_package ' ) {
357
+ task copy_plugin () {
339
358
description ' Copy plugin to the current-build directory'
340
359
doFirst {
341
360
// If the version number has been bumped delete the exploded directory.
@@ -368,6 +387,20 @@ task build_unityPackage(dependsOn: 'copy_plugin') {
368
387
}
369
388
}
370
389
390
+ task clean () {
391
+ doFirst {
392
+ delete ' build'
393
+ file(" source" ). listFiles(). each { f ->
394
+ if (file(" $f /obj" ). exists()) {
395
+ delete " $f /obj"
396
+ }
397
+ if (file(" $f /bin" ). exists()) {
398
+ delete " $f /bin"
399
+ }
400
+ }
401
+ }
402
+ }
403
+
371
404
defaultTasks = [' prebuild' , ' build' , ' postbuild' ]
372
405
for (phase in defaultTasks) {
373
406
if (! tasks. findByName(phase)) {
0 commit comments