From 76392a3a4ef3e3cc6aaceb848f1192790f179834 Mon Sep 17 00:00:00 2001 From: Paul Pacheco Date: Sat, 6 Apr 2019 07:33:47 -0500 Subject: [PATCH] refactor: keep consistent namespace --- Assets/Mirror/Tests/FloatBytePackerTest.cs | 2 +- Assets/Mirror/Tests/MessageBaseTests.cs | 2 +- Assets/Mirror/Tests/MessagePackerTest.cs | 2 +- Assets/Mirror/Tests/WeaverAssembler.cs | 287 +++++++++++---------- Assets/Mirror/Tests/WeaverTest.cs | 2 +- 5 files changed, 149 insertions(+), 146 deletions(-) diff --git a/Assets/Mirror/Tests/FloatBytePackerTest.cs b/Assets/Mirror/Tests/FloatBytePackerTest.cs index d57801fdf..4351a61f0 100644 --- a/Assets/Mirror/Tests/FloatBytePackerTest.cs +++ b/Assets/Mirror/Tests/FloatBytePackerTest.cs @@ -1,5 +1,5 @@ using NUnit.Framework; -namespace Mirror +namespace Mirror.Tests { [TestFixture] public class FloatBytePackerTest diff --git a/Assets/Mirror/Tests/MessageBaseTests.cs b/Assets/Mirror/Tests/MessageBaseTests.cs index 93bf4a659..99e0fd4b7 100644 --- a/Assets/Mirror/Tests/MessageBaseTests.cs +++ b/Assets/Mirror/Tests/MessageBaseTests.cs @@ -1,6 +1,6 @@ using NUnit.Framework; -namespace Mirror +namespace Mirror.Tests { struct TestMessage : IMessageBase { diff --git a/Assets/Mirror/Tests/MessagePackerTest.cs b/Assets/Mirror/Tests/MessagePackerTest.cs index 5023de746..369b321f5 100644 --- a/Assets/Mirror/Tests/MessagePackerTest.cs +++ b/Assets/Mirror/Tests/MessagePackerTest.cs @@ -1,5 +1,5 @@ using NUnit.Framework; -namespace Mirror +namespace Mirror.Tests { [TestFixture] public class MessagePackerTest diff --git a/Assets/Mirror/Tests/WeaverAssembler.cs b/Assets/Mirror/Tests/WeaverAssembler.cs index 61b830efa..1d99f174a 100644 --- a/Assets/Mirror/Tests/WeaverAssembler.cs +++ b/Assets/Mirror/Tests/WeaverAssembler.cs @@ -4,185 +4,188 @@ using UnityEditor.Compilation; using UnityEngine; -public class WeaverAssembler : MonoBehaviour +namespace Mirror.Tests { - public const string OutputDirectory = "Assets/Mirror/Tests/WeaverTests~/"; - public static string OutputFile { get; set; } - public static HashSet SourceFiles { get; private set; } - public static HashSet ReferenceAssemblies { get; private set; } - public static bool AllowUnsafe { get; set; } - public static List CompilerMessages { get; private set; } - public static bool CompilerErrors { get; private set; } - public static bool DeleteOutputOnClear { get; set; } - - // static constructor to initialize static properties - static WeaverAssembler() + public class WeaverAssembler : MonoBehaviour { - SourceFiles = new HashSet(); - ReferenceAssemblies = new HashSet(); - CompilerMessages = new List(); - } + public const string OutputDirectory = "Assets/Mirror/Tests/WeaverTests~/"; + public static string OutputFile { get; set; } + public static HashSet SourceFiles { get; private set; } + public static HashSet ReferenceAssemblies { get; private set; } + public static bool AllowUnsafe { get; set; } + public static List CompilerMessages { get; private set; } + public static bool CompilerErrors { get; private set; } + public static bool DeleteOutputOnClear { get; set; } - // Add a range of source files to compile - public static void AddSourceFiles(string[] sourceFiles) - { - foreach (string src in sourceFiles) + // static constructor to initialize static properties + static WeaverAssembler() { - SourceFiles.Add(OutputDirectory + src); + SourceFiles = new HashSet(); + ReferenceAssemblies = new HashSet(); + CompilerMessages = new List(); } - } - // Add a range of reference files by full path - public static void AddReferencesByFullPath(string[] refAsms) - { - foreach (string asm in refAsms) + // Add a range of source files to compile + public static void AddSourceFiles(string[] sourceFiles) { - ReferenceAssemblies.Add(asm); - } - } - - // Add a range of reference files by assembly name only - public static void AddReferencesByAssemblyName(string[] refAsms) - { - foreach (string asm in refAsms) - { - string asmFullPath; - if (FindReferenceAssemblyPath(asm, out asmFullPath)) + foreach (string src in sourceFiles) { - ReferenceAssemblies.Add(asmFullPath); + SourceFiles.Add(OutputDirectory + src); } } - } - // Find reference assembly specified by asmName and store its full path in asmFullPath - // do not pass in paths in asmName, just assembly names - public static bool FindReferenceAssemblyPath(string asmName, out string asmFullPath) - { - asmFullPath = ""; - - Assembly[] asms = CompilationPipeline.GetAssemblies(); - foreach (Assembly asm in asms) + // Add a range of reference files by full path + public static void AddReferencesByFullPath(string[] refAsms) { - foreach (string asmRef in asm.compiledAssemblyReferences) + foreach (string asm in refAsms) { - if (asmRef.EndsWith(asmName)) + ReferenceAssemblies.Add(asm); + } + } + + // Add a range of reference files by assembly name only + public static void AddReferencesByAssemblyName(string[] refAsms) + { + foreach (string asm in refAsms) + { + string asmFullPath; + if (FindReferenceAssemblyPath(asm, out asmFullPath)) { - asmFullPath = asmRef; - return true; + ReferenceAssemblies.Add(asmFullPath); } } } - return false; - } - - // Add reference (not cleared during calls to Clear) - public static void ClearReferences() - { - ReferenceAssemblies.Clear(); - } - - // Delete output dll / pdb / mdb - public static void DeleteOutput() - { - if (OutputFile.Length < 5) return; // "x.dll" shortest possible dll name - - string projPathFile = OutputDirectory + OutputFile; - - try + // Find reference assembly specified by asmName and store its full path in asmFullPath + // do not pass in paths in asmName, just assembly names + public static bool FindReferenceAssemblyPath(string asmName, out string asmFullPath) { - File.Delete(projPathFile); + asmFullPath = ""; - } - catch {} + Assembly[] asms = CompilationPipeline.GetAssemblies(); + foreach (Assembly asm in asms) + { + foreach (string asmRef in asm.compiledAssemblyReferences) + { + if (asmRef.EndsWith(asmName)) + { + asmFullPath = asmRef; + return true; + } + } + } - try - { - File.Delete(Path.ChangeExtension(projPathFile, ".pdb")); - - } - catch {} - - try - { - File.Delete(Path.ChangeExtension(projPathFile, ".dll.mdb")); - - } - catch {} - } - - // clear all settings except for referenced assemblies (which are cleared with ClearReferences) - public static void Clear() - { - if (DeleteOutputOnClear) - { - DeleteOutput(); + return false; } - CompilerErrors = false; - OutputFile = ""; - SourceFiles.Clear(); - CompilerMessages.Clear(); - AllowUnsafe = false; - DeleteOutputOnClear = false; - } - - // build synchronously - public static void Build() - { - BuildAssembly(true); - } - - // build asynchronously - this isn't currently used - public static void BuildAsync() - { - BuildAssembly(false); - } - - private static void BuildAssembly(bool wait) - { - AssemblyBuilder assemblyBuilder = new AssemblyBuilder(OutputDirectory + OutputFile, SourceFiles.ToArray()); - assemblyBuilder.additionalReferences = ReferenceAssemblies.ToArray(); - if (AllowUnsafe) + // Add reference (not cleared during calls to Clear) + public static void ClearReferences() { - assemblyBuilder.compilerOptions.AllowUnsafeCode = true; + ReferenceAssemblies.Clear(); } - assemblyBuilder.buildStarted += delegate (string assemblyPath) + // Delete output dll / pdb / mdb + public static void DeleteOutput() { + if (OutputFile.Length < 5) return; // "x.dll" shortest possible dll name + + string projPathFile = OutputDirectory + OutputFile; + + try + { + File.Delete(projPathFile); + + } + catch { } + + try + { + File.Delete(Path.ChangeExtension(projPathFile, ".pdb")); + + } + catch { } + + try + { + File.Delete(Path.ChangeExtension(projPathFile, ".dll.mdb")); + + } + catch { } + } + + // clear all settings except for referenced assemblies (which are cleared with ClearReferences) + public static void Clear() + { + if (DeleteOutputOnClear) + { + DeleteOutput(); + } + + CompilerErrors = false; + OutputFile = ""; + SourceFiles.Clear(); + CompilerMessages.Clear(); + AllowUnsafe = false; + DeleteOutputOnClear = false; + } + + // build synchronously + public static void Build() + { + BuildAssembly(true); + } + + // build asynchronously - this isn't currently used + public static void BuildAsync() + { + BuildAssembly(false); + } + + private static void BuildAssembly(bool wait) + { + AssemblyBuilder assemblyBuilder = new AssemblyBuilder(OutputDirectory + OutputFile, SourceFiles.ToArray()); + assemblyBuilder.additionalReferences = ReferenceAssemblies.ToArray(); + if (AllowUnsafe) + { + assemblyBuilder.compilerOptions.AllowUnsafeCode = true; + } + + assemblyBuilder.buildStarted += delegate (string assemblyPath) + { //Debug.LogFormat("Assembly build started for {0}", assemblyPath); }; - assemblyBuilder.buildFinished += delegate (string assemblyPath, CompilerMessage[] compilerMessages) - { - CompilerMessages.AddRange(compilerMessages); - foreach (CompilerMessage cm in compilerMessages) + assemblyBuilder.buildFinished += delegate (string assemblyPath, CompilerMessage[] compilerMessages) { - if (cm.type == CompilerMessageType.Warning) + CompilerMessages.AddRange(compilerMessages); + foreach (CompilerMessage cm in compilerMessages) { + if (cm.type == CompilerMessageType.Warning) + { //Debug.LogWarningFormat("{0}:{1} -- {2}", cm.file, cm.line, cm.message); } - else if (cm.type == CompilerMessageType.Error) - { - Debug.LogErrorFormat("{0}:{1} -- {2}", cm.file, cm.line, cm.message); - CompilerErrors = true; + else if (cm.type == CompilerMessageType.Error) + { + Debug.LogErrorFormat("{0}:{1} -- {2}", cm.file, cm.line, cm.message); + CompilerErrors = true; + } } - } - }; + }; - // Start build of assembly - if (!assemblyBuilder.Build()) - { - Debug.LogErrorFormat("Failed to start build of assembly {0}", assemblyBuilder.assemblyPath); - return; - } - - if (wait) - { - while (assemblyBuilder.status != AssemblyBuilderStatus.Finished) + // Start build of assembly + if (!assemblyBuilder.Build()) { - System.Threading.Thread.Sleep(10); + Debug.LogErrorFormat("Failed to start build of assembly {0}", assemblyBuilder.assemblyPath); + return; + } + + if (wait) + { + while (assemblyBuilder.status != AssemblyBuilderStatus.Finished) + { + System.Threading.Thread.Sleep(10); + } } } } -} +} \ No newline at end of file diff --git a/Assets/Mirror/Tests/WeaverTest.cs b/Assets/Mirror/Tests/WeaverTest.cs index 327630efa..9bf1f583a 100644 --- a/Assets/Mirror/Tests/WeaverTest.cs +++ b/Assets/Mirror/Tests/WeaverTest.cs @@ -7,7 +7,7 @@ using Mirror.Weaver; -namespace Mirror +namespace Mirror.Tests { [TestFixture] public class WeaverTest