mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
Weaver tests: compilationpipeline dependencies moved into Unity.Mirror.Weaver.CodeGen assembly.
so Tests assembly is actually weaved.
This commit is contained in:
parent
61d86b1e8d
commit
ec50f462bc
@ -0,0 +1,51 @@
|
||||
// helper function to use ILPostProcessor for an assembly from file.
|
||||
// we keep this in Weaver folder because we can access CompilationPipleine here.
|
||||
// in tests folder we can't, unless we rename to "Unity.*.CodeGen",
|
||||
// but then tests wouldn't be weaved anymore.
|
||||
using System;
|
||||
using System.IO;
|
||||
using Unity.CompilationPipeline.Common.Diagnostics;
|
||||
using Unity.CompilationPipeline.Common.ILPostProcessing;
|
||||
|
||||
namespace Mirror.Weaver
|
||||
{
|
||||
public static class ILPostProcessorFromFile
|
||||
{
|
||||
// read, weave, write file via ILPostProcessor
|
||||
public static void ILPostProcessFile(string assemblyPath, string[] references, Action<string> OnWarning, Action<string> OnError)
|
||||
{
|
||||
// we COULD Weave() with a test logger manually.
|
||||
// but for test result consistency on all platforms,
|
||||
// let's invoke the ILPostProcessor here too.
|
||||
CompiledAssemblyFromFile assembly = new CompiledAssemblyFromFile(assemblyPath);
|
||||
assembly.References = references;
|
||||
|
||||
// create ILPP and check WillProcess like Unity would.
|
||||
ILPostProcessorHook ilpp = new ILPostProcessorHook();
|
||||
if (ilpp.WillProcess(assembly))
|
||||
{
|
||||
//Debug.Log("Will Process: " + assembly.Name);
|
||||
|
||||
// process it like Unity would
|
||||
ILPostProcessResult result = ilpp.Process(assembly);
|
||||
|
||||
// handle the error messages like Unity would
|
||||
foreach (DiagnosticMessage message in result.Diagnostics)
|
||||
{
|
||||
if (message.DiagnosticType == DiagnosticType.Warning)
|
||||
{
|
||||
OnWarning(message.MessageData);
|
||||
}
|
||||
else if (message.DiagnosticType == DiagnosticType.Error)
|
||||
{
|
||||
OnError(message.MessageData);
|
||||
}
|
||||
}
|
||||
|
||||
// save the weaved assembly to file.
|
||||
// some tests open it and check for certain IL code.
|
||||
File.WriteAllBytes(assemblyPath, result.InMemoryAssembly.PeData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2a4b115486b74d27a9540f3c39ae2d46
|
||||
timeCreated: 1630152191
|
@ -3,8 +3,6 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Unity.CompilationPipeline.Common.Diagnostics;
|
||||
using Unity.CompilationPipeline.Common.ILPostProcessing;
|
||||
using UnityEditor.Compilation;
|
||||
using UnityEngine;
|
||||
|
||||
@ -126,10 +124,8 @@ public static void Build(Action<string> OnWarning, Action<string> OnError)
|
||||
// TODO invoke ILPostProcessor manually
|
||||
// TODO save to file manually, so tests using the DLLs use the waved ones.
|
||||
|
||||
// we COULD Weave() with a test logger manually.
|
||||
// but for test result consistency on all platforms,
|
||||
// let's invoke the ILPostProcessor here too.
|
||||
CompiledAssemblyFromFile assembly = new CompiledAssemblyFromFile(assemblyPath);
|
||||
|
||||
//
|
||||
// References needs to be set to something.
|
||||
// otherwise we get NullReferenceException in WillProcess while
|
||||
// checking References.
|
||||
@ -139,38 +135,15 @@ public static void Build(Action<string> OnWarning, Action<string> OnError)
|
||||
references.AddRange(assemblyBuilder.defaultReferences);
|
||||
if (assemblyBuilder.additionalReferences != null)
|
||||
references.AddRange(assemblyBuilder.additionalReferences);
|
||||
assembly.References = references.ToArray();
|
||||
|
||||
// create ILPP and check WillProcess like Unity would.
|
||||
ILPostProcessorHook ilpp = new ILPostProcessorHook();
|
||||
if (ilpp.WillProcess(assembly))
|
||||
{
|
||||
Debug.Log("Will Process: " + assembly.Name);
|
||||
|
||||
// process it like Unity would
|
||||
ILPostProcessResult result = ilpp.Process(assembly);
|
||||
|
||||
// handle the error messages like Unity would
|
||||
foreach (DiagnosticMessage message in result.Diagnostics)
|
||||
{
|
||||
if (message.DiagnosticType == DiagnosticType.Warning)
|
||||
{
|
||||
OnWarning(message.MessageData);
|
||||
}
|
||||
else if (message.DiagnosticType == DiagnosticType.Error)
|
||||
{
|
||||
OnError(message.MessageData);
|
||||
}
|
||||
}
|
||||
|
||||
// save the weaved assembly to file.
|
||||
// some tests open it and check for certain IL code.
|
||||
File.WriteAllBytes(assemblyPath, result.InMemoryAssembly.PeData);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("WONT PROCESS: " + assembly.Name);
|
||||
}
|
||||
// we COULD Weave() with a test logger manually.
|
||||
// but for test result consistency on all platforms,
|
||||
// let's invoke the ILPostProcessor here too.
|
||||
// NOTE: CompilationPipeline can only be imported if this
|
||||
// assembly's name is 'Unity.*.CodeGen'.
|
||||
// BUT: then this assembly itself isn't weaved.
|
||||
// we need it to be weaved for tests too though.
|
||||
ILPostProcessorFromFile.ILPostProcessFile(assemblyPath, references.ToArray(), OnWarning, OnError);
|
||||
#endif
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user