Skip to content

Commit ee59fff

Browse files
author
Stewart Miles
committed
Fixed compilation when using Mono 5 or above.
Unity 2019.x and later ship with Mono 5.x which generate .pdb rather than .dll.mdb symbol files. This modifies the build and packaging process to support processing .pdb files when Mono 5.x is detected. Change-Id: I40a6956d7fcdca4e30a80d76921a1f16f8855098
1 parent e5b12e0 commit ee59fff

File tree

7 files changed

+167
-53
lines changed

7 files changed

+167
-53
lines changed

build.gradle

Lines changed: 102 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ project.ext {
112112
"XBUILD_EXE", false, {
113113
unityRootDirTree.matching {
114114
include (operatingSystem == OperatingSystem.WINDOWS ?
115-
"**/Mono/bin/xbuild.bat" : "**/xbuild")
115+
"**/bin/xbuild.bat" : "**/xbuild")
116116
exclude unitySearchDirExcludes
117117
}
118118
})
@@ -121,6 +121,51 @@ project.ext {
121121
}
122122
saveProperty("XBUILD_EXE", xbuildExe, cacheProperties)
123123

124+
// Find mono to determine the distribution being used.
125+
monoExe = getFileFromPropertyOrFileTree(
126+
"MONO_EXE", false, {
127+
unityRootDirTree.matching {
128+
include (operatingSystem == OperatingSystem.WINDOWS ?
129+
"**/bin/mono.bat" : "**/bin/mono")
130+
exclude unitySearchDirExcludes
131+
}
132+
})
133+
saveProperty("MONO_EXE", monoExe, cacheProperties)
134+
135+
// Get the mono distribution version.
136+
def versionRegEx = /^.* version ([^ ]+) .*/
137+
def stdout = new ByteArrayOutputStream()
138+
exec {
139+
commandLine monoExe, "-V"
140+
ignoreExitValue true
141+
standardOutput = stdout
142+
}
143+
def monoVersionList =
144+
stdout.toString().replace("\r\n", "\n").tokenize("\n").findResults {
145+
def versionMatch = it =~ versionRegEx
146+
if (versionMatch.matches()) {
147+
return versionMatch.group(1)
148+
}
149+
return null
150+
}
151+
if (!monoVersionList) {
152+
throw new StopActionException(
153+
sprintf("Unable to determine mono version from %s", monoExe))
154+
}
155+
monoVersion = monoVersionList[0]
156+
157+
// Mono 5.x and above generate .pdb files that are compatible with visual
158+
// studio as opposed to the mono-specific .pdb files.
159+
pdbSupported = monoVersion.tokenize(".")[0].toInteger() >= 5
160+
161+
if (pdbSupported) {
162+
logger.warn(
163+
sprintf("Mono %s detected which will generate .pdb files " +
164+
"that are not compatible with older versions of Unity. " +
165+
"This can be fixed by compiling with Unity 5.6.",
166+
monoVersion))
167+
}
168+
124169
// Find the NUnit framework dll.
125170
unityNUnitDll = getFileFromPropertyOrFileTree(
126171
"UNITY_NUNIT_PATH", true, {
@@ -139,7 +184,7 @@ project.ext {
139184
"NUNIT_CONSOLE_EXE", false, {
140185
unityRootDirTree.matching {
141186
include (operatingSystem == OperatingSystem.WINDOWS ?
142-
"**/Mono/bin/nunit-console2.bat" :
187+
"**/bin/nunit-console2.bat" :
143188
"**/nunit-console2")
144189
exclude unitySearchDirExcludes
145190
}
@@ -170,7 +215,7 @@ project.ext {
170215
unityPackagePath = findFileProperty("UNITY_PACKAGE_PATH", null)
171216

172217
// Whether debug symbols should be included.
173-
debugEnabled = findProperty("NDEBUG") == null
218+
debugEnabled = true
174219

175220
// Whether interactive mode tests are enabled.
176221
interactiveModeTestsEnabled =
@@ -231,8 +276,8 @@ project.ext {
231276
unityInteractiveModeArguments = ["-gvh_noninteractive"]
232277
// Extension for Unity asset metadata files.
233278
unityMetadataExtension = ".meta"
234-
// Extension for debug files.
235-
dllMdbExtension = ".mdb"
279+
// Extensions for debug files.
280+
symbolDatabaseExtension = pdbSupported ? ".pdb" : ".dll.mdb"
236281
// Changelog file.
237282
changelog = new File(scriptDirectory, "CHANGELOG.md")
238283
pythonBootstrapDir = new File(buildDir, "python_bootstrap")
@@ -414,8 +459,8 @@ void checkNUnitConsolePath() {
414459
List<String> splitFilenameExtension(File fileObj) {
415460
String filename = fileObj.name
416461
int extensionIndex =
417-
(filename - project.ext.unityMetadataExtension -
418-
project.ext.dllMdbExtension).lastIndexOf(".")
462+
(filename - project.ext.symbolDatabaseExtension -
463+
project.ext.unityMetadataExtension).lastIndexOf(".")
419464
if (extensionIndex < 0) return [filename, ""]
420465
String basename = filename.substring(0, extensionIndex)
421466
String extension = filename.substring(extensionIndex)
@@ -554,7 +599,7 @@ File copyAssetMetadataFile(File sourceFile, File targetFile) {
554599
if (!sourceFile.name.endsWith(project.ext.unityMetadataExtension)) {
555600
return copyFile(sourceFile, targetFile)
556601
}
557-
String[] lines = sourceFile.text.split("\n")
602+
String[] lines = sourceFile.text.tokenize("\n")
558603

559604
// Parse the existing version from the asset metadata.
560605
def folderAssetRegEx = /^folderAsset:\s+yes\s*$/
@@ -639,7 +684,18 @@ Task createXbuildTask(String taskName, String taskDescription,
639684
Iterable<File> outputFilesInBinaryOutputDir = outputFiles.collect {
640685
return new File(binaryOutputDir, it.path)
641686
}
687+
688+
if (project.ext.debugEnabled) {
689+
outputFilesInBinaryOutputDir += outputFilesInBinaryOutputDir.findResults {
690+
return it.name.endsWith(".dll") ?
691+
new File(it.parentFile.path,
692+
splitFilenameExtension(it)[0] +
693+
project.ext.symbolDatabaseExtension) : null
694+
}
695+
}
696+
642697
Iterable<Task> dependsOnTasks = dependsOn ? dependsOn : []
698+
Iterable<Task> compileTaskDependencies = dependsOnTasks.clone()
643699
Iterable<Task> patchVersionFilesTasks = inputFiles.findResults {
644700
if (it.name == "VersionNumber.cs") {
645701
File versionFile = it
@@ -668,12 +724,14 @@ Task createXbuildTask(String taskName, String taskDescription,
668724
return patchVersionTask
669725
}
670726
}
727+
if (patchVersionFilesTasks) {
728+
compileTaskDependencies += patchVersionFilesTasks
729+
}
730+
671731
Task task = tasks.create(name: taskName,
672732
description: taskDescription,
673733
type: Exec,
674-
dependsOn: patchVersionFilesTasks ?
675-
patchVersionFilesTasks :
676-
dependsOnTasks).with {
734+
dependsOn: compileTaskDependencies).with {
677735
inputs.files inputFiles
678736
outputs.files files(outputFilesInBinaryOutputDir)
679737
executable project.ext.xbuildExe
@@ -723,25 +781,21 @@ Task createBuildPluginDllTask(String componentName,
723781
File projectDir = new File(project.ext.pluginSourceDir, projectName)
724782
File projectBuildDir = new File(project.ext.buildDir, projectName)
725783

726-
List<File> buildFiles = [new File(assemblyDllBasename)]
727-
if (project.ext.debugEnabled) {
728-
buildFiles += [new File(assemblyDllBasename + project.ext.dllMdbExtension)]
729-
}
730-
731784
// Compile the C# project.
732785
Task compileTask = createXbuildTask(
733786
sprintf("compile%s", componentName), sprintf("Compile %s", projectName),
734787
project.ext.pluginSolutionFile, projectName,
735788
fileTree(new File(projectDir, "src")), projectBuildDir,
736-
buildFiles, dependsOn)
789+
[new File(assemblyDllBasename)], dependsOn)
737790
compileTask.ext.componentName = componentName
738791

739792
// Template metadata for the built DLL.
740-
Iterable<File> assemblyDllMetaFiles = buildFiles.collect {
741-
new File(new File(project.ext.pluginTemplateDir,
742-
project.ext.pluginEditorDllDir.path),
743-
it.name + project.ext.unityMetadataExtension)
744-
}
793+
Iterable<File> assemblyDllMetaFiles =
794+
compileTask.outputs.files.collect {
795+
new File(new File(project.ext.pluginTemplateDir,
796+
project.ext.pluginEditorDllDir.path),
797+
it.name + project.ext.unityMetadataExtension)
798+
}
745799
// Optionally map unversioned to versioned filenames.
746800
Iterable<File> unversionedFiles = files(compileTask.outputs.files,
747801
assemblyDllMetaFiles)
@@ -942,7 +996,6 @@ Task createUnityTask(String taskName, String summary,
942996
executeArguments)
943997
}
944998
unityTask.with {
945-
inputs.files fileTree(projectDir)
946999
outputs.files files(logFile)
9471000
}
9481001
unityTask.ext.projectDir = projectDir
@@ -1030,22 +1083,32 @@ Task createUnityTestTask(String taskName, String description,
10301083
Iterable<File> editorAssets,
10311084
Iterable<String> additionalArguments,
10321085
Boolean batchMode, createTaskClosure) {
1033-
List<File> inputFiles = fileTree(testScriptsDir).collect {
1034-
new File(it.absolutePath - testScriptsDir.absolutePath)
1086+
List<File> testScripts = []
1087+
if (testScriptsDir) {
1088+
testScripts = fileTree(testScriptsDir).collect {
1089+
new File(it.absolutePath.substring(
1090+
testScriptsDir.absolutePath.length() + 1))
1091+
}
10351092
}
1093+
10361094
// Setup the Unity project.
10371095
Task setupTestProject = createSetupUnityProjectTask(
10381096
sprintf("setup%s", taskName), dependsOn, taskName, batchMode)
10391097
setupTestProject.with {
1040-
inputs.files inputFiles
1098+
inputs.files (testScripts + editorAssets)
10411099
}
10421100

1101+
List<Task> copyTasks = []
1102+
10431103
// Task which copies test scripts into the project.
1044-
Task copyTestScripts = createCopyFilesTask(
1045-
sprintf("copyScriptsFor%s", taskName),
1046-
sprintf("Copy the test scripts into the %s Unity project.", taskName),
1047-
inputFiles, testScriptsDir, setupTestProject.ext.projectDir,
1048-
[setupTestProject], null)
1104+
if (testScriptsDir) {
1105+
Task copyTestScripts = createCopyFilesTask(
1106+
sprintf("copyScriptsFor%s", taskName),
1107+
sprintf("Copy the test scripts into the %s Unity project.", taskName),
1108+
testScripts, testScriptsDir, setupTestProject.ext.projectDir,
1109+
[setupTestProject], null)
1110+
copyTasks += [copyTestScripts]
1111+
}
10491112

10501113
// Task which copies editor scripts into the project.
10511114
Task copyEditorAssets = tasks.create(
@@ -1059,10 +1122,11 @@ Task createUnityTestTask(String taskName, String description,
10591122
into new File(new File(setupTestProject.ext.projectDir, "Assets"),
10601123
"Editor")
10611124
}
1125+
copyTasks += [copyEditorAssets]
10621126

10631127
// Create the test task.
10641128
Task testTask = createUnityTask(taskName, "test",
1065-
[copyTestScripts, copyEditorAssets],
1129+
copyTasks,
10661130
setupTestProject.ext.projectDir.name,
10671131
setupTestProject.ext.containerDir,
10681132
additionalArguments, batchMode,
@@ -1124,8 +1188,7 @@ Task compileResolverLibTests = createXbuildTask(
11241188
fileTree(new File(new File(project.ext.pluginSourceDir,
11251189
"JarResolverLib"), "src")),
11261190
new File(project.ext.testDir, "ResolverLibTests"),
1127-
[new File("JarResolverTests.dll"),
1128-
new File("JarResolverTests.dll.mdb")], []).with {
1191+
[new File("JarResolverTests.dll")], []).with {
11291192
doFirst { checkNUnitDllPath() }
11301193
}
11311194

@@ -1546,7 +1609,7 @@ task gitAddReleaseFilesToStaging(type: Exec, dependsOn: releasePlugin) {
15461609
*/
15471610
String readVersionSummaryFromChangelog() {
15481611
String versionSummary = ""
1549-
for (String line in project.ext.changelog.text.split("\n")) {
1612+
for (String line in project.ext.changelog.text.tokenize("\n")) {
15501613
String trimmedLine = line.trim()
15511614
if (line.isEmpty()) break
15521615
versionSummary += line + "\n"
@@ -1631,8 +1694,7 @@ Task compileVersionHandlerImplTests = createXbuildTask(
16311694
"unit_tests"),
16321695
"src")),
16331696
new File(project.ext.testDir, "VersionHandlerImplTests"),
1634-
[new File("Google.VersionHandlerImplTests.dll"),
1635-
new File("Google.VersionHandlerImplTests.dll.mdb")], []).with {
1697+
[new File("Google.VersionHandlerImplTests.dll")], []).with {
16361698
doFirst { checkNUnitDllPath() }
16371699
}
16381700

@@ -1653,8 +1715,7 @@ Task compileUnityPackageManagerResolverTests = createXbuildTask(
16531715
"unit_tests"),
16541716
"src")),
16551717
new File(project.ext.testDir, "UnityPackageManagerResolverTests"),
1656-
[new File("Google.UnityPackageManagerResolverTests.dll"),
1657-
new File("Google.UnityPackageManagerResolverTests.dll.mdb")],
1718+
[new File("Google.UnityPackageManagerResolverTests.dll")],
16581719
[buildUnityPackageManagerResolver]).with {
16591720
doFirst { checkNUnitDllPath() }
16601721
}
@@ -1717,8 +1778,7 @@ Task compileIntegrationTester = createXbuildTask(
17171778
fileTree(new File(project.ext.pluginSourceDir,
17181779
"IntegrationTester")),
17191780
new File(project.ext.buildDir, "IntegrationTester"),
1720-
[new File("Google.IntegrationTester.dll"),
1721-
new File("Google.IntegrationTester.dll.mdb")],
1781+
[new File("Google.IntegrationTester.dll")],
17221782
[compileVersionHandler])
17231783

17241784
/*
@@ -1775,8 +1835,7 @@ createUnityIntegrationTest(
17751835
"AndroidResolverIntegrationTests",
17761836
fileTree(new File(new File(project.ext.pluginSourceDir, "AndroidResolver"),
17771837
"test")),
1778-
[new File("Google.AndroidResolverIntegrationTests.dll"),
1779-
new File("Google.AndroidResolverIntegrationTests.dll.mdb")],
1838+
[new File("Google.AndroidResolverIntegrationTests.dll")],
17801839
new File(
17811840
project.ext.scriptDirectory,
17821841
"source/AndroidResolver/test/AndroidResolverIntegrationTestsUnityProject"),

export_unity_package_config.json

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,18 @@
77
"importer": "PluginImporter",
88
"platforms": ["Editor"],
99
"paths": [
10-
"ExternalDependencyManager/Editor/Google.VersionHandler.dll",
11-
"ExternalDependencyManager/Editor/Google.VersionHandler.dll.mdb"
10+
"ExternalDependencyManager/Editor/Google.VersionHandler.*"
1211
]
1312
},
1413
{
1514
"importer": "PluginImporter",
1615
"platforms": [],
1716
"labels": ["gvhp_targets-editor"],
1817
"paths": [
19-
"ExternalDependencyManager/Editor/Google.IOSResolver_*.dll",
20-
"ExternalDependencyManager/Editor/Google.IOSResolver_*.dll.mdb",
21-
"ExternalDependencyManager/Editor/Google.JarResolver_*.dll",
22-
"ExternalDependencyManager/Editor/Google.JarResolver_*.dll.mdb",
23-
"ExternalDependencyManager/Editor/Google.VersionHandlerImpl_*.dll",
24-
"ExternalDependencyManager/Editor/Google.VersionHandlerImpl_*.dll.mdb",
25-
"ExternalDependencyManager/Editor/Google.UnityPackageManagerResolver_*.dll",
26-
"ExternalDependencyManager/Editor/Google.UnityPackageManagerResolver_*.dll.mdb"
18+
"ExternalDependencyManager/Editor/Google.IOSResolver_*.*",
19+
"ExternalDependencyManager/Editor/Google.JarResolver_*.*",
20+
"ExternalDependencyManager/Editor/Google.VersionHandlerImpl_*.*",
21+
"ExternalDependencyManager/Editor/Google.UnityPackageManagerResolver_*.*"
2722
],
2823
"override_metadata_upm": {
2924
"PluginImporter": {

plugin/Assets/ExternalDependencyManager/Editor/Google.IOSResolver.pdb.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin/Assets/ExternalDependencyManager/Editor/Google.JarResolver.pdb.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin/Assets/ExternalDependencyManager/Editor/Google.UnityPackageManagerResolver.pdb.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin/Assets/ExternalDependencyManager/Editor/Google.VersionHandler.pdb.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin/Assets/ExternalDependencyManager/Editor/Google.VersionHandlerImpl.pdb.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)