Skip to content

Commit e1578f9

Browse files
committed
Updating build script to use Unity distro only.
This is done to facilitate CI builds. This removes the Dockerfile and monodevelop build environment. Introduced properties in the csproj files that are used to define the directory for the Unity and NUnit assemblies. These are set in the build.gradle file by searching the paths in Unity. If you are building the solution outside the gradle script, you'll need to update the hints manually in the IDE. Change-Id: I1282dcf50c0efdee2e69df04ab207bf1f1f67966
1 parent cbcb21c commit e1578f9

File tree

8 files changed

+165
-133
lines changed

8 files changed

+165
-133
lines changed

Diff for: Dockerfile

-24
This file was deleted.

Diff for: build.gradle

+125-92
Original file line numberDiff line numberDiff line change
@@ -45,84 +45,74 @@ project.ext {
4545
'may fail.')
4646
}
4747

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;
6457
}
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.')
7758
}
7859

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")
11471
}
11572

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")
12088
}
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")
123101
}
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")
126116
}
127117

128118
pluginSrc = file('plugin').absolutePath
@@ -140,27 +130,52 @@ project.ext {
140130
task compile_resolverTests(type: Exec) {
141131
description 'Compile the tests for the Mono framework component.'
142132
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'
145136
}
146137

147138
task test_resolverLib(type: Exec, dependsOn: compile_resolverTests) {
148139
description 'Runs the tests.'
149140
workingDir 'source'
150141
commandLine "nunit-console",
151142
"JarResolverTests/bin/Debug/JarResolverTests.dll"
152-
ext.remoteTaskPhase = 'prebuild'
143+
ext.remoteTaskPhase = 'build'
153144
}
154145

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+
}
164179
}
165180

166181
// Construct the name of a versioned asset from the source filename and version
@@ -190,11 +205,15 @@ def build_pluginDll(projectName, assemblyDllBasename) {
190205

191206
def compileTask = tasks.create(name: "compile_" + projectName,
192207
type: Exec,
193-
description: 'Compile ' + projectName,
194-
dependsOn: [copy_unityDlls])
208+
description: 'Compile ' + projectName
209+
)
195210
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"
198217
def assemblyDllSource = file("source/" + projectName + "/bin/Debug/" +
199218
assemblyDllBasename)
200219

@@ -218,7 +237,7 @@ def build_pluginDll(projectName, assemblyDllBasename) {
218237
}
219238
return fn
220239
})
221-
copyTask.ext.remoteTaskPhase = "prebuild"
240+
copyTask.ext.remoteTaskPhase = "build"
222241
}
223242

224243
build_pluginDll("PlayServicesResolver", "Google.JarResolver.dll")
@@ -249,15 +268,15 @@ task copy_pluginTemplate(type: Copy, dependsOn: update_metadataForVersion) {
249268
into "${pluginProj}"
250269
exclude '**/*.dll.*', '**/*.txt.meta'
251270
duplicatesStrategy 'include'
252-
ext.remoteTaskPhase = 'prebuild'
271+
ext.remoteTaskPhase = 'build'
253272
}
254273

255274
task inject_versionIntoMetaFiles(dependsOn: [copy_pluginTemplate,
256275
'copy_PlayServicesResolver',
257276
'copy_VersionHandler',
258277
'copy_IOSResolver']) {
259278
description 'Inject the version number into the plugin\'s meta files.'
260-
ext.remoteTaskPhase = 'prebuild'
279+
ext.remoteTaskPhase = 'build'
261280
doLast {
262281
for (fileobj in fileTree("${pluginProj}")) {
263282
if (fileobj.path.endsWith('.meta')) {
@@ -309,7 +328,7 @@ task generate_manifest(dependsOn: ['copy_manifestMetadata',
309328
"${pluginVersion}"))
310329
manifest.write(list.join('\n') + '\n')
311330
}
312-
ext.remoteTaskPhase = 'prebuild'
331+
ext.remoteTaskPhase = 'build'
313332
}
314333

315334
task export_package(dependsOn: 'generate_manifest') {
@@ -335,7 +354,7 @@ task export_package(dependsOn: 'generate_manifest') {
335354
ext.remoteTaskPhase = 'build'
336355
}
337356

338-
task copy_plugin(dependsOn: 'export_package') {
357+
task copy_plugin() {
339358
description 'Copy plugin to the current-build directory'
340359
doFirst {
341360
// If the version number has been bumped delete the exploded directory.
@@ -368,6 +387,20 @@ task build_unityPackage(dependsOn: 'copy_plugin') {
368387
}
369388
}
370389

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+
371404
defaultTasks = ['prebuild', 'build', 'postbuild']
372405
for (phase in defaultTasks) {
373406
if (!tasks.findByName(phase)) {

Diff for: gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.3-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

Diff for: source/IOSResolver/IOSResolver.csproj

+12-5
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,25 @@
3030
<WarningLevel>4</WarningLevel>
3131
<ConsolePause>False</ConsolePause>
3232
</PropertyGroup>
33+
<PropertyGroup>
34+
<UnityHintPath>..\..\unity_dlls</UnityHintPath>
35+
<UnityIosPath>..\..\unity_dlls</UnityIosPath>
36+
</PropertyGroup>
3337
<ItemGroup>
3438
<Reference Include="UnityEditor">
35-
<HintPath>..\..\unity_dlls\UnityEditor.dll</HintPath>
39+
<HintPath>$(UnityHintPath)/UnityEditor.dll</HintPath>
3640
</Reference>
3741
<Reference Include="UnityEngine">
38-
<HintPath>..\..\unity_dlls\UnityEngine.dll</HintPath>
42+
<HintPath>$(UnityHintPath)/UnityEngine.dll</HintPath>
43+
</Reference>
44+
<Reference Include="Unity.UNetWeaver">
45+
<HintPath>$(UnityHintPath)/Unity.UNetWeaver.dll</HintPath>
3946
</Reference>
40-
<Reference Include="System" />
41-
<Reference Include="System.Xml" />
4247
<Reference Include="UnityEditor.iOS.Extensions.Xcode">
43-
<HintPath>..\..\unity_dlls\UnityEditor.iOS.Extensions.Xcode.dll</HintPath>
48+
<HintPath>$(UnityIosPath)/UnityEditor.iOS.Extensions.Xcode.dll</HintPath>
4449
</Reference>
50+
<Reference Include="System" />
51+
<Reference Include="System.Xml" />
4552
</ItemGroup>
4653
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
4754
<ItemGroup>

Diff for: source/JarResolverLib/JarResolverLib.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<ItemGroup>
3434
<Reference Include="System" />
3535
<Reference Include="System.Xml" />
36+
<Reference Include="System.Core" />
3637
</ItemGroup>
3738
<ItemGroup>
3839
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -54,4 +55,4 @@
5455
</Properties>
5556
</MonoDevelop>
5657
</ProjectExtensions>
57-
</Project>
58+
</Project>

0 commit comments

Comments
 (0)