From 53be9b6d9949645d5334690961ff31f90065a93a Mon Sep 17 00:00:00 2001 From: c6burns Date: Sat, 6 Apr 2019 14:02:14 -0600 Subject: [PATCH] fix(weaver): fix #706 find system dlls (#729) * added asmresolver back in * disambiguate Assembly symbol * add cache for pipeline asms * add back precomp refs from pipeline --- .../Editor/Weaver/CompilationFinishedHook.cs | 35 +++++++++++++------ Assets/Mirror/Editor/Weaver/Program.cs | 3 +- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/Assets/Mirror/Editor/Weaver/CompilationFinishedHook.cs b/Assets/Mirror/Editor/Weaver/CompilationFinishedHook.cs index 4e6466c97..5b47c4810 100644 --- a/Assets/Mirror/Editor/Weaver/CompilationFinishedHook.cs +++ b/Assets/Mirror/Editor/Weaver/CompilationFinishedHook.cs @@ -6,7 +6,8 @@ using UnityEditor; using UnityEditor.Compilation; using UnityEngine; -using Assembly = System.Reflection.Assembly; +using DotNetAssembly = System.Reflection.Assembly; +using UnityAssembly = UnityEditor.Compilation.Assembly; namespace Mirror.Weaver { @@ -15,6 +16,8 @@ public static class CompilationFinishedHook const string MirrorRuntimeAssemblyName = "Mirror"; const string MirrorWeaverAssemblyName = "Mirror.Weaver"; + private static UnityAssembly[] _cachedAssemblies; + public static Action OnWeaverMessage; // delegate for subscription to Weaver debug messages public static Action OnWeaverWarning; // delegate for subscription to Weaver warning messages public static Action OnWeaverError; // delete for subscription to Weaver error messages @@ -47,14 +50,15 @@ static void HandleError(string msg) [InitializeOnLoadMethod] static void OnInitializeOnLoad() { + // pipeline assemblies are valid until the next call to OnInitializeOnLoad + _cachedAssemblies = CompilationPipeline.GetAssemblies(); + CompilationPipeline.assemblyCompilationFinished += OnCompilationFinished; } static string FindMirrorRuntime() { - UnityEditor.Compilation.Assembly[] assemblies = CompilationPipeline.GetAssemblies(); - - foreach (UnityEditor.Compilation.Assembly assembly in assemblies) + foreach (UnityAssembly assembly in _cachedAssemblies) { if (assembly.name == MirrorRuntimeAssemblyName) { @@ -70,16 +74,16 @@ static HashSet GetDependencyDirectories(AssemblyName[] dependencies) // Since this assembly is already loaded in the domain this is a // no-op and returns the already loaded assembly return new HashSet( - dependencies.Select(dependency => Path.GetDirectoryName(Assembly.Load(dependency).Location)) + dependencies.Select(dependency => Path.GetDirectoryName(DotNetAssembly.Load(dependency).Location)) ); } // get all non-dynamic assembly directories - static HashSet GetNonDynamicAssemblyDirectories(Assembly[] assemblies) + static HashSet GetNonDynamicAssemblyDirectories(DotNetAssembly[] assemblies) { HashSet paths = new HashSet(); - foreach (Assembly assembly in assemblies) + foreach (DotNetAssembly assembly in assemblies) { if (!assembly.IsDynamic) { @@ -88,7 +92,7 @@ static HashSet GetNonDynamicAssemblyDirectories(Assembly[] assemblies) string assemblyName = assembly.GetName().Name; if (File.Exists(assemblyName)) { - paths.Add(Path.GetDirectoryName(Assembly.Load(assemblyName).Location)); + paths.Add(Path.GetDirectoryName(DotNetAssembly.Load(assemblyName).Location)); } } } @@ -148,8 +152,8 @@ static void OnCompilationFinished(string assemblyPath, CompilerMessage[] message } // find all assemblies and the currently compiling assembly - Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); - Assembly targetAssembly = assemblies.FirstOrDefault(asm => asm.GetName().Name == Path.GetFileNameWithoutExtension(assemblyPath)); + DotNetAssembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); + DotNetAssembly targetAssembly = assemblies.FirstOrDefault(asm => asm.GetName().Name == Path.GetFileNameWithoutExtension(assemblyPath)); // prepare variables HashSet dependencyPaths = new HashSet(); @@ -181,6 +185,17 @@ static void OnCompilationFinished(string assemblyPath, CompilerMessage[] message dependencyPaths = GetNonDynamicAssemblyDirectories(assemblies); } + // add compiled refs from CompilationPipeline + foreach (UnityAssembly unityAsm in _cachedAssemblies) + { + if (unityAsm.outputPath != assemblyPath) continue; + + foreach (string unityAsmRef in unityAsm.compiledAssemblyReferences) + { + dependencyPaths.Add(Path.GetDirectoryName(unityAsmRef)); + } + } + // construct full path to Project/Library/ScriptAssemblies string projectDirectory = Directory.GetParent(Application.dataPath).ToString(); string outputDirectory = Path.Combine(projectDirectory, Path.GetDirectoryName(assemblyPath)); diff --git a/Assets/Mirror/Editor/Weaver/Program.cs b/Assets/Mirror/Editor/Weaver/Program.cs index 35559ccfb..256e879cf 100644 --- a/Assets/Mirror/Editor/Weaver/Program.cs +++ b/Assets/Mirror/Editor/Weaver/Program.cs @@ -31,7 +31,8 @@ public static bool Process(string unityEngine, string netDLL, string outputDirec CheckAssemblies(assemblies); Log.WarningMethod = printWarning; Log.ErrorMethod = printError; - return Weaver.WeaveAssemblies(assemblies, extraAssemblyPaths, null, outputDirectory, unityEngine, netDLL); + IAssemblyResolver assemblyResolver = new DefaultAssemblyResolver(); + return Weaver.WeaveAssemblies(assemblies, extraAssemblyPaths, assemblyResolver, outputDirectory, unityEngine, netDLL); } private static void CheckDLLPath(string path)