From 1bd27a3e226be21be4cb253706012f0aecd3cb46 Mon Sep 17 00:00:00 2001 From: walon Date: Sat, 7 Oct 2023 21:59:56 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E4=BF=AE=E5=A4=8D=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=A1=A5=E6=8E=A5=E5=87=BD=E6=95=B0=E6=97=B6=EF=BC=8C=E5=A6=82?= =?UTF-8?q?=E6=9E=9C=E7=83=AD=E6=9B=B4=E6=96=B0=E7=A8=8B=E5=BA=8F=E9=9B=86?= =?UTF-8?q?=E6=9C=AA=E5=8C=85=E5=90=AB=E4=BB=BB=E4=BD=95=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E5=BC=95=E7=94=A8=E4=BA=86=E6=9F=90=E4=B8=AA?= =?UTF-8?q?aot=E7=A8=8B=E5=BA=8F=E9=9B=86=EF=BC=8C=E5=88=99=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E4=B8=BA=E8=AF=A5aot=E7=A8=8B=E5=BA=8F=E9=9B=86?= =?UTF-8?q?=E7=94=9F=E6=88=90=E6=A1=A5=E6=8E=A5=E5=87=BD=E6=95=B0=EF=BC=8C?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E5=87=BA=E7=8E=B0NotSupportNative2Managed?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Editor/Commands/MethodBridgeGeneratorCommand.cs | 13 ++++++++++--- Editor/Meta/AssemblyReferenceDeepCollector.cs | 5 +++++ Editor/MethodBridge/Analyzer.cs | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Editor/Commands/MethodBridgeGeneratorCommand.cs b/Editor/Commands/MethodBridgeGeneratorCommand.cs index 08879d9..de83cb7 100644 --- a/Editor/Commands/MethodBridgeGeneratorCommand.cs +++ b/Editor/Commands/MethodBridgeGeneratorCommand.cs @@ -10,6 +10,7 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; using UnityEditor; +using UnityEditor.Build; using UnityEngine; namespace HybridCLR.Editor.Commands @@ -47,14 +48,20 @@ namespace HybridCLR.Editor.Commands public static void CompileAndGenerateMethodBridge() { BuildTarget target = EditorUserBuildSettings.activeBuildTarget; - CompileDllCommand.CompileDll(target); GenerateMethodBridge(target); } public static void GenerateMethodBridge(BuildTarget target) { - List hotUpdateDllNames = SettingsUtil.HotUpdateAssemblyNamesExcludePreserved; - using (AssemblyReferenceDeepCollector collector = new AssemblyReferenceDeepCollector(MetaUtil.CreateHotUpdateAndAOTAssemblyResolver(target, hotUpdateDllNames), hotUpdateDllNames)) + string aotDllDir = SettingsUtil.GetAssembliesPostIl2CppStripDir(target); + List aotAssemblyNames = Directory.Exists(aotDllDir) ? + Directory.GetFiles(aotDllDir, "*.dll", SearchOption.TopDirectoryOnly).Select(Path.GetFileNameWithoutExtension).ToList() + : new List(); + if (aotAssemblyNames.Count == 0) + { + throw new Exception($"no aot assembly found. please run `HybridCLR/Generate/All` or `HybridCLR/Generate/AotDlls` to generate aot dlls before runing `HybridCLR/Generate/MethodBridge`"); + } + using (AssemblyReferenceDeepCollector collector = new AssemblyReferenceDeepCollector(MetaUtil.CreateAOTAssemblyResolver(target), aotAssemblyNames)) { var analyzer = new Analyzer(new Analyzer.Options { diff --git a/Editor/Meta/AssemblyReferenceDeepCollector.cs b/Editor/Meta/AssemblyReferenceDeepCollector.cs index 39f0f61..8850aac 100644 --- a/Editor/Meta/AssemblyReferenceDeepCollector.cs +++ b/Editor/Meta/AssemblyReferenceDeepCollector.cs @@ -30,6 +30,11 @@ namespace HybridCLR.Editor.Meta return LoadedModules.Where(e => !_rootAssemblies.Contains(e.Key)).Select(e => e.Value).ToList(); } + public List GetLoadedModules() + { + return LoadedModules.Select(e => e.Value).ToList(); + } + public List GetLoadedModulesOfRootAssemblies() { return _rootAssemblies.Select(ass => LoadedModules[ass]).ToList(); diff --git a/Editor/MethodBridge/Analyzer.cs b/Editor/MethodBridge/Analyzer.cs index 520d5ae..59e2dd7 100644 --- a/Editor/MethodBridge/Analyzer.cs +++ b/Editor/MethodBridge/Analyzer.cs @@ -143,7 +143,7 @@ namespace HybridCLR.Editor.MethodBridge { // 将所有非泛型函数全部加入函数列表,同时立马walk这些method。 // 后续迭代中将只遍历MethodSpec - foreach (var ass in _assemblyCollector.GetLoadedModulesExcludeRootAssemblies()) + foreach (var ass in _assemblyCollector.GetLoadedModules()) { foreach (TypeDef typeDef in ass.GetTypes()) {