refactor: keep consistent namespace

This commit is contained in:
Paul Pacheco 2019-04-06 07:33:47 -05:00
parent 3a7646bab7
commit 76392a3a4e
5 changed files with 149 additions and 146 deletions

View File

@ -1,5 +1,5 @@
using NUnit.Framework; using NUnit.Framework;
namespace Mirror namespace Mirror.Tests
{ {
[TestFixture] [TestFixture]
public class FloatBytePackerTest public class FloatBytePackerTest

View File

@ -1,6 +1,6 @@
using NUnit.Framework; using NUnit.Framework;
namespace Mirror namespace Mirror.Tests
{ {
struct TestMessage : IMessageBase struct TestMessage : IMessageBase
{ {

View File

@ -1,5 +1,5 @@
using NUnit.Framework; using NUnit.Framework;
namespace Mirror namespace Mirror.Tests
{ {
[TestFixture] [TestFixture]
public class MessagePackerTest public class MessagePackerTest

View File

@ -4,184 +4,187 @@
using UnityEditor.Compilation; using UnityEditor.Compilation;
using UnityEngine; using UnityEngine;
public class WeaverAssembler : MonoBehaviour namespace Mirror.Tests
{ {
public const string OutputDirectory = "Assets/Mirror/Tests/WeaverTests~/"; public class WeaverAssembler : MonoBehaviour
public static string OutputFile { get; set; }
public static HashSet<string> SourceFiles { get; private set; }
public static HashSet<string> ReferenceAssemblies { get; private set; }
public static bool AllowUnsafe { get; set; }
public static List<CompilerMessage> 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()
{ {
SourceFiles = new HashSet<string>(); public const string OutputDirectory = "Assets/Mirror/Tests/WeaverTests~/";
ReferenceAssemblies = new HashSet<string>(); public static string OutputFile { get; set; }
CompilerMessages = new List<CompilerMessage>(); public static HashSet<string> SourceFiles { get; private set; }
} public static HashSet<string> ReferenceAssemblies { get; private set; }
public static bool AllowUnsafe { get; set; }
public static List<CompilerMessage> 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 // static constructor to initialize static properties
public static void AddSourceFiles(string[] sourceFiles) static WeaverAssembler()
{
foreach (string src in sourceFiles)
{ {
SourceFiles.Add(OutputDirectory + src); SourceFiles = new HashSet<string>();
ReferenceAssemblies = new HashSet<string>();
CompilerMessages = new List<CompilerMessage>();
} }
}
// Add a range of reference files by full path // Add a range of source files to compile
public static void AddReferencesByFullPath(string[] refAsms) public static void AddSourceFiles(string[] sourceFiles)
{
foreach (string asm in refAsms)
{ {
ReferenceAssemblies.Add(asm); foreach (string src in sourceFiles)
}
}
// 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))
{ {
ReferenceAssemblies.Add(asmFullPath); SourceFiles.Add(OutputDirectory + src);
} }
} }
}
// Find reference assembly specified by asmName and store its full path in asmFullPath // Add a range of reference files by full path
// do not pass in paths in asmName, just assembly names public static void AddReferencesByFullPath(string[] refAsms)
public static bool FindReferenceAssemblyPath(string asmName, out string asmFullPath)
{
asmFullPath = "";
Assembly[] asms = CompilationPipeline.GetAssemblies();
foreach (Assembly asm in asms)
{ {
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; ReferenceAssemblies.Add(asmFullPath);
return true;
} }
} }
} }
return false; // 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)
// 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
{ {
File.Delete(projPathFile); asmFullPath = "";
} Assembly[] asms = CompilationPipeline.GetAssemblies();
catch {} foreach (Assembly asm in asms)
{
foreach (string asmRef in asm.compiledAssemblyReferences)
{
if (asmRef.EndsWith(asmName))
{
asmFullPath = asmRef;
return true;
}
}
}
try return false;
{
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; // Add reference (not cleared during calls to Clear)
OutputFile = ""; public static void ClearReferences()
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; 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); //Debug.LogFormat("Assembly build started for {0}", assemblyPath);
}; };
assemblyBuilder.buildFinished += delegate (string assemblyPath, CompilerMessage[] compilerMessages) assemblyBuilder.buildFinished += delegate (string assemblyPath, CompilerMessage[] compilerMessages)
{
CompilerMessages.AddRange(compilerMessages);
foreach (CompilerMessage cm in 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); //Debug.LogWarningFormat("{0}:{1} -- {2}", cm.file, cm.line, cm.message);
} }
else if (cm.type == CompilerMessageType.Error) else if (cm.type == CompilerMessageType.Error)
{ {
Debug.LogErrorFormat("{0}:{1} -- {2}", cm.file, cm.line, cm.message); Debug.LogErrorFormat("{0}:{1} -- {2}", cm.file, cm.line, cm.message);
CompilerErrors = true; CompilerErrors = true;
}
} }
} };
};
// Start build of assembly // Start build of assembly
if (!assemblyBuilder.Build()) if (!assemblyBuilder.Build())
{
Debug.LogErrorFormat("Failed to start build of assembly {0}", assemblyBuilder.assemblyPath);
return;
}
if (wait)
{
while (assemblyBuilder.status != AssemblyBuilderStatus.Finished)
{ {
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);
}
} }
} }
} }

View File

@ -7,7 +7,7 @@
using Mirror.Weaver; using Mirror.Weaver;
namespace Mirror namespace Mirror.Tests
{ {
[TestFixture] [TestFixture]
public class WeaverTest public class WeaverTest