fix: #2912 ILPostProcessor isn't used before 2020.3 because Unity bugs

This commit is contained in:
vis2k 2021-09-27 18:12:26 +08:00
parent 0d96636389
commit 8b5534f51f
8 changed files with 12 additions and 11 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -12,7 +12,7 @@
// ArraySegment<T> 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;

View File

@ -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;

View File

@ -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

View File

@ -103,7 +103,7 @@ public static void Build(Action<string> OnWarning, Action<string> 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<string> OnWarning, Action<string> 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()

View File

@ -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;