removing program class (#2161)

This commit is contained in:
James Frowen 2020-08-16 11:22:12 +01:00 committed by GitHub
parent 799e85a2e6
commit aa49c54dd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 62 additions and 65 deletions

View File

@ -144,7 +144,7 @@ static void OnCompilationFinished(string assemblyPath, CompilerMessage[] message
HashSet<string> 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;

View File

@ -0,0 +1,20 @@
using System;
namespace Mirror.Weaver
{
public static class Log
{
public static Action<string> WarningMethod;
public static Action<string> ErrorMethod;
public static void Warning(string msg)
{
WarningMethod(msg);
}
public static void Error(string msg)
{
ErrorMethod(msg);
}
}
}

View File

@ -1,62 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
namespace Mirror.Weaver
{
public static class Log
{
public static Action<string> WarningMethod;
public static Action<string> 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<string> printWarning, Action<string> 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<string> 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);
}
}
}
}

View File

@ -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<string> assemblies, IEnumerable<string> dependencies, string outputDir, string unityEngineDLLPath, string mirrorNetDLLPath)
static bool WeaveAssemblies(IEnumerable<string> assemblies, IEnumerable<string> dependencies, string outputDir, string unityEngineDLLPath, string mirrorNetDLLPath)
{
WeavingFailed = false;
WeaveLists = new WeaverLists();
@ -387,5 +387,44 @@ public static bool WeaveAssemblies(IEnumerable<string> assemblies, IEnumerable<s
}
return true;
}
public static bool Process(string unityEngine, string netDLL, string outputDirectory, string[] assemblies, string[] extraAssemblyPaths, Action<string> printWarning, Action<string> 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<string> 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);
}
}
}
}