[fix] 修复Unity 2020的il2cpp在不同目录存在同名ThreadPool文件,导致偶发生成的同一个lump文件中包含这两个文件时,出现编译错误的问题。解决方式为给每个目录生成一个lump文件

main
walon 2023-09-03 21:03:01 +08:00
parent 22760c6c7c
commit 9cf8f19517
1 changed files with 8 additions and 11 deletions

View File

@ -5,6 +5,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using UnityEditor; using UnityEditor;
using System.Reflection;
#if (UNITY_2020 || UNITY_2021) && UNITY_IOS #if (UNITY_2020 || UNITY_2021) && UNITY_IOS
using UnityEditor.Build; using UnityEditor.Build;
using UnityEditor.Callbacks; using UnityEditor.Callbacks;
@ -199,24 +200,20 @@ namespace HybridCLR.Editor
private static List<LumpFile> CreateLumps(string libil2cppDir, string outputDir) private static List<LumpFile> CreateLumps(string libil2cppDir, string outputDir)
{ {
BashUtil.RecreateDir(outputDir); BashUtil.RecreateDir(outputDir);
var cppFiles = Directory.GetFiles(libil2cppDir, "*.cpp", SearchOption.AllDirectories);
int maxCppFilePerLump = 50;
string il2cppConfigFile = $"{libil2cppDir}/il2cpp-config.h"; string il2cppConfigFile = $"{libil2cppDir}/il2cpp-config.h";
var lumpFiles = new List<LumpFile>(); var lumpFiles = new List<LumpFile>();
for (int i = 0; i < (cppFiles.Length + maxCppFilePerLump - 1) / maxCppFilePerLump; i++) int lumpFileIndex = 0;
foreach (var cppDir in Directory.GetDirectories(libil2cppDir, "*", SearchOption.AllDirectories).Concat(new string[] {libil2cppDir}))
{ {
var lumpFile = new LumpFile($"{outputDir}/lump_{i}.cpp", il2cppConfigFile); var lumpFile = new LumpFile($"{outputDir}/lump_{Path.GetFileName(cppDir)}_{lumpFileIndex}.cpp", il2cppConfigFile);
for (int j = 0; j < maxCppFilePerLump; j++) foreach (var file in Directory.GetFiles(cppDir, "*.cpp", SearchOption.TopDirectoryOnly))
{ {
int index = i * maxCppFilePerLump + j; lumpFile.cppFiles.Add(file);
if (index >= cppFiles.Length)
{
break;
}
lumpFile.cppFiles.Add(cppFiles[index]);
} }
lumpFile.SaveFile(); lumpFile.SaveFile();
lumpFiles.Add(lumpFile); lumpFiles.Add(lumpFile);
++lumpFileIndex;
} }
var mmFiles = Directory.GetFiles(libil2cppDir, "*.mm", SearchOption.AllDirectories); var mmFiles = Directory.GetFiles(libil2cppDir, "*.mm", SearchOption.AllDirectories);