[fix] 修复 Unity 2022导出的xcode工程包含多个ShellScript片段时错误地删除了非重复片断的bug
parent
e086228d90
commit
0b455eb882
|
@ -2,6 +2,7 @@ using HybridCLR.Editor.Installer;
|
||||||
using HybridCLR.Editor.Settings;
|
using HybridCLR.Editor.Settings;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEditor.Build;
|
using UnityEditor.Build;
|
||||||
using UnityEditor.Callbacks;
|
using UnityEditor.Callbacks;
|
||||||
|
@ -24,6 +25,31 @@ namespace HybridCLR.Editor.BuildProcessors
|
||||||
CopyLibil2cppToXcodeProj(pathToBuiltProject);
|
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)
|
private static void RemoveExternalLibil2cppOption(string pbxprojFile)
|
||||||
{
|
{
|
||||||
string pbxprojContent = File.ReadAllText(pbxprojFile, Encoding.UTF8);
|
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");
|
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 */,");
|
pbxprojContent = TryRemoveDunplicateShellScriptSegment(pbxprojFile, pbxprojContent);
|
||||||
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);
|
File.WriteAllText(pbxprojFile, pbxprojContent, Encoding.UTF8);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue