Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit 3447cd6

Browse files
authored
Build System Tweaks (#706)
1 parent 9fbc6a2 commit 3447cd6

File tree

4 files changed

+56
-25
lines changed

4 files changed

+56
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
- Updated the `MobileWorkerConnector` to use the KCP network protocol by default.
2323
- Changed the `mobile_launch.json` config to use the new Runtime.
2424
- Updated all the launch configs to use the new Runtime.
25+
- Changed the way builds are processed in the Unity Editor. If you don't have build support for a particular target, that specific build target will be skipped rather than the whole build process cancelled.
2526

2627
### Fixed
2728

workers/unity/Packages/com.improbable.gdk.buildsystem/Util/BuildSupportChecker.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System.IO;
33
using System.Linq;
4+
using Improbable.Gdk.BuildSystem;
45
using Improbable.Gdk.BuildSystem.Configuration;
56
using UnityEditor;
67
using UnityEngine;
@@ -52,6 +53,25 @@ public static BuildTarget[] GetBuildTargetsMissingBuildSupport(params BuildTarge
5253
.ToArray();
5354
}
5455

56+
public static string[] FilterWorkerTypes(BuildEnvironment environment, string[] desiredWorkerTypes)
57+
{
58+
return desiredWorkerTypes.Where(wantedWorkerType =>
59+
{
60+
var buildTargetsForWorker =
61+
WorkerBuilder.GetBuildTargetsForWorkerForEnvironment(wantedWorkerType, environment);
62+
var buildTargetsMissingBuildSupport = GetBuildTargetsMissingBuildSupport(buildTargetsForWorker);
63+
64+
if (buildTargetsMissingBuildSupport.Length > 0)
65+
{
66+
Debug.LogError(ConstructMissingSupportMessage(wantedWorkerType,
67+
environment, buildTargetsMissingBuildSupport));
68+
return false;
69+
}
70+
71+
return true;
72+
}).ToArray();
73+
}
74+
5575
public static string ConstructMissingSupportMessage(string workerType, BuildEnvironment environment,
5676
BuildTarget[] buildTargetsMissingBuildSupport)
5777
{

workers/unity/Packages/com.improbable.gdk.buildsystem/WorkerBuilder.cs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,18 @@ public static void Build()
5353
CommandLineUtility.GetCommandLineValue(commandLine, BuildWorkerTypes,
5454
"UnityClient,UnityGameLogic");
5555

56-
var wantedWorkerTypes = workerTypesArg.Split(',');
57-
foreach (var wantedWorkerType in wantedWorkerTypes)
58-
{
59-
var buildTargetsForWorker = GetBuildTargetsForWorkerForEnvironment(wantedWorkerType, buildEnvironment);
60-
var buildTargetsMissingBuildSupport = BuildSupportChecker.GetBuildTargetsMissingBuildSupport(buildTargetsForWorker);
56+
var desiredWorkerTypes = workerTypesArg.Split(',');
57+
var filteredWorkerTypes = BuildSupportChecker.FilterWorkerTypes(buildEnvironment, desiredWorkerTypes);
6158

62-
if (buildTargetsMissingBuildSupport.Length > 0)
63-
{
64-
throw new BuildFailedException(BuildSupportChecker.ConstructMissingSupportMessage(wantedWorkerType, buildEnvironment, buildTargetsMissingBuildSupport));
65-
}
59+
if (desiredWorkerTypes.Length != filteredWorkerTypes.Length)
60+
{
61+
throw new BuildFailedException(
62+
"Unable to complete build. Missing build support. Check logs for specific errors.");
6663
}
6764

6865
ScriptingImplementation scriptingBackend;
69-
var wantedScriptingBackend = CommandLineUtility.GetCommandLineValue(commandLine, "scriptingBackend", "mono");
66+
var wantedScriptingBackend =
67+
CommandLineUtility.GetCommandLineValue(commandLine, "scriptingBackend", "mono");
7068
switch (wantedScriptingBackend)
7169
{
7270
case "mono":
@@ -81,7 +79,7 @@ public static void Build()
8179

8280
LocalLaunch.BuildConfig();
8381

84-
foreach (var wantedWorkerType in wantedWorkerTypes)
82+
foreach (var wantedWorkerType in filteredWorkerTypes)
8583
{
8684
BuildWorkerForEnvironment(wantedWorkerType, buildEnvironment, scriptingBackend);
8785
}
@@ -98,9 +96,11 @@ public static void Build()
9896
}
9997
}
10098

101-
public static BuildTarget[] GetBuildTargetsForWorkerForEnvironment(string workerType, BuildEnvironment targetEnvironment)
99+
public static BuildTarget[] GetBuildTargetsForWorkerForEnvironment(string workerType,
100+
BuildEnvironment targetEnvironment)
102101
{
103-
var environmentConfig = SpatialOSBuildConfiguration.GetInstance().GetEnvironmentConfigForWorker(workerType, targetEnvironment);
102+
var environmentConfig = SpatialOSBuildConfiguration.GetInstance()
103+
.GetEnvironmentConfigForWorker(workerType, targetEnvironment);
104104
if (environmentConfig == null)
105105
{
106106
return new BuildTarget[0];
@@ -109,10 +109,12 @@ public static BuildTarget[] GetBuildTargetsForWorkerForEnvironment(string worker
109109
return GetUnityBuildTargets(environmentConfig.BuildPlatforms);
110110
}
111111

112-
public static void BuildWorkerForEnvironment(string workerType, BuildEnvironment targetEnvironment, ScriptingImplementation? scriptingBackend = null)
112+
public static void BuildWorkerForEnvironment(string workerType, BuildEnvironment targetEnvironment,
113+
ScriptingImplementation? scriptingBackend = null)
113114
{
114115
var spatialOSBuildConfiguration = SpatialOSBuildConfiguration.GetInstance();
115-
var environmentConfig = spatialOSBuildConfiguration.GetEnvironmentConfigForWorker(workerType, targetEnvironment);
116+
var environmentConfig =
117+
spatialOSBuildConfiguration.GetEnvironmentConfigForWorker(workerType, targetEnvironment);
116118
if (environmentConfig == null)
117119
{
118120
Debug.LogWarning($"Skipping build for {workerType}.");
@@ -149,7 +151,6 @@ public static void BuildWorkerForEnvironment(string workerType, BuildEnvironment
149151
{
150152
PlayerSettings.SetScriptingBackend(buildTargetGroup, activeScriptingBackend);
151153
}
152-
153154
}
154155
}
155156

@@ -222,7 +223,8 @@ internal static SpatialBuildPlatforms GetCurrentBuildPlatform()
222223
private static void BuildWorkerForTarget(string workerType, BuildTarget buildTarget,
223224
BuildOptions buildOptions, BuildEnvironment targetEnvironment)
224225
{
225-
Debug.Log($"Building \"{buildTarget}\" for worker platform: \"{workerType}\", environment: \"{targetEnvironment}\"");
226+
Debug.Log(
227+
$"Building \"{buildTarget}\" for worker platform: \"{workerType}\", environment: \"{targetEnvironment}\"");
226228

227229
var spatialOSBuildConfiguration = SpatialOSBuildConfiguration.GetInstance();
228230
var workerBuildData = new WorkerBuildData(workerType, buildTarget);

workers/unity/Packages/com.improbable.gdk.tools/.CodeGenerator/GdkCodeGenerator/Templates/UnityWorkerMenuGenerator.tt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#>
77
<#= generatedHeader #>
88

9+
using System.Linq;
910
using Improbable.Gdk.BuildSystem;
1011
using Improbable.Gdk.BuildSystem.Configuration;
1112
using Improbable.Gdk.Tools;
@@ -90,23 +91,30 @@ var workerType = workerTypeList[i];
9091
// Delaying build by a frame to ensure the editor has re-rendered the UI to avoid odd glitches.
9192
EditorApplication.delayCall += () =>
9293
{
93-
if (!CheckWorkersCanBuildForEnvironment(environment, workerTypes))
94-
{
95-
DisplayBuildFailureDialog();
96-
97-
return;
98-
}
94+
var filteredWorkerTypes = BuildSupportChecker.FilterWorkerTypes(environment, workerTypes);
9995

10096
try
10197
{
10298
LocalLaunch.BuildConfig();
10399

104-
foreach (var workerType in workerTypes)
100+
foreach (var workerType in filteredWorkerTypes)
105101
{
106102
WorkerBuilder.BuildWorkerForEnvironment(workerType, environment);
107103
}
108104

109-
Debug.LogFormat("Completed build for {0} target", environment);
105+
if (workerTypes.Length == filteredWorkerTypes.Length)
106+
{
107+
Debug.Log($"Completed build for {environment} target.");
108+
}
109+
else
110+
{
111+
var missingWorkerTypes = string.Join(" ", workerTypes.Except(filteredWorkerTypes));
112+
var completedWorkerTypes = string.Join(" ", workerTypes.Intersect(filteredWorkerTypes));
113+
Debug.LogWarning(
114+
$"Completed build for {environment} target.\n"
115+
+ $"Completed builds for: {completedWorkerTypes}\n"
116+
+ $"Skipped builds for: {missingWorkerTypes}. See above for more information.");
117+
}
110118
}
111119
catch (System.Exception)
112120
{

0 commit comments

Comments
 (0)