From 0b455eb88253554d2362bbffd92527435436f512 Mon Sep 17 00:00:00 2001 From: walon Date: Fri, 12 Jul 2024 09:18:57 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E4=BF=AE=E5=A4=8D=20Unity=202022?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E7=9A=84xcode=E5=B7=A5=E7=A8=8B=E5=8C=85?= =?UTF-8?q?=E5=90=AB=E5=A4=9A=E4=B8=AAShellScript=E7=89=87=E6=AE=B5?= =?UTF-8?q?=E6=97=B6=E9=94=99=E8=AF=AF=E5=9C=B0=E5=88=A0=E9=99=A4=E4=BA=86?= =?UTF-8?q?=E9=9D=9E=E9=87=8D=E5=A4=8D=E7=89=87=E6=96=AD=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...Lil2cppSourceCodeToXcodeproj2022OrNewer.cs | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/Editor/BuildProcessors/AddLil2cppSourceCodeToXcodeproj2022OrNewer.cs b/Editor/BuildProcessors/AddLil2cppSourceCodeToXcodeproj2022OrNewer.cs index e936332..084e388 100644 --- a/Editor/BuildProcessors/AddLil2cppSourceCodeToXcodeproj2022OrNewer.cs +++ b/Editor/BuildProcessors/AddLil2cppSourceCodeToXcodeproj2022OrNewer.cs @@ -2,6 +2,7 @@ using HybridCLR.Editor.Installer; using HybridCLR.Editor.Settings; using System.IO; using System.Text; +using System.Text.RegularExpressions; using UnityEditor; using UnityEditor.Build; using UnityEditor.Callbacks; @@ -24,6 +25,31 @@ namespace HybridCLR.Editor.BuildProcessors CopyLibil2cppToXcodeProj(pathToBuiltProject); } + private static string TryRemoveDunplicateShellScriptSegment(string pbxprojFile, string pbxprojContent) + { + // will appear duplicated Shell Script segment when append to existed xcode project. + // This is unity bug. + // we remove duplicated Shell Script to avoid build error. + string copyFileComment = @"/\* CopyFiles \*/,\s+([A-Z0-9]{24}) /\* ShellScript \*/,\s+([A-Z0-9]{24}) /\* ShellScript \*/,"; + var m = Regex.Match(pbxprojContent, copyFileComment, RegexOptions.Multiline); + if (!m.Success) + { + return pbxprojContent; + } + + if (m.Groups[1].Value != m.Groups[2].Value) + { + throw new BuildFailedException($"find invalid /* ShellScript */ segment"); + } + + int startIndexOfDupShellScript = m.Groups[2].Index; + int endIndexOfDupShellScript = pbxprojContent.IndexOf(",", startIndexOfDupShellScript); + + pbxprojContent = pbxprojContent.Remove(startIndexOfDupShellScript, endIndexOfDupShellScript + 1 - startIndexOfDupShellScript); + Debug.LogWarning($"[AddLil2cppSourceCodeToXcodeproj] remove duplicated '/* ShellScript */' from file '{pbxprojFile}'"); + return pbxprojContent; + } + private static void RemoveExternalLibil2cppOption(string pbxprojFile) { string pbxprojContent = File.ReadAllText(pbxprojFile, Encoding.UTF8); @@ -38,13 +64,8 @@ namespace HybridCLR.Editor.BuildProcessors 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}'"); - } + pbxprojContent = TryRemoveDunplicateShellScriptSegment(pbxprojFile, pbxprojContent); + File.WriteAllText(pbxprojFile, pbxprojContent, Encoding.UTF8); }