Files
UnrealEngineUWP/Engine/Source/Programs/AutomationTool/Scripts/CookCommand.Automation.cs
Peter Sauerbrei 040aa73caf converted LauncherWorker to utilize a single UAT command
fixed problem with IP not being set for CotF
#ue4
#codereview daniel.lamb, chris.gagnon

[CL 2303312 by Peter Sauerbrei in Main branch]
2014-09-18 18:55:01 -04:00

159 lines
4.8 KiB
C#

// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Reflection;
using System.Linq;
using AutomationTool;
using UnrealBuildTool;
/// <summary>
/// Helper command used for cooking.
/// </summary>
/// <remarks>
/// Command line parameters used by this command:
/// -clean
/// </remarks>
public partial class Project : CommandUtils
{
#region Cook Command
public static void Cook(ProjectParams Params)
{
if ((!Params.Cook && !(Params.CookOnTheFly && !Params.SkipServer)) || Params.SkipCook)
{
return;
}
Params.ValidateAndLog();
Log("********** COOK COMMAND STARTED **********");
string UE4EditorExe = HostPlatform.Current.GetUE4ExePath(Params.UE4Exe);
if (!FileExists(UE4EditorExe))
{
throw new AutomationException("Missing " + UE4EditorExe + " executable. Needs to be built first.");
}
if (Params.CookOnTheFly && !Params.SkipServer)
{
if (Params.ClientTargetPlatforms.Count > 0)
{
var LogFolderOutsideOfSandbox = GetLogFolderOutsideOfSandbox();
if (!GlobalCommandLine.Installed)
{
// In the installed runs, this is the same folder as CmdEnv.LogFolder so delete only in not-installed
DeleteDirectory(LogFolderOutsideOfSandbox);
CreateDirectory(LogFolderOutsideOfSandbox);
}
var ServerLogFile = CombinePaths(LogFolderOutsideOfSandbox, "Server.log");
Platform ClientPlatformInst = Params.ClientTargetPlatformInstances[0];
string TargetCook = ClientPlatformInst.GetCookPlatform(false, Params.HasDedicatedServerAndClient, Params.CookFlavor);
ServerProcess = RunCookOnTheFlyServer(Params.RawProjectPath, Params.NoClient ? "" : ServerLogFile, TargetCook, Params.RunCommandline);
if (ServerProcess != null)
{
Log("Waiting a few seconds for the server to start...");
Thread.Sleep(5000);
}
}
else
{
throw new AutomationException("Failed to run, client target platform not specified");
}
}
else
{
var PlatformsToCook = new HashSet<string>();
if (!Params.NoClient)
{
foreach (var ClientPlatform in Params.ClientTargetPlatforms)
{
// Use the data platform, sometimes we will copy another platform's data
var DataPlatform = Params.GetCookedDataPlatformForClientTarget(ClientPlatform);
PlatformsToCook.Add(Params.GetTargetPlatformInstance(DataPlatform).GetCookPlatform(false, Params.HasDedicatedServerAndClient, Params.CookFlavor));
}
}
if (Params.DedicatedServer)
{
foreach (var ServerPlatform in Params.ServerTargetPlatforms)
{
// Use the data platform, sometimes we will copy another platform's data
var DataPlatform = Params.GetCookedDataPlatformForServerTarget(ServerPlatform);
PlatformsToCook.Add(Params.GetTargetPlatformInstance(DataPlatform).GetCookPlatform(true, false, Params.CookFlavor));
}
}
if (Params.Clean.HasValue && Params.Clean.Value && !Params.IterativeCooking)
{
Log("Cleaning cooked data.");
CleanupCookedData(PlatformsToCook.ToList(), Params);
}
// cook the set of maps, or the run map, or nothing
string[] Maps = null;
if (Params.HasMapsToCook)
{
Maps = Params.MapsToCook.ToArray();
}
string[] Dirs = null;
if (Params.HasDirectoriesToCook)
{
Dirs = Params.DirectoriesToCook.ToArray();
}
string[] Cultures = null;
if (Params.HasCulturesToCook)
{
Cultures = Params.CulturesToCook.ToArray();
}
try
{
var CommandletParams = "-buildmachine -Unversioned -fileopenlog";
if (Params.UseDebugParamForEditorExe)
{
CommandletParams += " -debug";
}
if (Params.Manifests)
{
CommandletParams += " -manifests";
}
if (Params.IterativeCooking)
{
CommandletParams += " -iterate";
}
CookCommandlet(Params.RawProjectPath, Params.UE4Exe, Maps, Dirs, Cultures, CombineCommandletParams(PlatformsToCook.ToArray()), CommandletParams);
}
catch (Exception Ex)
{
// Delete cooked data (if any) as it may be incomplete / corrupted.
Log("Cook failed. Deleting cooked data.");
CleanupCookedData(PlatformsToCook.ToList(), Params);
AutomationTool.ErrorReporter.Error("Cook failed.", (int)AutomationTool.ErrorCodes.Error_UnknownCookFailure);
throw Ex;
}
}
Log("********** COOK COMMAND COMPLETED **********");
}
private static void CleanupCookedData(List<string> PlatformsToCook, ProjectParams Params)
{
var ProjectPath = Path.GetFullPath(Params.RawProjectPath);
var CookedSandboxesPath = CombinePaths(GetDirectoryName(ProjectPath), "Saved", "Cooked");
var CleanDirs = new string[PlatformsToCook.Count];
for (int DirIndex = 0; DirIndex < CleanDirs.Length; ++DirIndex)
{
CleanDirs[DirIndex] = CombinePaths(CookedSandboxesPath, PlatformsToCook[DirIndex]);
}
const bool bQuiet = true;
DeleteDirectory(bQuiet, CleanDirs);
}
#endregion
}