diff --git a/Assets/Mirror/Editor/Weaver/CompilationFinishedHook.cs b/Assets/Mirror/Editor/Weaver/CompilationFinishedHook.cs index d15653b84..991c96484 100644 --- a/Assets/Mirror/Editor/Weaver/CompilationFinishedHook.cs +++ b/Assets/Mirror/Editor/Weaver/CompilationFinishedHook.cs @@ -144,7 +144,7 @@ static void OnCompilationFinished(string assemblyPath, CompilerMessage[] message HashSet dependencyPaths = GetDependecyPaths(assemblyPath); // passing null in the outputDirectory param will do an in-place update of the assembly - if (Program.Process(unityEngineCoreModuleDLL, mirrorRuntimeDll, null, new[] { assemblyPath }, dependencyPaths.ToArray(), HandleWarning, HandleError)) + if (Weaver.Process(unityEngineCoreModuleDLL, mirrorRuntimeDll, null, new[] { assemblyPath }, dependencyPaths.ToArray(), HandleWarning, HandleError)) { // NOTE: WeaveFailed is critical for unit tests but isn't used elsewhere WeaveFailed = false; diff --git a/Assets/Mirror/Editor/Weaver/Log.cs b/Assets/Mirror/Editor/Weaver/Log.cs new file mode 100644 index 000000000..75d09321a --- /dev/null +++ b/Assets/Mirror/Editor/Weaver/Log.cs @@ -0,0 +1,20 @@ +using System; + +namespace Mirror.Weaver +{ + public static class Log + { + public static Action WarningMethod; + public static Action ErrorMethod; + + public static void Warning(string msg) + { + WarningMethod(msg); + } + + public static void Error(string msg) + { + ErrorMethod(msg); + } + } +} diff --git a/Assets/Mirror/Editor/Weaver/Program.cs.meta b/Assets/Mirror/Editor/Weaver/Log.cs.meta similarity index 100% rename from Assets/Mirror/Editor/Weaver/Program.cs.meta rename to Assets/Mirror/Editor/Weaver/Log.cs.meta diff --git a/Assets/Mirror/Editor/Weaver/Program.cs b/Assets/Mirror/Editor/Weaver/Program.cs deleted file mode 100644 index e3e9bd390..000000000 --- a/Assets/Mirror/Editor/Weaver/Program.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; - -namespace Mirror.Weaver -{ - public static class Log - { - public static Action WarningMethod; - public static Action ErrorMethod; - - public static void Warning(string msg) - { - WarningMethod(msg); - } - - public static void Error(string msg) - { - ErrorMethod(msg); - } - } - - public static class Program - { - public static bool Process(string unityEngine, string netDLL, string outputDirectory, string[] assemblies, string[] extraAssemblyPaths, Action printWarning, Action printError) - { - CheckDllPath(unityEngine); - CheckDllPath(netDLL); - CheckOutputDirectory(outputDirectory); - CheckAssemblies(assemblies); - Log.WarningMethod = printWarning; - Log.ErrorMethod = printError; - return Weaver.WeaveAssemblies(assemblies, extraAssemblyPaths, outputDirectory, unityEngine, netDLL); - } - - static void CheckDllPath(string path) - { - if (!File.Exists(path)) - throw new Exception("dll could not be located at " + path + "!"); - } - - static void CheckAssemblies(IEnumerable assemblyPaths) - { - foreach (string assemblyPath in assemblyPaths) - CheckAssemblyPath(assemblyPath); - } - - static void CheckAssemblyPath(string assemblyPath) - { - if (!File.Exists(assemblyPath)) - throw new Exception("Assembly " + assemblyPath + " does not exist!"); - } - - static void CheckOutputDirectory(string outputDir) - { - if (outputDir != null && !Directory.Exists(outputDir)) - { - Directory.CreateDirectory(outputDir); - } - } - } -} diff --git a/Assets/Mirror/Editor/Weaver/Weaver.cs b/Assets/Mirror/Editor/Weaver/Weaver.cs index d99ba25b7..41b0df168 100644 --- a/Assets/Mirror/Editor/Weaver/Weaver.cs +++ b/Assets/Mirror/Editor/Weaver/Weaver.cs @@ -345,7 +345,7 @@ static bool Weave(string assName, AssemblyDefinition unityAssembly, AssemblyDefi // write to outputDir if specified, otherwise perform in-place write WriterParameters writeParams = new WriterParameters { WriteSymbols = true }; - if (outputDir != null) + if (!string.IsNullOrEmpty(outputDir)) { CurrentAssembly.Write(Helpers.DestinationFileFor(outputDir, assName), writeParams); } @@ -359,7 +359,7 @@ static bool Weave(string assName, AssemblyDefinition unityAssembly, AssemblyDefi return true; } - public static bool WeaveAssemblies(IEnumerable assemblies, IEnumerable dependencies, string outputDir, string unityEngineDLLPath, string mirrorNetDLLPath) + static bool WeaveAssemblies(IEnumerable assemblies, IEnumerable dependencies, string outputDir, string unityEngineDLLPath, string mirrorNetDLLPath) { WeavingFailed = false; WeaveLists = new WeaverLists(); @@ -387,5 +387,44 @@ public static bool WeaveAssemblies(IEnumerable assemblies, IEnumerable printWarning, Action printError) + { + Validate(unityEngine, netDLL, outputDirectory, assemblies, extraAssemblyPaths); + Log.WarningMethod = printWarning; + Log.ErrorMethod = printError; + return WeaveAssemblies(assemblies, extraAssemblyPaths, outputDirectory, unityEngine, netDLL); + } + + static void Validate(string unityEngine, string netDLL, string outputDirectory, string[] assemblies, string[] extraAssemblyPaths) + { + CheckDllPath(unityEngine); + CheckDllPath(netDLL); + CheckOutputDirectory(outputDirectory); + CheckAssemblies(assemblies); + } + static void CheckDllPath(string path) + { + if (!File.Exists(path)) + throw new Exception("dll could not be located at " + path + "!"); + } + static void CheckAssemblies(IEnumerable assemblyPaths) + { + foreach (string assemblyPath in assemblyPaths) + CheckAssemblyPath(assemblyPath); + } + static void CheckAssemblyPath(string assemblyPath) + { + if (!File.Exists(assemblyPath)) + throw new Exception("Assembly " + assemblyPath + " does not exist!"); + } + static void CheckOutputDirectory(string outputDir) + { + if (!string.IsNullOrEmpty(outputDir) && !Directory.Exists(outputDir)) + { + Directory.CreateDirectory(outputDir); + } + } } }