[new] Installer支持从本地目录复制改造后的libil2cpp目录

main
walon 2023-04-29 12:11:16 +08:00
parent 0ccdd424ab
commit 8fd9b2ec82
3 changed files with 66 additions and 14 deletions

View File

@ -1,6 +1,7 @@
# change logs
- 2023.04.29 Installer支持从本地目录复制改造后的libil2cpp
- 2023.03.28 `HybridCLR/Generate/Il2CppDef`生成的代码位置移到`hybridclr/generated`下
- 2022.8.30 创建
- 2022.08.30 创建

View File

@ -169,7 +169,8 @@ namespace HybridCLR.Editor.Installer
public void InstallDefaultHybridCLR()
{
RunInitLocalIl2CppData(GetIl2CppPathByContentPath(EditorApplication.applicationContentsPath), _curVersion);
string libil2cppDir = PrepareLibil2cppWithHybridclrFromGitRepo();
RunInitLocalIl2CppData(GetIl2CppPathByContentPath(EditorApplication.applicationContentsPath), libil2cppDir, _curVersion);
}
public bool HasInstalledHybridCLR()
@ -202,7 +203,37 @@ namespace HybridCLR.Editor.Installer
BashUtil.RunCommand(workDir, "git", new string[] {"clone", "-b", branch, "--depth", "1", repoUrl, repoDir});
}
private void RunInitLocalIl2CppData(string editorIl2cppPath, UnityVersion version)
private string PrepareLibil2cppWithHybridclrFromGitRepo()
{
string workDir = SettingsUtil.HybridCLRDataDir;
Directory.CreateDirectory(workDir);
//BashUtil.RecreateDir(workDir);
// clone hybridclr
string hybridclrRepoURL = HybridCLRSettings.Instance.hybridclrRepoURL;
string hybridclrRepoDir = $"{workDir}/{hybridclr_repo_path}";
CloneBranch(workDir, hybridclrRepoURL, _curDefaultVersion.hybridclr.branch, hybridclrRepoDir);
if (!Directory.Exists(hybridclrRepoDir))
{
throw new Exception($"clone hybridclr fail. url: {hybridclrRepoURL}");
}
// clone il2cpp_plus
string il2cppPlusRepoURL = HybridCLRSettings.Instance.il2cppPlusRepoURL;
string il2cppPlusRepoDir = $"{workDir}/{il2cpp_plus_repo_path}";
CloneBranch(workDir, il2cppPlusRepoURL, _curDefaultVersion.il2cpp_plus.branch, il2cppPlusRepoDir);
if (!Directory.Exists(il2cppPlusRepoDir))
{
throw new Exception($"clone il2cpp_plus fail. url: {il2cppPlusRepoDir}");
}
Directory.Move($"{hybridclrRepoDir}/hybridclr", $"{il2cppPlusRepoDir}/libil2cpp/hybridclr");
return $"{il2cppPlusRepoDir}/libil2cpp";
}
private void RunInitLocalIl2CppData(string editorIl2cppPath, string libil2cppWithHybridclrSourceDir, UnityVersion version)
{
if (!IsComaptibleVersion())
{
@ -217,15 +248,6 @@ namespace HybridCLR.Editor.Installer
BashUtil.RemoveDir(buildiOSDir);
BashUtil.CopyDir($"{SettingsUtil.HybridCLRDataPathInPackage}/iOSBuild", buildiOSDir, true);
// clone hybridclr
string hybridclrRepoURL = HybridCLRSettings.Instance.hybridclrRepoURL;
string hybridclrRepoDir = $"{workDir}/{hybridclr_repo_path}";
CloneBranch(workDir, hybridclrRepoURL, _curDefaultVersion.hybridclr.branch, hybridclrRepoDir);
// clone il2cpp_plus
string il2cppPlusRepoURL = HybridCLRSettings.Instance.il2cppPlusRepoURL;
string il2cppPlusRepoDir = $"{workDir}/{il2cpp_plus_repo_path}";
CloneBranch(workDir, il2cppPlusRepoURL, _curDefaultVersion.il2cpp_plus.branch, il2cppPlusRepoDir);
// create LocalIl2Cpp
string localUnityDataDir = SettingsUtil.LocalUnityDataDir;
@ -239,8 +261,7 @@ namespace HybridCLR.Editor.Installer
// replace libil2cpp
string dstLibil2cppDir = $"{SettingsUtil.LocalIl2CppDir}/libil2cpp";
BashUtil.CopyDir($"{il2cppPlusRepoDir}/libil2cpp", dstLibil2cppDir, true);
BashUtil.CopyDir($"{hybridclrRepoDir}/hybridclr", $"{dstLibil2cppDir}/hybridclr", true);
BashUtil.CopyDir($"{libil2cppWithHybridclrSourceDir}", dstLibil2cppDir, true);
// clean Il2cppBuildCache
BashUtil.RemoveDir($"{SettingsUtil.ProjectDir}/Library/Il2cppBuildCache", true);

View File

@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Reflection;
using UnityEditor;
using UnityEngine;
@ -10,6 +11,10 @@ namespace HybridCLR.Editor.Installer
{
private InstallerController _controller;
private bool _installFromDir;
private string _installLibil2cppWithHybridclrSourceDir;
private void OnEnable()
{
_controller = new InstallerController();
@ -66,6 +71,17 @@ namespace HybridCLR.Editor.Installer
private void GUIInstallButton(string content, string button)
{
EditorGUILayout.BeginHorizontal();
_installFromDir = EditorGUILayout.Toggle("从本地复制libil2cpp", _installFromDir);
EditorGUI.BeginDisabledGroup(!_installFromDir);
EditorGUILayout.TextField(_installLibil2cppWithHybridclrSourceDir, GUILayout.Width(400));
if (GUILayout.Button("选择目录", GUILayout.Width(100)))
{
_installLibil2cppWithHybridclrSourceDir = EditorUtility.OpenFolderPanel("选择libil2cpp目录", Application.dataPath, "libil2cpp");
}
EditorGUI.EndDisabledGroup();
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(content);
if (GUILayout.Button(button, GUILayout.Width(100)))
@ -79,6 +95,20 @@ namespace HybridCLR.Editor.Installer
private void InstallLocalHybridCLR()
{
if (_installFromDir)
{
if (!Directory.Exists(_installLibil2cppWithHybridclrSourceDir))
{
Debug.LogError($"本地libil2cpp复制目录不存在. '{_installLibil2cppWithHybridclrSourceDir}'");
return;
}
if (!File.Exists($"{_installLibil2cppWithHybridclrSourceDir}/il2cpp-config.h") || !File.Exists($"{_installLibil2cppWithHybridclrSourceDir}/hybridclr/RuntimeApi.cpp"))
{
Debug.LogError($"本地libil2cpp不是合法有效的源码目录. '{_installLibil2cppWithHybridclrSourceDir}'");
return;
}
}
_controller.InstallDefaultHybridCLR();
}
}