From aed13e464b9a76c757e7078b57f285609308719a Mon Sep 17 00:00:00 2001 From: walon Date: Fri, 23 Sep 2022 14:26:28 +0800 Subject: [PATCH] =?UTF-8?q?[new]=20=E8=BF=87=E6=BB=A4=E9=9D=9Eaot=E6=B3=9B?= =?UTF-8?q?=E5=9E=8B=E7=B1=BB=E5=8F=8A=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Editor/AOT/Analyzer.cs | 22 +++++++++++++++++++ Editor/AOT/ConstraintContext.cs | 22 +++++++++++++++++++ Editor/AOT/ConstraintContext.cs.meta | 11 ++++++++++ .../Commands/AOTReferenceGeneratorCommand.cs | 4 ++-- Editor/Commands/CompileDllCommand.cs | 10 ++++----- Editor/Commands/LinkGeneratorCommand.cs | 2 +- .../Commands/MethodBridgeGeneratorCommand.cs | 2 +- Editor/Commands/PrebuildCommand.cs | 2 +- .../ReversePInvokeWrapperGeneratorCommand.cs | 2 +- 9 files changed, 66 insertions(+), 11 deletions(-) create mode 100644 Editor/AOT/ConstraintContext.cs create mode 100644 Editor/AOT/ConstraintContext.cs.meta diff --git a/Editor/AOT/Analyzer.cs b/Editor/AOT/Analyzer.cs index a23cae4..331422d 100644 --- a/Editor/AOT/Analyzer.cs +++ b/Editor/AOT/Analyzer.cs @@ -37,6 +37,10 @@ namespace HybridCLR.Editor.AOT private readonly HashSet _hotUpdateAssemblyFiles; + public List AotGenericTypes { get; } = new List(); + + public List AotGenericMethods { get; } = new List(); + public Analyzer(Options options) { _assemblyCollector = options.Collector; @@ -63,6 +67,16 @@ namespace HybridCLR.Editor.AOT return _hotUpdateAssemblyFiles.Contains(type.Module.Name); } + private bool IsAotType(TypeDef type) + { + return !_hotUpdateAssemblyFiles.Contains(type.Module.Name); + } + + private bool IsAotGenericMethod(MethodDef method) + { + return IsAotType(method.DeclaringType) && method.HasGenericParameters; + } + private void OnNewMethod(GenericMethod method) { if(method == null) @@ -179,10 +193,18 @@ namespace HybridCLR.Editor.AOT } } + private void FilterAOTGenericTypeAndMethods() + { + var cc = new ConstraintContext(); + AotGenericTypes.AddRange(_genericTypes.Where(type => IsAotType(type.Type)).Select(gc => cc.ApplyConstraints(gc))); + AotGenericMethods.AddRange(_genericMethods.Where(method => IsAotGenericMethod(method.Method)).Select(gm => cc.ApplyConstraints(gm))); + } + public void Run() { Prepare(); RecursiveCollect(); + FilterAOTGenericTypeAndMethods(); } } } diff --git a/Editor/AOT/ConstraintContext.cs b/Editor/AOT/ConstraintContext.cs new file mode 100644 index 0000000..0a9a7fc --- /dev/null +++ b/Editor/AOT/ConstraintContext.cs @@ -0,0 +1,22 @@ +using HybridCLR.Editor.Meta; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HybridCLR.Editor.AOT +{ + public class ConstraintContext + { + public GenericClass ApplyConstraints(GenericClass gc) + { + return gc; + } + + public GenericMethod ApplyConstraints(GenericMethod gm) + { + return gm; + } + } +} diff --git a/Editor/AOT/ConstraintContext.cs.meta b/Editor/AOT/ConstraintContext.cs.meta new file mode 100644 index 0000000..3e99cab --- /dev/null +++ b/Editor/AOT/ConstraintContext.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 812d81a75b690394bbe16ef5f0bcbc46 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Commands/AOTReferenceGeneratorCommand.cs b/Editor/Commands/AOTReferenceGeneratorCommand.cs index 39e18c7..e6a1d27 100644 --- a/Editor/Commands/AOTReferenceGeneratorCommand.cs +++ b/Editor/Commands/AOTReferenceGeneratorCommand.cs @@ -13,7 +13,7 @@ namespace HybridCLR.Editor.Commands public static class AOTReferenceGeneratorCommand { - [MenuItem("HybridCLR/Generate/AOTGenericReference", priority = 18)] + [MenuItem("HybridCLR/Generate/AOTGenericReference", priority = 102)] public static void GenerateAOTGenericReference() { GenerateAOTGenericReference(true); @@ -39,7 +39,7 @@ namespace HybridCLR.Editor.Commands analyzer.Run(); var writer = new GenericReferenceWriter(); - writer.Write(analyzer.GenericTypes.ToList(), analyzer.GenericMethods.ToList(), $"{Application.dataPath}/{gs.outputAOTGenericReferenceFile}"); + writer.Write(analyzer.AotGenericTypes.ToList(), analyzer.AotGenericMethods.ToList(), $"{Application.dataPath}/{gs.outputAOTGenericReferenceFile}"); AssetDatabase.Refresh(); } } diff --git a/Editor/Commands/CompileDllCommand.cs b/Editor/Commands/CompileDllCommand.cs index ec1ded6..c3d9547 100644 --- a/Editor/Commands/CompileDllCommand.cs +++ b/Editor/Commands/CompileDllCommand.cs @@ -32,31 +32,31 @@ namespace HybridCLR.Editor.Commands CompileDll(SettingsUtil.GetHotFixDllsOutputDirByTarget(target), target); } - [MenuItem("HybridCLR/CompileDll/ActiveBuildTarget")] + [MenuItem("HybridCLR/CompileDll/ActiveBuildTarget", priority = 100)] public static void CompileDllActiveBuildTarget() { CompileDll(EditorUserBuildSettings.activeBuildTarget); } - [MenuItem("HybridCLR/CompileDll/Win32")] + [MenuItem("HybridCLR/CompileDll/Win32", priority = 200)] public static void CompileDllWin32() { CompileDll(BuildTarget.StandaloneWindows); } - [MenuItem("HybridCLR/CompileDll/Win64")] + [MenuItem("HybridCLR/CompileDll/Win64", priority = 201)] public static void CompileDllWin64() { CompileDll(BuildTarget.StandaloneWindows64); } - [MenuItem("HybridCLR/CompileDll/Android")] + [MenuItem("HybridCLR/CompileDll/Android", priority = 202)] public static void CompileDllAndroid() { CompileDll(BuildTarget.Android); } - [MenuItem("HybridCLR/CompileDll/IOS")] + [MenuItem("HybridCLR/CompileDll/IOS", priority = 203)] public static void CompileDllIOS() { CompileDll(BuildTarget.iOS); diff --git a/Editor/Commands/LinkGeneratorCommand.cs b/Editor/Commands/LinkGeneratorCommand.cs index e0f3993..200b660 100644 --- a/Editor/Commands/LinkGeneratorCommand.cs +++ b/Editor/Commands/LinkGeneratorCommand.cs @@ -16,7 +16,7 @@ namespace HybridCLR.Editor.Commands public static class LinkGeneratorCommand { - [MenuItem("HybridCLR/Generate/LinkXml", priority = 10)] + [MenuItem("HybridCLR/Generate/LinkXml", priority = 100)] public static void GenerateLinkXml() { GenerateLinkXml(true); diff --git a/Editor/Commands/MethodBridgeGeneratorCommand.cs b/Editor/Commands/MethodBridgeGeneratorCommand.cs index 654a764..ebafae5 100644 --- a/Editor/Commands/MethodBridgeGeneratorCommand.cs +++ b/Editor/Commands/MethodBridgeGeneratorCommand.cs @@ -58,7 +58,7 @@ namespace HybridCLR.Editor.Commands CleanIl2CppBuildCache(); } - [MenuItem("HybridCLR/Generate/MethodBridge", priority = 15)] + [MenuItem("HybridCLR/Generate/MethodBridge", priority = 101)] public static void GenerateMethodBridge() { GenerateMethodBridge(true); diff --git a/Editor/Commands/PrebuildCommand.cs b/Editor/Commands/PrebuildCommand.cs index c8d7a9c..a3373d7 100644 --- a/Editor/Commands/PrebuildCommand.cs +++ b/Editor/Commands/PrebuildCommand.cs @@ -12,7 +12,7 @@ namespace HybridCLR.Editor.Commands /// /// 按照必要的顺序,执行所有生成操作,适合打包前操作 /// - [MenuItem("HybridCLR/Generate/All", priority = 30)] + [MenuItem("HybridCLR/Generate/All", priority = 200)] public static void GenerateAll() { // 顺序随意 diff --git a/Editor/Commands/ReversePInvokeWrapperGeneratorCommand.cs b/Editor/Commands/ReversePInvokeWrapperGeneratorCommand.cs index c8e0d41..7d95b7c 100644 --- a/Editor/Commands/ReversePInvokeWrapperGeneratorCommand.cs +++ b/Editor/Commands/ReversePInvokeWrapperGeneratorCommand.cs @@ -16,7 +16,7 @@ namespace HybridCLR.Editor.Commands public static class ReversePInvokeWrapperGeneratorCommand { - [MenuItem("HybridCLR/Generate/ReversePInvokeWrapper", priority = 20)] + [MenuItem("HybridCLR/Generate/ReversePInvokeWrapper", priority = 103)] public static void GenerateReversePInvokeWrapper() { string ReversePInvokeWrapperStubFile = $"{SettingsUtil.LocalIl2CppDir}/libil2cpp/hybridclr/metadata/ReversePInvokeMethodStub.cpp";