[fix] fix the bug where MissingMetadataChecker can't detect references to newly added AOT assemblies.

main
walon 2024-12-18 18:21:37 +08:00
parent 2458c9a9ba
commit 0c99afd58e
1 changed files with 12 additions and 4 deletions

View File

@ -13,17 +13,19 @@ namespace HybridCLR.Editor.HotUpdate
{ {
private readonly HashSet<string> _aotAssNames; private readonly HashSet<string> _aotAssNames;
private readonly HashSet<string> _hotUpdateAssNames;
private readonly AssemblyCache _assCache; private readonly AssemblyCache _assCache;
public MissingMetadataChecker(string aotDllDir, IEnumerable<string> excludeDllNames) public MissingMetadataChecker(string aotDllDir, IEnumerable<string> hotUpdateAssNames)
{ {
var excludeDllNameSet = new HashSet<string>(excludeDllNames ?? new List<string>()); _hotUpdateAssNames = new HashSet<string>(hotUpdateAssNames ?? new List<string>());
_aotAssNames = new HashSet<string>(); _aotAssNames = new HashSet<string>();
foreach (var aotFile in Directory.GetFiles(aotDllDir, "*.dll")) foreach (var aotFile in Directory.GetFiles(aotDllDir, "*.dll"))
{ {
string aotAssName = Path.GetFileNameWithoutExtension(aotFile); string aotAssName = Path.GetFileNameWithoutExtension(aotFile);
if (excludeDllNameSet.Contains(aotAssName)) if (_hotUpdateAssNames.Contains(aotAssName))
{ {
continue; continue;
} }
@ -34,6 +36,8 @@ namespace HybridCLR.Editor.HotUpdate
public bool Check(string hotUpdateDllPath) public bool Check(string hotUpdateDllPath)
{ {
bool anyMissing = false;
ModuleDef mod = ModuleDefMD.Load(File.ReadAllBytes(hotUpdateDllPath), _assCache.ModCtx); ModuleDef mod = ModuleDefMD.Load(File.ReadAllBytes(hotUpdateDllPath), _assCache.ModCtx);
foreach (var refass in mod.GetAssemblyRefs()) foreach (var refass in mod.GetAssemblyRefs())
@ -43,9 +47,13 @@ namespace HybridCLR.Editor.HotUpdate
{ {
_assCache.LoadModule(refass.Name, true); _assCache.LoadModule(refass.Name, true);
} }
else if (!_hotUpdateAssNames.Contains(refAssName))
{
UnityEngine.Debug.LogError($"Missing AOT Assembly: {refAssName}");
anyMissing = true;
}
} }
bool anyMissing = false;
foreach (TypeRef typeRef in mod.GetTypeRefs()) foreach (TypeRef typeRef in mod.GetTypeRefs())
{ {