Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
Tweaked CI/CD builds (#779)
Browse files Browse the repository at this point in the history
* Test to see if we can set the il2cpp cache directory at build time

* fixed typo

* put it where it usually is

* Android already properly sets the cache directories, so we'll skip those

also seperate the arch verson caches as well

* just put in a subfolder so we can just cache the parent

* updated IL2CPP caching

* put a lock file in there

* moved build report up to command line method

updated UwpPlayerBuildTools to return the build report

* don't cache android as it has special cache directories defined

delete mabu cache before building lumin
  • Loading branch information
StephenHodgson authored Feb 8, 2021
1 parent 7693f63 commit e6659c3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 11 deletions.
47 changes: 39 additions & 8 deletions Editor/BuildAndDeploy/UnityPlayerBuildTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
using UnityEditor;
using UnityEditor.Build.Reporting;
using UnityEngine;
using XRTK.Extensions;
using XRTK.Editor.Utilities;
using XRTK.Editor.Utilities.SymbolicLinks;
using XRTK.Extensions;
using Debug = UnityEngine.Debug;

namespace XRTK.Editor.BuildAndDeploy
Expand Down Expand Up @@ -97,20 +97,43 @@ public static BuildReport BuildUnityPlayer(IBuildInfo buildInfo)

buildInfo.OutputDirectory = $"{buildInfo.OutputDirectory}/{PlayerSettings.productName}";

var cacheIl2Cpp = true;

switch (buildInfo.BuildTarget)
{
case BuildTarget.Lumin:
buildInfo.OutputDirectory += ".mpk";

if (Directory.Exists($"{Directory.GetParent(Application.dataPath)}\\Library\\Mabu"))
{
Directory.Delete($"{Directory.GetParent(Application.dataPath)}\\Library\\Mabu", true);
}
break;
case BuildTarget.Android:
buildInfo.OutputDirectory += ".apk";
cacheIl2Cpp = false;
break;
case BuildTarget.StandaloneWindows:
case BuildTarget.StandaloneWindows64:
buildInfo.OutputDirectory += ".exe";
break;
}

var prevIl2CppArgs = PlayerSettings.GetAdditionalIl2CppArgs();

if (cacheIl2Cpp)
{
var il2cppCache = $"{Directory.GetParent(Application.dataPath)}\\Library\\il2cpp_cache\\{buildInfo.BuildTarget}";

if (!Directory.Exists(il2cppCache))
{
Directory.CreateDirectory(il2cppCache);
}

File.WriteAllText($"{il2cppCache}\\xrtk.lock", string.Empty);
PlayerSettings.SetAdditionalIl2CppArgs($"--cachedirectory=\"{il2cppCache}\"");
}

BuildReport buildReport = default;

if (Application.isBatchMode)
Expand All @@ -134,6 +157,7 @@ public static BuildReport BuildUnityPlayer(IBuildInfo buildInfo)
Debug.LogError($"{e.Message}\n{e.StackTrace}");
}

PlayerSettings.SetAdditionalIl2CppArgs(prevIl2CppArgs);
PlayerSettings.colorSpace = oldColorSpace;

if (EditorUserBuildSettings.activeBuildTarget != oldBuildTarget)
Expand Down Expand Up @@ -201,7 +225,8 @@ public static async void StartCommandLineBuild()
Debug.Log($"Starting command line build for {EditorUserBuildSettings.activeBuildTarget}...");
EditorAssemblyReloadManager.LockReloadAssemblies = true;

bool success;
BuildReport buildReport = default;

try
{
SyncSolution();
Expand All @@ -215,24 +240,30 @@ public static async void StartCommandLineBuild()
switch (EditorUserBuildSettings.activeBuildTarget)
{
case BuildTarget.WSAPlayer:
success = await UwpPlayerBuildTools.BuildPlayer(new UwpBuildInfo(true));
buildReport = await UwpPlayerBuildTools.BuildPlayer(new UwpBuildInfo(true));
break;
default:
var buildInfo = new BuildInfo(true) as IBuildInfo;
ParseBuildCommandLine(ref buildInfo);
var buildResult = BuildUnityPlayer(buildInfo);
success = buildResult.summary.result == BuildResult.Succeeded;
buildReport = BuildUnityPlayer(buildInfo);
break;
}
}
catch (Exception e)
{
Debug.LogError($"Build Failed!\n{e.Message}\n{e.StackTrace}");
success = false;
}

Debug.Log($"Exiting command line build... Build success? {success}");
EditorApplication.Exit(success ? 0 : 1);
if (buildReport == null)
{
Debug.LogError("Failed to find a valid build report!");
EditorApplication.Exit(1);
}
else
{
Debug.Log($"Exiting command line build...\nBuild success? {buildReport.summary.result}\nBuild time: {buildReport.summary.totalTime:g}");
EditorApplication.Exit(buildReport.summary.result == BuildResult.Succeeded ? 0 : 1);
}
}

internal static bool CheckBuildScenes()
Expand Down
12 changes: 9 additions & 3 deletions Editor/BuildAndDeploy/UwpPlayerBuildTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading.Tasks;
using UnityEditor;
using UnityEditor.Build.Reporting;
using UnityEngine;
using XRTK.Editor.Utilities;

namespace XRTK.Editor.BuildAndDeploy
Expand Down Expand Up @@ -87,7 +88,7 @@ async void PostBuildAction(IBuildInfo innerBuildInfo, BuildReport buildReport)
/// </summary>
/// <param name="buildInfo"></param>
/// <param name="cancellationToken"></param>
public static async Task<bool> BuildPlayer(UwpBuildInfo buildInfo, CancellationToken cancellationToken = default)
public static async Task<BuildReport> BuildPlayer(UwpBuildInfo buildInfo, CancellationToken cancellationToken = default)
{
if (buildInfo.IsCommandLine)
{
Expand All @@ -99,10 +100,15 @@ public static async Task<bool> BuildPlayer(UwpBuildInfo buildInfo, CancellationT

if (success && buildInfo.BuildAppx)
{
success &= await UwpAppxBuildTools.BuildAppxAsync(buildInfo, cancellationToken);
success = await UwpAppxBuildTools.BuildAppxAsync(buildInfo, cancellationToken);

if (!success)
{
Debug.LogError("Failed to build Appx!");
}
}

return success;
return buildReport;
}
}
}

0 comments on commit e6659c3

Please sign in to comment.