Files
UnrealEngineUWP/Engine/Source/Programs/AutomationTool/AutomationUtils/UBTUtils.cs
andrew grant 499f555538 Restore 21213169
Improvements to BenchmarkBuild script.
- Added -editor-startup and -editor-game options to measure startup and startup time with -game
- Renamed -pie to -editor-pie to match other editor options-
- Allow different editor tests to use different sets of maps via -editor-startup=map2+map2, -editor-pie=map1+map2 etc
- Added AllEditor option to run all editor benchmarking
- Added -coldddc-noshared DDC option
- BenchmarkBuild now defaults to cleaning each targets after benchmarking its build time to save disk space (disable with -nopostclean)
- Moved Editor benchmark tests into separate files and reduced some duplicated code
- Updated help info

Other
- Fixed UAT GetProjectProperties returning inaccurate values if called twice with different platforms
- Doubled number of UBT logs that can be generated from a single UAT script
- Allow scripts to call UnrealBuild.CleanWithUBT to perform cleanup
- Simplified a lot of code

#rb na

#ROBOMERGE-AUTHOR: andrew.grant
#ROBOMERGE-SOURCE: CL 21213895 via CL 21213903 via CL 21213910 via CL 21214414 via CL 21214472
#ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v972-20964824)

[CL 21214930 by andrew grant in ue5-main branch]
2022-07-22 00:56:39 -04:00

154 lines
6.8 KiB
C#

// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EpicGames.Core;
using UnrealBuildBase;
using UnrealBuildTool;
namespace AutomationTool
{
public partial class CommandUtils
{
/// <summary>
/// Runs UBT with the specified commandline. Automatically creates a logfile. When
/// no LogName is specified, the executable name is used as logfile base name.
/// </summary>
/// <param name="Env">Environment to use.</param>
/// <param name="CommandLine">Commandline to pass on to UBT.</param>
/// <param name="LogName">Optional logfile name.</param>
[Obsolete("Deprecated in UE5.1; function signature has changed")]
public static void RunUBT(CommandEnvironment Env, string UBTExecutable, string CommandLine)
{
if (!FileExists(UBTExecutable))
{
throw new AutomationException("Unable to find UBT executable: " + UBTExecutable);
}
string BaseLogName = String.Format("UBT-{0}", String.Join("-", SharedUtils.ParseCommandLine(CommandLine).Where(x => !x.Contains('/') && !x.Contains('\\') && !x.StartsWith("-"))));
string LogName;
for(int Attempt = 1;;Attempt++)
{
LogName = String.Format("{0}.txt", (Attempt == 1)? BaseLogName : String.Format("{0}_{1}", BaseLogName, Attempt));
FileReference LogLocation = FileReference.Combine(new DirectoryReference(Env.LogFolder), LogName);
if(!FileReference.Exists(LogLocation))
{
CommandLine += String.Format(" -log=\"{0}\"", LogLocation);
break;
}
if (Attempt >= 100)
{
throw new AutomationException("Unable to find name for UBT log file {0} after {1} attempts", BaseLogName, Attempt);
}
}
IProcessResult Result = Run(UBTExecutable, CommandLine, Options: ERunOptions.AllowSpew | ERunOptions.NoStdOutCapture);
if(Result.ExitCode != 0)
{
throw new AutomationException((ExitCode)Result.ExitCode, "UnrealBuildTool failed. See log for more details. ({0})", CommandUtils.CombinePaths(Env.FinalLogFolder, LogName)) { OutputFormat = AutomationExceptionOutputFormat.Minimal };
}
}
/// <summary>
/// Runs UBT with the specified commandline. Automatically creates a logfile. When
/// no LogName is specified, the executable name is used as logfile base name.
/// </summary>
/// <param name="Env">Environment to use.</param>
/// <param name="CommandLine">Commandline to pass on to UBT.</param>
/// <param name="LogName">Optional logfile name.</param>
public static void RunUBT(CommandEnvironment Env, FileReference UnrealBuildToolDll, string CommandLine)
{
if (!FileReference.Exists(UnrealBuildToolDll))
{
throw new AutomationException($"Unable to find UnrealBuildTool.dll: {UnrealBuildToolDll}");
}
string BaseLogName = String.Format("UBT-{0}", String.Join("-", SharedUtils.ParseCommandLine(CommandLine).Where(x => !x.Contains('/') && !x.Contains('\\') && !x.StartsWith("-"))));
string LogName;
for(int Attempt = 1;;Attempt++)
{
LogName = String.Format("{0}.txt", (Attempt == 1)? BaseLogName : String.Format("{0}_{1}", BaseLogName, Attempt));
FileReference LogLocation = FileReference.Combine(new DirectoryReference(Env.LogFolder), LogName);
if(!FileReference.Exists(LogLocation))
{
CommandLine += String.Format(" -log=\"{0}\"", LogLocation);
break;
}
if (Attempt >= 50)
{
throw new AutomationException("Unable to find name for UBT log file after {0} attempts", Attempt);
}
}
CommandLine = $"\"{UnrealBuildToolDll}\" {CommandLine}";
IProcessResult Result = Run(Unreal.DotnetPath.FullName, CommandLine, Options: ERunOptions.AllowSpew | ERunOptions.NoStdOutCapture);
if(Result.ExitCode != 0)
{
throw new AutomationException((ExitCode)Result.ExitCode, "UnrealBuildTool failed. See log for more details. ({0})", CommandUtils.CombinePaths(Env.FinalLogFolder, LogName)) { OutputFormat = AutomationExceptionOutputFormat.Minimal };
}
}
/// <summary>
/// Builds a UBT Commandline.
/// </summary>
/// <param name="Project">Unreal project to build (optional)</param>
/// <param name="Target">Target to build.</param>
/// <param name="Platform">Platform to build for.</param>
/// <param name="Config">Configuration to build.</param>
/// <param name="AdditionalArgs">Additional arguments to pass on to UBT.</param>
public static string UBTCommandline(FileReference Project, string Target, UnrealTargetPlatform Platform, UnrealTargetConfiguration Config, string AdditionalArgs = "")
{
string CmdLine;
if (Project == null)
{
CmdLine = String.Format("{0} {1} {2} {3}", Target, Platform, Config, AdditionalArgs);
}
else
{
CmdLine = String.Format("{0} {1} {2} -Project={3} {4}", Target, Platform, Config, CommandUtils.MakePathSafeToUseWithCommandLine(Project.FullName), AdditionalArgs);
}
return CmdLine;
}
/// <summary>
/// Builds a target using UBT. Automatically creates a logfile. When
/// no LogName is specified, the executable name is used as logfile base name.
/// </summary>
/// <param name="Env">BuildEnvironment to use.</param>
/// <param name="Project">Unreal project to build (optional)</param>
/// <param name="Target">Target to build.</param>
/// <param name="Platform">Platform to build for.</param>
/// <param name="Config">Configuration to build.</param>
/// <param name="AdditionalArgs">Additional arguments to pass on to UBT.</param>
/// <param name="LogName">Optional logifle name.</param>
[Obsolete("Deprecated in UE5.1; Use the alternate version below with the UnrealBuildTool.dll, not executable")]
public static void RunUBT(CommandEnvironment Env, string UBTExecutable, FileReference Project, string Target, UnrealTargetPlatform Platform, UnrealTargetConfiguration Config, string AdditionalArgs = "")
{
RunUBT(Env, UBTExecutable, UBTCommandline(Project, Target, Platform, Config, AdditionalArgs));
}
/// <summary>
/// Builds a target using UBT. Automatically creates a logfile. When
/// no LogName is specified, the executable name is used as logfile base name.
/// </summary>
/// <param name="Env">BuildEnvironment to use.</param>
/// <param name="Project">Unreal project to build (optional)</param>
/// <param name="Target">Target to build.</param>
/// <param name="Platform">Platform to build for.</param>
/// <param name="Config">Configuration to build.</param>
/// <param name="AdditionalArgs">Additional arguments to pass on to UBT.</param>
/// <param name="LogName">Optional logifle name.</param>
public static void RunUBT(CommandEnvironment Env, FileReference UnrealBuildToolDll, FileReference Project, string Target, UnrealTargetPlatform Platform, UnrealTargetConfiguration Config, string AdditionalArgs = "")
{
RunUBT(Env, UnrealBuildToolDll, UBTCommandline(Project, Target, Platform, Config, AdditionalArgs));
}
}
}