[fix] 修复当Append xcode项目到现存的xcode项目时,第1次会导致'Run Script'命令被重复追加,从第2次起将会找不到--external-lib-il2-cpp而打印错误日志的bug

main
walon 2024-05-14 21:59:56 +08:00
parent f935127cd3
commit 97dae7fed2
1 changed files with 16 additions and 6 deletions

View File

@ -37,16 +37,26 @@ namespace HybridCLR.Editor.BuildProcessors
{ {
string pbxprojContent = File.ReadAllText(pbxprojFile, Encoding.UTF8); string pbxprojContent = File.ReadAllText(pbxprojFile, Encoding.UTF8);
string removeBuildOption = @"--external-lib-il2-cpp=\""$PROJECT_DIR/Libraries/libil2cpp.a\"""; string removeBuildOption = @"--external-lib-il2-cpp=\""$PROJECT_DIR/Libraries/libil2cpp.a\""";
if (!pbxprojContent.Contains(removeBuildOption)) if (pbxprojContent.Contains(removeBuildOption))
{ {
//throw new BuildFailedException("modified project.pbxproj fail");
Debug.LogError("[AddLil2cppSourceCodeToXcodeproj] modified project.pbxproj fail");
return;
}
pbxprojContent = pbxprojContent.Replace(removeBuildOption, ""); pbxprojContent = pbxprojContent.Replace(removeBuildOption, "");
File.WriteAllText(pbxprojFile, pbxprojContent, Encoding.UTF8);
Debug.Log($"[AddLil2cppSourceCodeToXcodeproj] remove il2cpp build option '{removeBuildOption}' from file '{pbxprojFile}'"); Debug.Log($"[AddLil2cppSourceCodeToXcodeproj] remove il2cpp build option '{removeBuildOption}' from file '{pbxprojFile}'");
} }
else
{
Debug.LogWarning($"[AddLil2cppSourceCodeToXcodeproj] project.pbxproj remove building option:'{removeBuildOption}' fail. This may occur when 'Append' to existing xcode project in building");
}
int strShellScriptIndex1 = pbxprojContent.IndexOf("/* ShellScript */,");
int strShellScriptIndex2 = pbxprojContent.IndexOf("/* ShellScript */,", strShellScriptIndex1 + 10);
if (strShellScriptIndex2 >= 0)
{
pbxprojContent = pbxprojContent.Remove(strShellScriptIndex1, strShellScriptIndex2 - strShellScriptIndex1);
Debug.LogWarning($"[AddLil2cppSourceCodeToXcodeproj] remove duplicated '/* ShellScript */' from file '{pbxprojFile}'");
}
File.WriteAllText(pbxprojFile, pbxprojContent, Encoding.UTF8);
}
private static void CopyLibil2cppToXcodeProj(string pathToBuiltProject) private static void CopyLibil2cppToXcodeProj(string pathToBuiltProject)
{ {