From 8b5534f51fd998c6544ef7b5e81864bbd952ba9d Mon Sep 17 00:00:00 2001 From: vis2k Date: Mon, 27 Sep 2021 18:12:26 +0800 Subject: [PATCH] fix: #2912 ILPostProcessor isn't used before 2020.3 because Unity bugs --- .../Editor/Weaver/EntryPoint/CompilationFinishedHook.cs | 2 +- .../Editor/Weaver/EntryPoint/CompilationFinishedLogger.cs | 2 +- Assets/Mirror/Editor/Weaver/EntryPoint/EnterPlayModeHook.cs | 2 +- .../ILPostProcessorAssemblyResolver.cs | 2 +- .../EntryPointILPostProcessor/ILPostProcessorFromFile.cs | 2 +- .../Weaver/EntryPointILPostProcessor/ILPostProcessorHook.cs | 5 +++-- Assets/Mirror/Tests/Editor/Weaver/WeaverAssembler.cs | 4 ++-- Assets/Mirror/Tests/Editor/Weaver/WeaverTests.cs | 4 ++-- 8 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Assets/Mirror/Editor/Weaver/EntryPoint/CompilationFinishedHook.cs b/Assets/Mirror/Editor/Weaver/EntryPoint/CompilationFinishedHook.cs index 1c3860c12..93effbc4f 100644 --- a/Assets/Mirror/Editor/Weaver/EntryPoint/CompilationFinishedHook.cs +++ b/Assets/Mirror/Editor/Weaver/EntryPoint/CompilationFinishedHook.cs @@ -1,6 +1,6 @@ // for Unity 2020+ we use ILPostProcessor. // only automatically invoke it for older versions. -#if !UNITY_2020_1_OR_NEWER +#if !UNITY_2020_3_OR_NEWER using System; using System.Collections.Generic; using System.IO; diff --git a/Assets/Mirror/Editor/Weaver/EntryPoint/CompilationFinishedLogger.cs b/Assets/Mirror/Editor/Weaver/EntryPoint/CompilationFinishedLogger.cs index 7f782eec7..e05340484 100644 --- a/Assets/Mirror/Editor/Weaver/EntryPoint/CompilationFinishedLogger.cs +++ b/Assets/Mirror/Editor/Weaver/EntryPoint/CompilationFinishedLogger.cs @@ -1,7 +1,7 @@ // logger for compilation finished hook. // where we need a callback and Debug.Log. // for Unity 2020+ we use ILPostProcessor. -#if !UNITY_2020_1_OR_NEWER +#if !UNITY_2020_3_OR_NEWER using Mono.CecilX; using UnityEngine; diff --git a/Assets/Mirror/Editor/Weaver/EntryPoint/EnterPlayModeHook.cs b/Assets/Mirror/Editor/Weaver/EntryPoint/EnterPlayModeHook.cs index 48b6d6bbd..5dffa975e 100644 --- a/Assets/Mirror/Editor/Weaver/EntryPoint/EnterPlayModeHook.cs +++ b/Assets/Mirror/Editor/Weaver/EntryPoint/EnterPlayModeHook.cs @@ -1,4 +1,4 @@ -#if !UNITY_2020_1_OR_NEWER +#if !UNITY_2020_3_OR_NEWER // make sure we weaved successfully when entering play mode. using UnityEditor; using UnityEngine; diff --git a/Assets/Mirror/Editor/Weaver/EntryPointILPostProcessor/ILPostProcessorAssemblyResolver.cs b/Assets/Mirror/Editor/Weaver/EntryPointILPostProcessor/ILPostProcessorAssemblyResolver.cs index aeb226533..cbc8e4125 100644 --- a/Assets/Mirror/Editor/Weaver/EntryPointILPostProcessor/ILPostProcessorAssemblyResolver.cs +++ b/Assets/Mirror/Editor/Weaver/EntryPointILPostProcessor/ILPostProcessorAssemblyResolver.cs @@ -12,7 +12,7 @@ // ArraySegment in Mirror.Tests.Dll. // // we need a custom resolver for ILPostProcessor. -#if UNITY_2020_1_OR_NEWER +#if UNITY_2020_3_OR_NEWER using System; using System.Collections.Generic; using System.IO; diff --git a/Assets/Mirror/Editor/Weaver/EntryPointILPostProcessor/ILPostProcessorFromFile.cs b/Assets/Mirror/Editor/Weaver/EntryPointILPostProcessor/ILPostProcessorFromFile.cs index 2155b3827..6a706411e 100644 --- a/Assets/Mirror/Editor/Weaver/EntryPointILPostProcessor/ILPostProcessorFromFile.cs +++ b/Assets/Mirror/Editor/Weaver/EntryPointILPostProcessor/ILPostProcessorFromFile.cs @@ -2,7 +2,7 @@ // 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. -#if UNITY_2020_1_OR_NEWER +#if UNITY_2020_3_OR_NEWER using System; using System.IO; using Unity.CompilationPipeline.Common.Diagnostics; diff --git a/Assets/Mirror/Editor/Weaver/EntryPointILPostProcessor/ILPostProcessorHook.cs b/Assets/Mirror/Editor/Weaver/EntryPointILPostProcessor/ILPostProcessorHook.cs index 25ba6c0fe..0cfb43387 100644 --- a/Assets/Mirror/Editor/Weaver/EntryPointILPostProcessor/ILPostProcessorHook.cs +++ b/Assets/Mirror/Editor/Weaver/EntryPointILPostProcessor/ILPostProcessorHook.cs @@ -1,5 +1,6 @@ -// hook via ILPostProcessor from Unity 2020+ -#if UNITY_2020_1_OR_NEWER +// hook via ILPostProcessor from Unity 2020.3+ +// (2020.1 has errors https://github.com/vis2k/Mirror/issues/2912) +#if UNITY_2020_3_OR_NEWER // Unity.CompilationPipeline reference is only resolved if assembly name is // Unity.*.CodeGen: // https://forum.unity.com/threads/how-does-unity-do-codegen-and-why-cant-i-do-it-myself.853867/#post-5646937 diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverAssembler.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverAssembler.cs index d8b8025d9..1f4618a2f 100644 --- a/Assets/Mirror/Tests/Editor/Weaver/WeaverAssembler.cs +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverAssembler.cs @@ -103,7 +103,7 @@ public static void Build(Action OnWarning, Action OnError) assemblyBuilder.compilerOptions.AllowUnsafeCode = true; } -#if UNITY_2020_1_OR_NEWER +#if UNITY_2020_3_OR_NEWER // Unity automatically invokes ILPostProcessor after // AssemblyBuilder.Build() (on windows at least. not on mac). // => .buildFinished() below CompilerMessages would already contain @@ -134,7 +134,7 @@ public static void Build(Action OnWarning, Action OnError) } } -#if UNITY_2020_1_OR_NEWER +#if UNITY_2020_3_OR_NEWER // on 2018/2019, CompilationFinishedHook weaves after building. // on 2020, ILPostProcessor weaves after building. // on windows, it runs after AssemblyBuilder.Build() diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverTests.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverTests.cs index 347ea859c..8259249cb 100644 --- a/Assets/Mirror/Tests/Editor/Weaver/WeaverTests.cs +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverTests.cs @@ -45,7 +45,7 @@ protected void BuildAndWeaveTestAssembly(string className, string testName) [OneTimeSetUp] public void FixtureSetup() { -#if !UNITY_2020_1_OR_NEWER +#if !UNITY_2020_3_OR_NEWER // CompilationFinishedHook is used for tests pre-2020 ILPostProcessor CompilationFinishedHook.UnityLogEnabled = false; CompilationFinishedHook.OnWeaverError += HandleWeaverError; @@ -56,7 +56,7 @@ public void FixtureSetup() [OneTimeTearDown] public void FixtureCleanup() { -#if !UNITY_2020_1_OR_NEWER +#if !UNITY_2020_3_OR_NEWER // CompilationFinishedHook is used for tests pre-2020 ILPostProcessor CompilationFinishedHook.OnWeaverError -= HandleWeaverError; CompilationFinishedHook.OnWeaverWarning -= HandleWeaverWarning;