Refactor Xcode project file handling in build processor

pull/70/head
absences 2026-10-12 11:11:49 +08:00 committed by GitHub
parent f5ca39f3c9
commit 9c59fcd45f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 27 additions and 6 deletions

View File

@ -20,17 +20,38 @@
#if UNITY_2022 && (UNITY_IOS || UNITY_TVOS || UNITY_VISIONOS)
using HybridCLR.Settings;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Callbacks;
using UnityEngine;
namespace HybridCLR.BuildProcessors
{
public static class AddLil2cppSourceCodeToXcodeproj2022OrNewer
{
public static string GetXcodeProjectFile(string pathToBuiltProject)
{
foreach (string dir in Directory.GetDirectories(pathToBuiltProject, "*.xcodeproj", SearchOption.TopDirectoryOnly))
{
string pbxprojFile = $"{dir}/project.pbxproj";
if (File.Exists(pbxprojFile))
{
return pbxprojFile;
}
}
throw new BuildFailedException($"can't find xxxx.xcodeproj/project.pbxproj in {pathToBuiltProject}");
}
[PostProcessBuild]
public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject)
{
if (!HybridCLRSettings.Instance.enable)
HybridCLRSettings globalSettings = SettingsUtil.HybridCLRSettings;
if (!globalSettings.enable)
return;
string pbxprojFile = BuildProcessorUtil.GetXcodeProjectFile(pathToBuiltProject);
string pbxprojFile = GetXcodeProjectFile(pathToBuiltProject);
RemoveExternalLibil2cppOption(pbxprojFile);
CopyLibil2cppToXcodeProj(pathToBuiltProject);
}
@ -84,9 +105,9 @@ namespace HybridCLR.BuildProcessors
{
string srcLibil2cppDir = $"{SettingsUtil.LocalIl2CppDir}/libil2cpp";
string destLibil2cppDir = $"{pathToBuiltProject}/Il2CppOutputProject/IL2CPP/libil2cpp";
BashUtil.RemoveDir(destLibil2cppDir);
BashUtil.CopyDir(srcLibil2cppDir, destLibil2cppDir, true);
Directory.Delete(destLibil2cppDir, true);
FileUtil.CopyFileOrDirectory(srcLibil2cppDir, destLibil2cppDir);
}
}
}
#endif
#endif