Nessuna descrizione
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

setupSymbols.gradle 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Defines logic for:
  2. // - embedding symbols_table/debug symbols into the bundle.
  3. // - for creating symbols zip with files having .so extension
  4. // UnityLibrary has to be evaluated first, so we could find buildIl2Cpp task
  5. evaluationDependsOn(':unityLibrary')
  6. def insertCopyInfo(Hashtable<String, String> map,
  7. String targetDirectory,
  8. String extension,
  9. File sourceFile) {
  10. def abi = sourceFile.getParentFile().getName();
  11. def fileName = sourceFile.getName();
  12. def targetAbi = file(targetDirectory).toPath().resolve(abi)
  13. def dst = targetAbi.resolve(fileName + extension).toString()
  14. map.put(sourceFile.getAbsolutePath(), dst)
  15. }
  16. def constructCopyInfoForUnitySymbols(Project unityLibrary, String targetDirectory, String extension, Task buildIl2CppTask) {
  17. def unityLibraryRoot = unityLibrary.projectDir.toPath()
  18. def unitySymbols = unityLibraryRoot.resolve('symbols')
  19. // Note: libil2cpp.so might not yet exist, thus querying directory won't return libil2cpp.so
  20. def files = fileTree(unitySymbols)
  21. def result = new Hashtable<String, String>()
  22. for (File f: files) {
  23. insertCopyInfo(result, targetDirectory, extension, f)
  24. }
  25. if (buildIl2CppTask != null) {
  26. buildIl2CppTask.outputs.files.each { it ->
  27. String path = it.toString()
  28. if (!path.contains(unitySymbols.toString()))
  29. return;
  30. insertCopyInfo(result, targetDirectory, extension, it)
  31. }
  32. }
  33. return result
  34. }
  35. def setupSymbols(String configName, String symbolType, String extension) {
  36. def dependee = tasks.findByName("extract${configName}Native${symbolType}");
  37. if (dependee == null)
  38. return;
  39. def unityLibrary = project(':unityLibrary')
  40. def buildIl2CppTask = unityLibrary.tasks.findByName('buildIl2Cpp')
  41. def copyTaskName = "copy${configName}Unity${symbolType}";
  42. def copyInfo = constructCopyInfoForUnitySymbols(unityLibrary, dependee.outputs.files.asPath, extension, buildIl2CppTask)
  43. def task = tasks.register(copyTaskName) {
  44. for (def c : copyInfo)
  45. {
  46. inputs.file c.key
  47. outputs.file c.value
  48. }
  49. doLast {
  50. def rootIdx = projectDir.getParent().toString().length() + 1;
  51. println "Copying Unity symbols: "
  52. for (def c : copyInfo) {
  53. println " ${c.key.substring(rootIdx)} -> ${c.value.substring(rootIdx)}"
  54. ant.copy(tofile: c.value, file: c.key)
  55. }
  56. }
  57. }
  58. if (buildIl2CppTask != null)
  59. task.get().dependsOn buildIl2CppTask
  60. // 'copy{configName}Unity{symbolType}' must be executed after 'extract${configName}Native${symbolType}' task
  61. // In case 'extract${configName}Native${symbolType}' produces same files as 'copy{configName}Unity{symbolType}'
  62. dependee.finalizedBy copyTaskName
  63. // native-debug-symbols.zip depends on 'copy{configName}Unity{symbolType}' task
  64. def mergeNativeDebugMetadataTask = tasks.findByName("merge${configName}NativeDebugMetadata");
  65. if (mergeNativeDebugMetadataTask != null)
  66. mergeNativeDebugMetadataTask.dependsOn copyTaskName;
  67. // 'copy{configName}Unity{symbolType}' must be executed after 'package{configName}Bundle'
  68. def packageBundleTask = tasks.findByName("package${configName}Bundle");
  69. if (packageBundleTask != null)
  70. packageBundleTask.dependsOn copyTaskName;
  71. }
  72. def createMergeNativeDebugMetadataSoTask(String configName, String symbolType) {
  73. def extractNativeSymbols = tasks.findByName("extract${configName}Native${symbolType}");
  74. if (extractNativeSymbols == null)
  75. return;
  76. def copyUnitySymbolsTaskName = "copy${configName}Unity${symbolType}";
  77. def copyUnitySymbolsTask = tasks.findByName(copyUnitySymbolsTaskName);
  78. tasks.register("merge${configName}NativeDebugMetadataSo", Zip) {
  79. dependsOn extractNativeSymbols, copyUnitySymbolsTask
  80. from extractNativeSymbols.outputs.files.asPath
  81. archiveFileName = "native-debug-symbols-so.zip"
  82. destinationDirectory = file(tasks.findByName("merge${configName}NativeDebugMetadata").outputs.files.asPath).getParentFile()
  83. rename '(.*\\.so)(.*)', '$1'
  84. }
  85. }
  86. afterEvaluate {
  87. def dbgLevel = project.android.defaultConfig.ndk.debugSymbolLevel == null ?
  88. "none" :
  89. project.android.defaultConfig.ndk.debugSymbolLevel.toString().toLowerCase();
  90. if (dbgLevel.equals("none"))
  91. return;
  92. def symbolType = "SymbolTables";
  93. def symbolExt = ".sym";
  94. if (dbgLevel.equals("full"))
  95. {
  96. symbolType = "DebugMetadata";
  97. symbolExt = ".dbg";
  98. }
  99. android.buildTypes.configureEach { buildType ->
  100. // Turn 'debug' into 'Debug', 'release' into 'Release'
  101. var c = buildType.name.substring(0, 1).toUpperCase() + buildType.name.substring(1)
  102. setupSymbols(c, symbolType, symbolExt);
  103. createMergeNativeDebugMetadataSoTask(c, symbolType)
  104. }
  105. }