[fix] 修复 externalHotUpdateAssembliyDirs 无法正确工作的bug

main
walon 2022-12-13 11:40:18 +08:00
parent 8afdcb985d
commit c8acfef61d
7 changed files with 40 additions and 34 deletions

View File

@ -1,4 +1,5 @@
using System; using HybridCLR.Editor.Meta;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -35,10 +36,12 @@ namespace HybridCLR.Editor.BuildProcessors
} }
} }
var assResolver = MetaUtil.CreateHotUpdateAssemblyResolver(EditorUserBuildSettings.activeBuildTarget);
// 检查是否填写了正确的dll名称 // 检查是否填写了正确的dll名称
foreach (var hotUpdateDll in allHotUpdateDllFiles) foreach (var hotUpdateDll in allHotUpdateDllFiles)
{ {
if (assemblies.All(ass => !ass.EndsWith(hotUpdateDll))) string hotUpdateAssName = hotUpdateDll.Substring(0, hotUpdateDll.Length - 4);
if (assemblies.All(ass => !ass.EndsWith(hotUpdateDll)) && string.IsNullOrEmpty(assResolver.ResolveAssembly(hotUpdateAssName, false)))
{ {
throw new Exception($"热更新 assembly:{hotUpdateDll} 不存在,请检查拼写错误"); throw new Exception($"热更新 assembly:{hotUpdateDll} 不存在,请检查拼写错误");
} }

View File

@ -26,29 +26,12 @@ namespace HybridCLR.Editor.Commands
var ls = SettingsUtil.HybridCLRSettings; var ls = SettingsUtil.HybridCLRSettings;
var allAssByNames = new Dictionary<string, Assembly>(); List<string> hotfixAssemblies = SettingsUtil.HotUpdateAssemblyNames;
foreach (var ass in AppDomain.CurrentDomain.GetAssemblies())
{
allAssByNames[ass.GetName().Name] = ass;
}
var hotfixAssembles = new List<Assembly>();
foreach(var assName in SettingsUtil.HotUpdateAssemblyNames)
{
if (allAssByNames.TryGetValue(assName, out var ass))
{
hotfixAssembles.Add(ass);
}
else
{
throw new Exception($"assembly:{assName} 不存在");
}
}
var analyzer = new Analyzer(Meta.MetaUtil.CreateBuildTargetAssemblyResolver(EditorUserBuildSettings.activeBuildTarget), HybridCLRSettings.Instance.collectAssetReferenceTypes); var analyzer = new Analyzer(Meta.MetaUtil.CreateBuildTargetAssemblyResolver(EditorUserBuildSettings.activeBuildTarget), HybridCLRSettings.Instance.collectAssetReferenceTypes);
var refTypes = analyzer.CollectRefs(hotfixAssembles); var refTypes = analyzer.CollectRefs(hotfixAssemblies);
Debug.Log($"[LinkGeneratorCommand] hotfix assembly count:{hotfixAssembles.Count}, ref type count:{refTypes.Count} output:{Application.dataPath}/{ls.outputLinkFile}"); Debug.Log($"[LinkGeneratorCommand] hotfix assembly count:{hotfixAssemblies.Count}, ref type count:{refTypes.Count} output:{Application.dataPath}/{ls.outputLinkFile}");
var linkXmlWriter = new LinkXmlWriter(); var linkXmlWriter = new LinkXmlWriter();
linkXmlWriter.Write($"{Application.dataPath}/{ls.outputLinkFile}", refTypes); linkXmlWriter.Write($"{Application.dataPath}/{ls.outputLinkFile}", refTypes);
AssetDatabase.Refresh(); AssetDatabase.Refresh();

View File

@ -52,12 +52,9 @@ namespace HybridCLR.Editor.Commands
static IAssemblyResolver CreateBuildTargetAssemblyResolver(BuildTarget target) static IAssemblyResolver CreateBuildTargetAssemblyResolver(BuildTarget target)
{ {
return new CombinedAssemblyResolver(new PathAssemblyResolver( return new CombinedAssemblyResolver(
SettingsUtil.GetAssembliesPostIl2CppStripDir(target), new PathAssemblyResolver(SettingsUtil.GetAssembliesPostIl2CppStripDir(target)),
SettingsUtil.GetHotUpdateDllsOutputDirByTarget(target)), MetaUtil.CreateHotUpdateAssemblyResolver(target)
new UnityPluginAssemblyResolver(),
new UnityDotNetAOTAssemblyResolver(),
new UnityEditorAssemblyResolver()
); );
} }

View File

@ -22,23 +22,23 @@ namespace HybridCLR.Editor.Link
_analyzeAssetType = analyzeAssetType; _analyzeAssetType = analyzeAssetType;
} }
public HashSet<TypeRef> CollectRefs(List<Assembly> rootAssemblies) public HashSet<TypeRef> CollectRefs(List<string> rootAssemblies)
{ {
using (var assCollector = new AssemblyCache(_resolver)) using (var assCollector = new AssemblyCache(_resolver))
{ {
var rootAssemblyName = new HashSet<string>(); var rootAssemblyName = new HashSet<string>();
foreach (var ass in rootAssemblies) foreach (var ass in rootAssemblies)
{ {
if (!rootAssemblyName.Add(ass.GetName().Name)) if (!rootAssemblyName.Add(ass))
{ {
throw new Exception($"assembly:{ass.GetName().Name} 重复"); throw new Exception($"assembly:{ass} 重复");
} }
} }
var typeRefs = new HashSet<TypeRef>(TypeEqualityComparer.Instance); var typeRefs = new HashSet<TypeRef>(TypeEqualityComparer.Instance);
foreach (var rootAss in rootAssemblies) foreach (var rootAss in rootAssemblies)
{ {
var dnAss = assCollector.LoadModule(rootAss.GetName().Name); var dnAss = assCollector.LoadModule(rootAss);
foreach (var type in dnAss.GetTypeRefs()) foreach (var type in dnAss.GetTypeRefs())
{ {
if (!rootAssemblyName.Contains(type.DefinitionAssembly.Name)) if (!rootAssemblyName.Contains(type.DefinitionAssembly.Name))

View File

@ -141,6 +141,25 @@ namespace HybridCLR.Editor.Meta
} }
} }
public static IAssemblyResolver CreateExternalAssemblyResolver(BuildTarget target)
{
var externalDirs = HybridCLRSettings.Instance.externalHotUpdateAssembliyDirs;
if (externalDirs == null || externalDirs.Length == 0)
{
return new PathAssemblyResolver();
}
else
{
var externalDirList = new List<string>();
foreach (var dir in externalDirs)
{
externalDirList.Add($"{dir}/{target}");
externalDirList.Add(dir);
}
return new PathAssemblyResolver(externalDirList.ToArray());
}
}
public static IAssemblyResolver CreateBuildTargetAssemblyResolver(BuildTarget target) public static IAssemblyResolver CreateBuildTargetAssemblyResolver(BuildTarget target)
{ {
return new CombinedAssemblyResolver(CreateHotUpdateAssemblyResolver(target), return new CombinedAssemblyResolver(CreateHotUpdateAssemblyResolver(target),

View File

@ -16,7 +16,11 @@ namespace HybridCLR.Editor.Meta
{ {
return refAss.Location; return refAss.Location;
} }
return Assembly.Load(assemblyName).Location; if (throwExIfNotFind)
{
throw new Exception($"resolve assembly:{assemblyName} fail");
}
return null;
} }
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "com.focus-creative-games.hybridclr_unity", "name": "com.focus-creative-games.hybridclr_unity",
"version": "1.1.10", "version": "1.1.11",
"displayName": "HybridCLR", "displayName": "HybridCLR",
"description": "Unity package for HybridCLR. It includes editor and runtime scripts and assets for HybridCLR", "description": "Unity package for HybridCLR. It includes editor and runtime scripts and assets for HybridCLR",
"category": "Runtime", "category": "Runtime",