[new] support preserve UnityEngine core types when GenerateLinkXml
parent
208372e6af
commit
82163d2e50
|
|
@ -28,7 +28,7 @@ namespace HybridCLR.Editor.Commands
|
|||
List<string> hotfixAssemblies = SettingsUtil.HotUpdateAssemblyNamesExcludePreserved;
|
||||
|
||||
var analyzer = new Analyzer(MetaUtil.CreateHotUpdateAndAOTAssemblyResolver(target, hotfixAssemblies));
|
||||
var refTypes = analyzer.CollectRefs(hotfixAssemblies);
|
||||
var refTypes = analyzer.CollectRefs(hotfixAssemblies, !ls.dontPreserveUnityEngineCoreTypesInLinkXml);
|
||||
|
||||
Debug.Log($"[LinkGeneratorCommand] hotfix assembly count:{hotfixAssemblies.Count}, ref type count:{refTypes.Count} output:{Application.dataPath}/{ls.outputLinkFile}");
|
||||
var linkXmlWriter = new LinkXmlWriter();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
|
@ -21,12 +22,43 @@ namespace HybridCLR.Editor.Link
|
|||
_resolver = resolver;
|
||||
}
|
||||
|
||||
public HashSet<TypeRef> CollectRefs(List<string> rootAssemblies)
|
||||
|
||||
public HashSet<ITypeDefOrRef> CollectRefs(List<string> rootAssemblies, bool includeUnityEngineCoreTypes)
|
||||
{
|
||||
var typeRefs = new HashSet<ITypeDefOrRef>(TypeEqualityComparer.Instance);
|
||||
CollectHotUpdateRefs(rootAssemblies, typeRefs);
|
||||
|
||||
if (includeUnityEngineCoreTypes)
|
||||
{
|
||||
CollectUnityEngineCoreTypes(typeRefs);
|
||||
}
|
||||
return typeRefs;
|
||||
}
|
||||
|
||||
private void CollectUnityEngineCoreTypes(HashSet<ITypeDefOrRef> preservedTypes)
|
||||
{
|
||||
Debug.Log("CollectUnityEngineCoreTypes");
|
||||
string unityEngineDllPath = $"{EditorApplication.applicationContentsPath}/Managed/UnityEngine";
|
||||
|
||||
var assCollector = new AssemblyCache(_resolver);
|
||||
foreach (string unityEngineDll in Directory.GetFiles(unityEngineDllPath, "UnityEngine.*.dll", SearchOption.AllDirectories))
|
||||
{
|
||||
ModuleDefMD mod = assCollector.LoadModuleFromFileWithoutCache(unityEngineDll);
|
||||
foreach (TypeDef type in mod.GetTypes())
|
||||
{
|
||||
if (type.Methods.Any(m => m.IsInternalCall || m.IsPinvokeImpl))
|
||||
{
|
||||
preservedTypes.Add(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void CollectHotUpdateRefs(List<string> rootAssemblies, HashSet<ITypeDefOrRef> preservedTypes)
|
||||
{
|
||||
var assCollector = new AssemblyCache(_resolver);
|
||||
var rootAssemblyNames = new HashSet<string>(rootAssemblies);
|
||||
|
||||
var typeRefs = new HashSet<TypeRef>(TypeEqualityComparer.Instance);
|
||||
foreach (var rootAss in rootAssemblies)
|
||||
{
|
||||
var dnAss = assCollector.LoadModule(rootAss, false);
|
||||
|
|
@ -39,11 +71,10 @@ namespace HybridCLR.Editor.Link
|
|||
}
|
||||
if (!rootAssemblyNames.Contains(type.DefinitionAssembly.Name.ToString()))
|
||||
{
|
||||
typeRefs.Add(type);
|
||||
preservedTypes.Add(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
return typeRefs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace HybridCLR.Editor.Link
|
|||
{
|
||||
internal class LinkXmlWriter
|
||||
{
|
||||
public void Write(string outputLinkXmlFile, HashSet<TypeRef> refTypes)
|
||||
public void Write(string outputLinkXmlFile, HashSet<ITypeDefOrRef> refTypes)
|
||||
{
|
||||
string parentDir = Directory.GetParent(outputLinkXmlFile).FullName;
|
||||
Directory.CreateDirectory(parentDir);
|
||||
|
|
|
|||
|
|
@ -71,6 +71,13 @@ namespace HybridCLR.Editor.Meta
|
|||
return mod;
|
||||
}
|
||||
|
||||
public ModuleDefMD LoadModuleFromFileWithoutCache(string dllPath)
|
||||
{
|
||||
ModuleDefMD mod = ModuleDefMD.Load(File.ReadAllBytes(dllPath), _modCtx);
|
||||
mod.EnableTypeDefFindCache = true;
|
||||
return mod;
|
||||
}
|
||||
|
||||
private void LoadNetStandard()
|
||||
{
|
||||
string netstandardDllPath = _assemblyPathResolver.ResolveAssembly("netstandard", false);
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ namespace HybridCLR.Editor.Settings
|
|||
private SerializedProperty _externalHotUpdateAssembliyDirs;
|
||||
private SerializedProperty _strippedAOTDllOutputRootDir;
|
||||
private SerializedProperty _patchAOTAssemblies;
|
||||
private SerializedProperty _dontPreserveUnityEngineCoreTypesInLinkXml;
|
||||
private SerializedProperty _outputLinkFile;
|
||||
private SerializedProperty _outputAOTGenericReferenceFile;
|
||||
private SerializedProperty _maxGenericReferenceIteration;
|
||||
|
|
@ -51,6 +52,7 @@ namespace HybridCLR.Editor.Settings
|
|||
_externalHotUpdateAssembliyDirs = _serializedObject.FindProperty("externalHotUpdateAssembliyDirs");
|
||||
_strippedAOTDllOutputRootDir = _serializedObject.FindProperty("strippedAOTDllOutputRootDir");
|
||||
_patchAOTAssemblies = _serializedObject.FindProperty("patchAOTAssemblies");
|
||||
_dontPreserveUnityEngineCoreTypesInLinkXml = _serializedObject.FindProperty("dontPreserveUnityEngineCoreTypesInLinkXml");
|
||||
_outputLinkFile = _serializedObject.FindProperty("outputLinkFile");
|
||||
_outputAOTGenericReferenceFile = _serializedObject.FindProperty("outputAOTGenericReferenceFile");
|
||||
_maxGenericReferenceIteration = _serializedObject.FindProperty("maxGenericReferenceIteration");
|
||||
|
|
@ -140,6 +142,7 @@ namespace HybridCLR.Editor.Settings
|
|||
EditorGUILayout.PropertyField(_externalHotUpdateAssembliyDirs);
|
||||
EditorGUILayout.PropertyField(_strippedAOTDllOutputRootDir);
|
||||
EditorGUILayout.PropertyField(_patchAOTAssemblies);
|
||||
EditorGUILayout.PropertyField(_dontPreserveUnityEngineCoreTypesInLinkXml);
|
||||
EditorGUILayout.PropertyField(_outputLinkFile);
|
||||
EditorGUILayout.PropertyField(_outputAOTGenericReferenceFile);
|
||||
EditorGUILayout.PropertyField(_maxGenericReferenceIteration);
|
||||
|
|
|
|||
|
|
@ -39,6 +39,9 @@ namespace HybridCLR.Editor.Settings
|
|||
[Tooltip("supplementary metadata assembly names(without .dll suffix)")]
|
||||
public string[] patchAOTAssemblies;
|
||||
|
||||
[Tooltip("don't preserve UnityEngine core types in link.xml")]
|
||||
public bool dontPreserveUnityEngineCoreTypesInLinkXml = false;
|
||||
|
||||
[Tooltip("output file of automatic generated link.xml by scanning hot update assemblies")]
|
||||
public string outputLinkFile = "HybridCLRGenerate/link.xml";
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue