From dd61c08ba0e1cd4e968c95b84e2dfcdcb2eed498 Mon Sep 17 00:00:00 2001 From: Sean Parker Date: Tue, 21 Jul 2020 14:44:35 +0100 Subject: [PATCH] Prevent worker builds with compiler errors in Unity Editor (#1425) * Add CHANGELOG entry * Disable MenuBuild with editor compile errors * Fix codegen for Unity worker menu build * Generate one validation function for menu build --- CHANGELOG.md | 1 + .../BuildSystem/UnityWorkerMenuGenerator.cs | 11 +++++++++++ .../io.improbable.gdk.buildsystem/WorkerBuilder.cs | 1 - 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65077d9e87..95c8adb36d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Added - Added support for multiple annotations in Code Writer API. [#1427](https://github.com/spatialos/gdk-for-unity/pull/1427) +- Prevent building workers with Unity Editor compile errors. [#1425](https://github.com/spatialos/gdk-for-unity/pull/1425) ## `0.3.8` - 2020-07-20 diff --git a/workers/unity/Packages/io.improbable.gdk.buildsystem/.codegen/Source/Generators/BuildSystem/UnityWorkerMenuGenerator.cs b/workers/unity/Packages/io.improbable.gdk.buildsystem/.codegen/Source/Generators/BuildSystem/UnityWorkerMenuGenerator.cs index 93b04351ae..0c490db3b7 100644 --- a/workers/unity/Packages/io.improbable.gdk.buildsystem/.codegen/Source/Generators/BuildSystem/UnityWorkerMenuGenerator.cs +++ b/workers/unity/Packages/io.improbable.gdk.buildsystem/.codegen/Source/Generators/BuildSystem/UnityWorkerMenuGenerator.cs @@ -34,6 +34,9 @@ public static CodeWriter Generate(List workerTypes) return workerTypes.Select(workerType => $@"""{workerType}"""); }); + var allMenuOptionValidators = buildWorkerMenu.Annotate($@"MenuItem(EditorConfig.ParentMenu + ""/"" + LocalMenu + ""/All workers"", true, EditorConfig.MenuOffset + {workerTypes.Count})") + .Annotate($@"MenuItem(EditorConfig.ParentMenu + ""/"" + CloudMenu + ""/All workers"", true, EditorConfig.MenuOffset + {workerTypes.Count})"); + for (var i = 0; i < workerTypes.Count; i++) { var workerType = workerTypes[i]; @@ -50,8 +53,16 @@ public static CodeWriter Generate(List workerTypes) { $@"MenuBuildCloud(new[] {{ {workerTypeString} }});" }); + + allMenuOptionValidators.Annotate($@"MenuItem(EditorConfig.ParentMenu + ""/"" + LocalMenu + ""/{workerType}"", true, EditorConfig.MenuOffset + {i})") + .Annotate($@"MenuItem(EditorConfig.ParentMenu + ""/"" + CloudMenu + ""/{workerType}"", true, EditorConfig.MenuOffset + {i})"); } + allMenuOptionValidators.Method("public static bool ValidateEditorCompile()", () => new[] + { + "return !EditorUtility.scriptCompilationFailed;" + }); + buildWorkerMenu.Annotate($@"MenuItem(EditorConfig.ParentMenu + ""/"" + LocalMenu + ""/All workers"", false, EditorConfig.MenuOffset + {workerTypes.Count})") .Method("public static void BuildLocalAll()", () => new[] { diff --git a/workers/unity/Packages/io.improbable.gdk.buildsystem/WorkerBuilder.cs b/workers/unity/Packages/io.improbable.gdk.buildsystem/WorkerBuilder.cs index c3cc65eb75..79e25e0481 100644 --- a/workers/unity/Packages/io.improbable.gdk.buildsystem/WorkerBuilder.cs +++ b/workers/unity/Packages/io.improbable.gdk.buildsystem/WorkerBuilder.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using Improbable.Gdk.BuildSystem.Configuration; using Improbable.Gdk.Core; using Improbable.Gdk.Tools;