ifdef out CompilationFinishedHook

This commit is contained in:
vis2k 2021-08-28 13:34:28 +08:00
parent 6d8fc523a7
commit 3ea5eb5d8d
4 changed files with 18 additions and 19 deletions

View File

@ -1,3 +1,6 @@
// for Unity 2020+ we use ILPostProcessor.
// only automatically invoke it for older versions.
#if !UNITY_2020_1_OR_NEWER
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@ -27,10 +30,6 @@ public static class CompilationFinishedHook
// controls weather Weaver errors are reported direct to the Unity console (tests enable this) // controls weather Weaver errors are reported direct to the Unity console (tests enable this)
public static bool UnityLogEnabled = true; public static bool UnityLogEnabled = true;
// for Unity 2020+ we use ILPostProcessor.
// only automatically invoke it for older versions.
// for newer versions, we still call CompilationFinished manually in tests.
#if !UNITY_2020_1_OR_NEWER
[InitializeOnLoadMethod] [InitializeOnLoadMethod]
public static void OnInitializeOnLoad() public static void OnInitializeOnLoad()
{ {
@ -64,7 +63,6 @@ public static void WeaveExistingAssemblies()
UnityEditorInternal.InternalEditorUtility.RequestScriptReload(); UnityEditorInternal.InternalEditorUtility.RequestScriptReload();
#endif #endif
} }
#endif
static Assembly FindCompilationPipelineAssembly(string assemblyName) => static Assembly FindCompilationPipelineAssembly(string assemblyName) =>
CompilationPipeline.GetAssemblies().First(assembly => assembly.name == assemblyName); CompilationPipeline.GetAssemblies().First(assembly => assembly.name == assemblyName);
@ -188,3 +186,4 @@ static bool WeaveFromFile(string assemblyPath, string[] dependencies)
} }
} }
} }
#endif

View File

@ -1,6 +1,7 @@
// logger for compilation finished hook. // logger for compilation finished hook.
// where we need a callback and Debug.Log. // where we need a callback and Debug.Log.
//#if !UNITY_2020_1_OR_NEWER <- still need it for tests in 2020+ // for Unity 2020+ we use ILPostProcessor.
#if !UNITY_2020_1_OR_NEWER
using Mono.CecilX; using Mono.CecilX;
using UnityEngine; using UnityEngine;
@ -27,4 +28,4 @@ public void Error(string message, MemberReference mr)
} }
} }
} }
//#endif #endif

View File

@ -115,14 +115,13 @@ public static void Build()
} }
#if UNITY_2020_1_OR_NEWER && UNITY_EDITOR_OSX #if UNITY_2020_1_OR_NEWER && UNITY_EDITOR_OSX
// on mac, AssemblyBuilder doesn't invoke ILPostProcessor after // CompilationFinishedHook weaves test pre Unity 2020.
// building. it does on windows though. // after Unity 2020, ILPostProcessor is invoked by AssemblyBuilder.
// // on mac, it is not invoked automatically.
// we need to weave manually here in 2020+. // need to do it manually until it's fixed by Unity.
// -> we have the assemblyPath
// -> simply use the from-file Assembly + Resolver from before. // TODO invoke ILPostProcessor manually
// TODO invoke ILPostProcessor for consistency with Windows tests // TODO save to file manually, so tests using the DLLs use the waved ones.
CompilationFinishedHook.OnCompilationFinished(assemblyPath, compilerMessages);
#endif #endif
}; };

View File

@ -45,8 +45,8 @@ protected void BuildAndWeaveTestAssembly(string className, string testName)
[OneTimeSetUp] [OneTimeSetUp]
public void FixtureSetup() public void FixtureSetup()
{ {
#if UNITY_2020_1_OR_NEWER && UNITY_EDITOR_OSX #if !UNITY_2020_1_OR_NEWER
// we still use CompilationFinishedHook to run tests in 2020+ on mac // CompilationFinishedHook is used for tests pre-2020 ILPostProcessor
CompilationFinishedHook.UnityLogEnabled = false; CompilationFinishedHook.UnityLogEnabled = false;
CompilationFinishedHook.OnWeaverError += HandleWeaverError; CompilationFinishedHook.OnWeaverError += HandleWeaverError;
CompilationFinishedHook.OnWeaverWarning += HandleWeaverWarning; CompilationFinishedHook.OnWeaverWarning += HandleWeaverWarning;
@ -56,8 +56,8 @@ public void FixtureSetup()
[OneTimeTearDown] [OneTimeTearDown]
public void FixtureCleanup() public void FixtureCleanup()
{ {
#if UNITY_2020_1_OR_NEWER && UNITY_EDITOR_OSX #if !UNITY_2020_1_OR_NEWER
// we still use CompilationFinishedHook to run tests in 2020+ on mac // CompilationFinishedHook is used for tests pre-2020 ILPostProcessor
CompilationFinishedHook.OnWeaverError -= HandleWeaverError; CompilationFinishedHook.OnWeaverError -= HandleWeaverError;
CompilationFinishedHook.OnWeaverWarning -= HandleWeaverWarning; CompilationFinishedHook.OnWeaverWarning -= HandleWeaverWarning;
CompilationFinishedHook.UnityLogEnabled = true; CompilationFinishedHook.UnityLogEnabled = true;