From 3ea5eb5d8d9abca3c20bd387209354afbc26c01c Mon Sep 17 00:00:00 2001 From: vis2k Date: Sat, 28 Aug 2021 13:34:28 +0800 Subject: [PATCH] ifdef out CompilationFinishedHook --- .../Weaver/EntryPoint/CompilationFinishedHook.cs | 9 ++++----- .../EntryPoint/CompilationFinishedLogger.cs | 5 +++-- .../Mirror/Tests/Editor/Weaver/WeaverAssembler.cs | 15 +++++++-------- Assets/Mirror/Tests/Editor/Weaver/WeaverTests.cs | 8 ++++---- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/Assets/Mirror/Editor/Weaver/EntryPoint/CompilationFinishedHook.cs b/Assets/Mirror/Editor/Weaver/EntryPoint/CompilationFinishedHook.cs index a63cf9aed..01ffff039 100644 --- a/Assets/Mirror/Editor/Weaver/EntryPoint/CompilationFinishedHook.cs +++ b/Assets/Mirror/Editor/Weaver/EntryPoint/CompilationFinishedHook.cs @@ -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.Collections.Generic; 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) 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] public static void OnInitializeOnLoad() { @@ -64,7 +63,6 @@ public static void WeaveExistingAssemblies() UnityEditorInternal.InternalEditorUtility.RequestScriptReload(); #endif } -#endif static Assembly FindCompilationPipelineAssembly(string assemblyName) => CompilationPipeline.GetAssemblies().First(assembly => assembly.name == assemblyName); @@ -188,3 +186,4 @@ static bool WeaveFromFile(string assemblyPath, string[] dependencies) } } } +#endif diff --git a/Assets/Mirror/Editor/Weaver/EntryPoint/CompilationFinishedLogger.cs b/Assets/Mirror/Editor/Weaver/EntryPoint/CompilationFinishedLogger.cs index d53597de9..7f782eec7 100644 --- a/Assets/Mirror/Editor/Weaver/EntryPoint/CompilationFinishedLogger.cs +++ b/Assets/Mirror/Editor/Weaver/EntryPoint/CompilationFinishedLogger.cs @@ -1,6 +1,7 @@ // logger for compilation finished hook. // 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 UnityEngine; @@ -27,4 +28,4 @@ public void Error(string message, MemberReference mr) } } } -//#endif +#endif diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverAssembler.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverAssembler.cs index 76fcca61b..e6e3da66a 100644 --- a/Assets/Mirror/Tests/Editor/Weaver/WeaverAssembler.cs +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverAssembler.cs @@ -115,14 +115,13 @@ public static void Build() } #if UNITY_2020_1_OR_NEWER && UNITY_EDITOR_OSX - // on mac, AssemblyBuilder doesn't invoke ILPostProcessor after - // building. it does on windows though. - // - // we need to weave manually here in 2020+. - // -> we have the assemblyPath - // -> simply use the from-file Assembly + Resolver from before. - // TODO invoke ILPostProcessor for consistency with Windows tests - CompilationFinishedHook.OnCompilationFinished(assemblyPath, compilerMessages); + // CompilationFinishedHook weaves test pre Unity 2020. + // after Unity 2020, ILPostProcessor is invoked by AssemblyBuilder. + // on mac, it is not invoked automatically. + // need to do it manually until it's fixed by Unity. + + // TODO invoke ILPostProcessor manually + // TODO save to file manually, so tests using the DLLs use the waved ones. #endif }; diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverTests.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverTests.cs index 4f5b53ca0..a5d467b74 100644 --- a/Assets/Mirror/Tests/Editor/Weaver/WeaverTests.cs +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverTests.cs @@ -45,8 +45,8 @@ protected void BuildAndWeaveTestAssembly(string className, string testName) [OneTimeSetUp] public void FixtureSetup() { -#if UNITY_2020_1_OR_NEWER && UNITY_EDITOR_OSX - // we still use CompilationFinishedHook to run tests in 2020+ on mac +#if !UNITY_2020_1_OR_NEWER + // CompilationFinishedHook is used for tests pre-2020 ILPostProcessor CompilationFinishedHook.UnityLogEnabled = false; CompilationFinishedHook.OnWeaverError += HandleWeaverError; CompilationFinishedHook.OnWeaverWarning += HandleWeaverWarning; @@ -56,8 +56,8 @@ public void FixtureSetup() [OneTimeTearDown] public void FixtureCleanup() { -#if UNITY_2020_1_OR_NEWER && UNITY_EDITOR_OSX - // we still use CompilationFinishedHook to run tests in 2020+ on mac +#if !UNITY_2020_1_OR_NEWER + // CompilationFinishedHook is used for tests pre-2020 ILPostProcessor CompilationFinishedHook.OnWeaverError -= HandleWeaverError; CompilationFinishedHook.OnWeaverWarning -= HandleWeaverWarning; CompilationFinishedHook.UnityLogEnabled = true;