[new] 过滤非aot泛型类及函数

main
walon 2022-09-23 14:26:28 +08:00
parent 0af6f704b2
commit aed13e464b
9 changed files with 66 additions and 11 deletions

View File

@ -37,6 +37,10 @@ namespace HybridCLR.Editor.AOT
private readonly HashSet<string> _hotUpdateAssemblyFiles;
public List<GenericClass> AotGenericTypes { get; } = new List<GenericClass>();
public List<GenericMethod> AotGenericMethods { get; } = new List<GenericMethod>();
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();
}
}
}

View File

@ -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;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 812d81a75b690394bbe16ef5f0bcbc46
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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();
}
}

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -12,7 +12,7 @@ namespace HybridCLR.Editor.Commands
/// <summary>
/// 按照必要的顺序,执行所有生成操作,适合打包前操作
/// </summary>
[MenuItem("HybridCLR/Generate/All", priority = 30)]
[MenuItem("HybridCLR/Generate/All", priority = 200)]
public static void GenerateAll()
{
// 顺序随意

View File

@ -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";