Skip to content

Instantly share code, notes, and snippets.

@andrewgrant
Created October 20, 2017 17:15
Show Gist options
  • Save andrewgrant/ac93bb56867bb5a3ef47ebcbc1c27cd6 to your computer and use it in GitHub Desktop.
Save andrewgrant/ac93bb56867bb5a3ef47ebcbc1c27cd6 to your computer and use it in GitHub Desktop.
Example of creating a UAT script for Unreal that leverages the BuildCookRun command. The Test/Run part is omitted because it's in a private project, but the "Run" part of BuildCookRun could be used instead
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using AutomationTool;
using UnrealBuildTool;
using Gauntlet;
using System.Net.NetworkInformation;
using static AutomationTool.P4Connection;
namespace OrionTest
{
/// <summary>
/// Performs Build+Cook+Pak+Stage+Test
/// </summary>
///
public class BuildCookTest : BuildCommand
{
/// <summary>
/// Checks that all of the required params are present, throws an exception if not
/// </summary>
/// <param name="Args"></param>
void CheckRequiredParams(params string[] Args)
{
foreach (string Arg in Args)
{
if (ParseParamValue(Arg, null) == null)
{
throw new AutomationException("Param {0} is missing but required. Required params are {1}", Arg, string.Join(",", Args));
}
}
}
/// <summary>
/// Main entrance point for this script
/// </summary>
/// <returns></returns>
public override ExitCode Execute()
{
// If no params, show usage flags
if (Params.Length == 0)
{
Console.WriteLine("Usage: BuildCookTest -platform=<plat> -configuration=<config> -test=<test> [-skipbuild -skipcook -skippak -skipcook -skipbc -skiptests -clean -iteratesharedbuild]");
return ExitCode.Success;
}
// check the essential params are present
CheckRequiredParams("platform", "configuration", "test");
// save off params here
string Platform = ParseParamValue("platform", null);
string Config = ParseParamValue("configuration", null);
string Test = ParseParamValue("test", null);
bool SkipSync = ParseParam("skipsync");
bool SkipBuild = ParseParam("skipbuild");
bool SkipCook = ParseParam("skipcook");
bool SkipBuildAndCook = ParseParam("skipbc") || (SkipBuild && SkipCook);
bool SkipTest = ParseParam("skiptest");
ExitCode Result = ExitCode.Success;
// Build/Cook status, assume success because we may skip this...
ExitCode BuildCookResult = ExitCode.Success;
if (SkipBuildAndCook == false)
{
BuildCookRun BCR = new BuildCookRun();
// basic arguments
string Args = string.Format("-project=OrionGame -platform={0} -config={1} -client -nocompile ", Platform, Config);
if (ParseParam("clean"))
{
Console.WriteLine("Cleaning Data");
Args += " -clean";
}
else
{
Args += " -iterate";
}
// UAT params are passed in as an array without the leading '-', so convert our command line to that
List<String> ArgList = Args.Split(' ').Select((string S) =>
{
if (S.Length > 0)
{
S = S.Substring(1);
}
return S;
}).ToList();
ArgList.AddRange(new string[] { "server", "serverplatform=Win64" });
//. Do build?
if (!SkipBuild)
{
if (!ParseParam("skipbuildclient") || !ParseParam("skipbuildeditor"))
{
ArgList.Add("build");
if (ParseParam("skipbuildclient"))
{
ArgList.Add("skipbuildclient");
}
if (ParseParam("skipbuildeditor"))
{
ArgList.Add("skipbuildeditor");
}
}
}
// Do cook? for the timebeing cooking is implicitly tied to pak/stage
if (SkipCook)
{
ArgList.AddRange(new string[] { "skipcook", "skippak", "skipstage", "nocompileeditor" });
}
else
{
ArgList.AddRange(new string[] { "cook", "pak", "stage" });
}
BCR.Params = ArgList.ToArray();
Console.WriteLine("Running: BuildCookRun " + BCR.Params);
BuildCookResult = BCR.Execute();
}
// If BuildCook succeeded, or was skipped
if (BuildCookResult == ExitCode.Success && SkipTest == false)
{
}
return Result;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment