Files
UnrealEngineUWP/Engine/Source/Programs/AutomationTool/Program.cs

183 lines
6.2 KiB
C#
Raw Normal View History

// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
// This software is provided "as-is," without any express or implied warranty.
// In no event shall the author, nor Epic Games, Inc. be held liable for any damages arising from the use of this software.
// This software will not be supported.
// Use at your own risk.
using System;
using System.Threading;
using System.Diagnostics;
using UnrealBuildTool;
using System.Reflection;
namespace AutomationTool
{
// NOTE: this needs to be kept in sync with EditorAnalytics.h and iPhonePackager.cs
public enum ErrorCodes
{
Error_UATNotFound = -1,
Error_Success = 0,
Error_Unknown = 1,
Error_Arguments = 2,
Error_UnknownCommand = 3,
Error_SDKNotFound = 10,
Error_ProvisionNotFound = 11,
Error_CertificateNotFound = 12,
Error_ProvisionAndCertificateNotFound = 13,
Error_InfoPListNotFound = 14,
Error_KeyNotFoundInPList = 15,
Error_ProvisionExpired = 16,
Error_CertificateExpired = 17,
Error_CertificateProvisionMismatch = 18,
Error_CodeUnsupported = 19,
Error_PluginsUnsupported = 20,
Error_UnknownCookFailure = 25,
Error_UnknownDeployFailure = 26,
Error_UnknownBuildFailure = 27,
Error_UnknownPackageFailure = 28,
Error_UnknownLaunchFailure = 29,
Error_StageMissingFile = 30,
Error_FailedToCreateIPA = 31,
Error_FailedToCodeSign = 32,
Error_DeviceBackupFailed = 33,
Error_AppUninstallFailed = 34,
Error_AppInstallFailed = 35,
Error_AppNotFound = 36,
Error_StubNotSignedCorrectly = 37,
Error_IPAMissingInfoPList = 38,
Error_DeleteFile = 39,
Error_DeleteDirectory = 40,
Error_CreateDirectory = 41,
Error_CopyFile = 42,
Error_OnlyOneObbFileSupported = 50,
Error_FailureGettingPackageInfo = 51,
Error_OnlyOneTargetConfigurationSupported = 52,
Error_ObbNotFound = 53,
Error_AndroidBuildToolsPathNotFound = 54,
Error_NoApkSuitableForArchitecture = 55,
Error_LauncherFailed = 100,
Error_UATLaunchFailure = 101,
Error_FailedToDeleteStagingDirectory = 102,
Error_MissingExecutable = 103,
};
public class ErrorReporter
{
static public void Error(string Line, int Code = 1)
{
if (Program.ReturnCode == 0)
{
Program.ReturnCode = Code;
}
Console.ForegroundColor = ConsoleColor.Red;
Log.WriteLine(TraceEventType.Error, "AutomationTool error: " + Line);
Console.ResetColor();
}
};
public class Program
{
// This needs to be static, otherwise SetConsoleCtrlHandler will result in a crash on exit.
static ProcessManager.CtrlHandlerDelegate ProgramCtrlHandler = new ProcessManager.CtrlHandlerDelegate(CtrlHandler);
static public int ReturnCode = 0;
[STAThread]
public static int Main()
{
var CommandLine = SharedUtils.ParseCommandLine();
HostPlatform.Initialize();
LogUtils.InitLogging(CommandLine);
UBT Utils.cs (New logging system) * Allows us to use built-in Trace providers (console, file, etc) directly and still use our custom formatting. * Fat comments explaining why Trace.WriteXXX functions should not be used directly in our system. * Fixes thread safety by using Trace.WriteXXX under the hood after formatting, which uses a global lock (except on Mono, where a bug appears to be preventing this. Simulating the call on that platform). * No need for TraceEvent overloads, which saves us the extra parameter cruft. * Removed non-varargs overloads of Log functions (technically a bit slower, but these are already small messages). * No longer needed VerbosityFilter and ConsoleListener classes. * Avoid calling GetSource() if we aren't outputting the source. * Avoid formatting the string if it won't pass the verbosity level. * Consolidated all of UAT and UBT options into this class, so they could fully share the implementation. UBT BuildConfiguration.cs * Added LogFilename (and --log=<file> arg) that enables logging to a file. * Added static ctor guard that asserts if someone tries to read a config before we have loaded config files and parsed config-override commandlines. It's a poor man's hack, but better than nothing! UBT UEBuildConfiguration.cs * Same static ctor guard as above. UBT UnrealBuildTools.cs (initialization refactoring) * In general I tried to de-mystify some of the rationale behind our startup code via fat comments. * Broke main into 3 stages: 1. "early code" that should not try to read a config value. * Very little code here. Mostly setting the current directory. * Does an early init of logging to ensure logging is around, but config values won't be ready. 2. "Init Configuration code" that loads config files and parses command lines that may override them. * I isolated two locations in startup that parsed long sets of switches and moved ones that trivially affected BuildConfiguration and UEBuildConfiguration in here. Those two locations seemed to have mostly copies of the same switches, indicating serious param parsing issues at some point in time. * This allows switches to override config files more easily than the patchwork of re-parsing that was currently used (particularly for -verbose). * I did a cursory examination of later code that indicated this double (actually, triple) parsing was no longer necessary with the refactors above. Any insight into why things may have ended up this way would be helpful. 3. "Post Init code" that is actually the meat of UBT. * I left this code largely untouched. * Removed 2 of 3 different command line logging statements. * Removed two redundant parses of config overrides (ParseBuildConfigurationFlags). * Guarded all of main in a try/catch block to ensure no exceptions can leak from UBT without returning a valid error code. It ALMOST already did this, but only covered the part surrounded by the Mutex. * There was a perplexing bit that redundantly called XmlConfigLoader.Reset<> (line 683) that I struggled to understand. It turns out UEBuildConfiguration was sensitive to the current directory being set before files were loaded, and the old code called XmlConfigLoader.Init() super early, which required it to be called again after the current directory was set (see UEBuldConfiguration.UEThirdPartySourceDirectory for the cause). After my changes, I verified as best I could that these calls are no longer needed and removed them. XmlConfigLoader.cs * Add support for Properties in XmlConfigLoader. AutomationTool Program.cs * Guard logging shutdown code in try/finally so it can't be missed. AutomationTool Log.cs * Uses new logging system from UBT * Removed unnecessary classes (VerbosityFilter, AutomationConsoleTraceListener, and AutomationFileTraceListener) * Console trace logic is handled by UBT code now, moved UTF8Output handling to InitLogging. * A custom TraceListener for file logging was unnecessary. * Logic to handle creating the log file and retry loops was move into InitLogging, and the result passed to a regular TextFileTraceListener. * Logic to handle copying the log on shutdown was moved to a ShutdownLogging function. #codereview:robert.manuszewski,michael.trepka,kellan.carr [CL 2526245 by Wes Hunt in Main branch]
2015-04-26 18:19:28 -04:00
try
{
Log.WriteLine(TraceEventType.Information, "Running on {0}", HostPlatform.Current.GetType().Name);
UBT Utils.cs (New logging system) * Allows us to use built-in Trace providers (console, file, etc) directly and still use our custom formatting. * Fat comments explaining why Trace.WriteXXX functions should not be used directly in our system. * Fixes thread safety by using Trace.WriteXXX under the hood after formatting, which uses a global lock (except on Mono, where a bug appears to be preventing this. Simulating the call on that platform). * No need for TraceEvent overloads, which saves us the extra parameter cruft. * Removed non-varargs overloads of Log functions (technically a bit slower, but these are already small messages). * No longer needed VerbosityFilter and ConsoleListener classes. * Avoid calling GetSource() if we aren't outputting the source. * Avoid formatting the string if it won't pass the verbosity level. * Consolidated all of UAT and UBT options into this class, so they could fully share the implementation. UBT BuildConfiguration.cs * Added LogFilename (and --log=<file> arg) that enables logging to a file. * Added static ctor guard that asserts if someone tries to read a config before we have loaded config files and parsed config-override commandlines. It's a poor man's hack, but better than nothing! UBT UEBuildConfiguration.cs * Same static ctor guard as above. UBT UnrealBuildTools.cs (initialization refactoring) * In general I tried to de-mystify some of the rationale behind our startup code via fat comments. * Broke main into 3 stages: 1. "early code" that should not try to read a config value. * Very little code here. Mostly setting the current directory. * Does an early init of logging to ensure logging is around, but config values won't be ready. 2. "Init Configuration code" that loads config files and parses command lines that may override them. * I isolated two locations in startup that parsed long sets of switches and moved ones that trivially affected BuildConfiguration and UEBuildConfiguration in here. Those two locations seemed to have mostly copies of the same switches, indicating serious param parsing issues at some point in time. * This allows switches to override config files more easily than the patchwork of re-parsing that was currently used (particularly for -verbose). * I did a cursory examination of later code that indicated this double (actually, triple) parsing was no longer necessary with the refactors above. Any insight into why things may have ended up this way would be helpful. 3. "Post Init code" that is actually the meat of UBT. * I left this code largely untouched. * Removed 2 of 3 different command line logging statements. * Removed two redundant parses of config overrides (ParseBuildConfigurationFlags). * Guarded all of main in a try/catch block to ensure no exceptions can leak from UBT without returning a valid error code. It ALMOST already did this, but only covered the part surrounded by the Mutex. * There was a perplexing bit that redundantly called XmlConfigLoader.Reset<> (line 683) that I struggled to understand. It turns out UEBuildConfiguration was sensitive to the current directory being set before files were loaded, and the old code called XmlConfigLoader.Init() super early, which required it to be called again after the current directory was set (see UEBuldConfiguration.UEThirdPartySourceDirectory for the cause). After my changes, I verified as best I could that these calls are no longer needed and removed them. XmlConfigLoader.cs * Add support for Properties in XmlConfigLoader. AutomationTool Program.cs * Guard logging shutdown code in try/finally so it can't be missed. AutomationTool Log.cs * Uses new logging system from UBT * Removed unnecessary classes (VerbosityFilter, AutomationConsoleTraceListener, and AutomationFileTraceListener) * Console trace logic is handled by UBT code now, moved UTF8Output handling to InitLogging. * A custom TraceListener for file logging was unnecessary. * Logic to handle creating the log file and retry loops was move into InitLogging, and the result passed to a regular TextFileTraceListener. * Logic to handle copying the log on shutdown was moved to a ShutdownLogging function. #codereview:robert.manuszewski,michael.trepka,kellan.carr [CL 2526245 by Wes Hunt in Main branch]
2015-04-26 18:19:28 -04:00
XmlConfigLoader.Init();
UBT Utils.cs (New logging system) * Allows us to use built-in Trace providers (console, file, etc) directly and still use our custom formatting. * Fat comments explaining why Trace.WriteXXX functions should not be used directly in our system. * Fixes thread safety by using Trace.WriteXXX under the hood after formatting, which uses a global lock (except on Mono, where a bug appears to be preventing this. Simulating the call on that platform). * No need for TraceEvent overloads, which saves us the extra parameter cruft. * Removed non-varargs overloads of Log functions (technically a bit slower, but these are already small messages). * No longer needed VerbosityFilter and ConsoleListener classes. * Avoid calling GetSource() if we aren't outputting the source. * Avoid formatting the string if it won't pass the verbosity level. * Consolidated all of UAT and UBT options into this class, so they could fully share the implementation. UBT BuildConfiguration.cs * Added LogFilename (and --log=<file> arg) that enables logging to a file. * Added static ctor guard that asserts if someone tries to read a config before we have loaded config files and parsed config-override commandlines. It's a poor man's hack, but better than nothing! UBT UEBuildConfiguration.cs * Same static ctor guard as above. UBT UnrealBuildTools.cs (initialization refactoring) * In general I tried to de-mystify some of the rationale behind our startup code via fat comments. * Broke main into 3 stages: 1. "early code" that should not try to read a config value. * Very little code here. Mostly setting the current directory. * Does an early init of logging to ensure logging is around, but config values won't be ready. 2. "Init Configuration code" that loads config files and parses command lines that may override them. * I isolated two locations in startup that parsed long sets of switches and moved ones that trivially affected BuildConfiguration and UEBuildConfiguration in here. Those two locations seemed to have mostly copies of the same switches, indicating serious param parsing issues at some point in time. * This allows switches to override config files more easily than the patchwork of re-parsing that was currently used (particularly for -verbose). * I did a cursory examination of later code that indicated this double (actually, triple) parsing was no longer necessary with the refactors above. Any insight into why things may have ended up this way would be helpful. 3. "Post Init code" that is actually the meat of UBT. * I left this code largely untouched. * Removed 2 of 3 different command line logging statements. * Removed two redundant parses of config overrides (ParseBuildConfigurationFlags). * Guarded all of main in a try/catch block to ensure no exceptions can leak from UBT without returning a valid error code. It ALMOST already did this, but only covered the part surrounded by the Mutex. * There was a perplexing bit that redundantly called XmlConfigLoader.Reset<> (line 683) that I struggled to understand. It turns out UEBuildConfiguration was sensitive to the current directory being set before files were loaded, and the old code called XmlConfigLoader.Init() super early, which required it to be called again after the current directory was set (see UEBuldConfiguration.UEThirdPartySourceDirectory for the cause). After my changes, I verified as best I could that these calls are no longer needed and removed them. XmlConfigLoader.cs * Add support for Properties in XmlConfigLoader. AutomationTool Program.cs * Guard logging shutdown code in try/finally so it can't be missed. AutomationTool Log.cs * Uses new logging system from UBT * Removed unnecessary classes (VerbosityFilter, AutomationConsoleTraceListener, and AutomationFileTraceListener) * Console trace logic is handled by UBT code now, moved UTF8Output handling to InitLogging. * A custom TraceListener for file logging was unnecessary. * Logic to handle creating the log file and retry loops was move into InitLogging, and the result passed to a regular TextFileTraceListener. * Logic to handle copying the log on shutdown was moved to a ShutdownLogging function. #codereview:robert.manuszewski,michael.trepka,kellan.carr [CL 2526245 by Wes Hunt in Main branch]
2015-04-26 18:19:28 -04:00
// Log if we're running from the launcher
var ExecutingAssemblyLocation = CommandUtils.CombinePaths(Assembly.GetExecutingAssembly().Location);
if (String.Compare(ExecutingAssemblyLocation, CommandUtils.CombinePaths(InternalUtils.ExecutingAssemblyLocation), true) != 0)
{
Log.WriteLine(TraceEventType.Information, "Executed from AutomationToolLauncher ({0})", ExecutingAssemblyLocation);
}
Log.WriteLine(TraceEventType.Information, "CWD={0}", Environment.CurrentDirectory);
UBT Utils.cs (New logging system) * Allows us to use built-in Trace providers (console, file, etc) directly and still use our custom formatting. * Fat comments explaining why Trace.WriteXXX functions should not be used directly in our system. * Fixes thread safety by using Trace.WriteXXX under the hood after formatting, which uses a global lock (except on Mono, where a bug appears to be preventing this. Simulating the call on that platform). * No need for TraceEvent overloads, which saves us the extra parameter cruft. * Removed non-varargs overloads of Log functions (technically a bit slower, but these are already small messages). * No longer needed VerbosityFilter and ConsoleListener classes. * Avoid calling GetSource() if we aren't outputting the source. * Avoid formatting the string if it won't pass the verbosity level. * Consolidated all of UAT and UBT options into this class, so they could fully share the implementation. UBT BuildConfiguration.cs * Added LogFilename (and --log=<file> arg) that enables logging to a file. * Added static ctor guard that asserts if someone tries to read a config before we have loaded config files and parsed config-override commandlines. It's a poor man's hack, but better than nothing! UBT UEBuildConfiguration.cs * Same static ctor guard as above. UBT UnrealBuildTools.cs (initialization refactoring) * In general I tried to de-mystify some of the rationale behind our startup code via fat comments. * Broke main into 3 stages: 1. "early code" that should not try to read a config value. * Very little code here. Mostly setting the current directory. * Does an early init of logging to ensure logging is around, but config values won't be ready. 2. "Init Configuration code" that loads config files and parses command lines that may override them. * I isolated two locations in startup that parsed long sets of switches and moved ones that trivially affected BuildConfiguration and UEBuildConfiguration in here. Those two locations seemed to have mostly copies of the same switches, indicating serious param parsing issues at some point in time. * This allows switches to override config files more easily than the patchwork of re-parsing that was currently used (particularly for -verbose). * I did a cursory examination of later code that indicated this double (actually, triple) parsing was no longer necessary with the refactors above. Any insight into why things may have ended up this way would be helpful. 3. "Post Init code" that is actually the meat of UBT. * I left this code largely untouched. * Removed 2 of 3 different command line logging statements. * Removed two redundant parses of config overrides (ParseBuildConfigurationFlags). * Guarded all of main in a try/catch block to ensure no exceptions can leak from UBT without returning a valid error code. It ALMOST already did this, but only covered the part surrounded by the Mutex. * There was a perplexing bit that redundantly called XmlConfigLoader.Reset<> (line 683) that I struggled to understand. It turns out UEBuildConfiguration was sensitive to the current directory being set before files were loaded, and the old code called XmlConfigLoader.Init() super early, which required it to be called again after the current directory was set (see UEBuldConfiguration.UEThirdPartySourceDirectory for the cause). After my changes, I verified as best I could that these calls are no longer needed and removed them. XmlConfigLoader.cs * Add support for Properties in XmlConfigLoader. AutomationTool Program.cs * Guard logging shutdown code in try/finally so it can't be missed. AutomationTool Log.cs * Uses new logging system from UBT * Removed unnecessary classes (VerbosityFilter, AutomationConsoleTraceListener, and AutomationFileTraceListener) * Console trace logic is handled by UBT code now, moved UTF8Output handling to InitLogging. * A custom TraceListener for file logging was unnecessary. * Logic to handle creating the log file and retry loops was move into InitLogging, and the result passed to a regular TextFileTraceListener. * Logic to handle copying the log on shutdown was moved to a ShutdownLogging function. #codereview:robert.manuszewski,michael.trepka,kellan.carr [CL 2526245 by Wes Hunt in Main branch]
2015-04-26 18:19:28 -04:00
// Hook up exit callbacks
var Domain = AppDomain.CurrentDomain;
Domain.ProcessExit += Domain_ProcessExit;
Domain.DomainUnload += Domain_ProcessExit;
HostPlatform.Current.SetConsoleCtrlHandler(ProgramCtrlHandler);
UBT Utils.cs (New logging system) * Allows us to use built-in Trace providers (console, file, etc) directly and still use our custom formatting. * Fat comments explaining why Trace.WriteXXX functions should not be used directly in our system. * Fixes thread safety by using Trace.WriteXXX under the hood after formatting, which uses a global lock (except on Mono, where a bug appears to be preventing this. Simulating the call on that platform). * No need for TraceEvent overloads, which saves us the extra parameter cruft. * Removed non-varargs overloads of Log functions (technically a bit slower, but these are already small messages). * No longer needed VerbosityFilter and ConsoleListener classes. * Avoid calling GetSource() if we aren't outputting the source. * Avoid formatting the string if it won't pass the verbosity level. * Consolidated all of UAT and UBT options into this class, so they could fully share the implementation. UBT BuildConfiguration.cs * Added LogFilename (and --log=<file> arg) that enables logging to a file. * Added static ctor guard that asserts if someone tries to read a config before we have loaded config files and parsed config-override commandlines. It's a poor man's hack, but better than nothing! UBT UEBuildConfiguration.cs * Same static ctor guard as above. UBT UnrealBuildTools.cs (initialization refactoring) * In general I tried to de-mystify some of the rationale behind our startup code via fat comments. * Broke main into 3 stages: 1. "early code" that should not try to read a config value. * Very little code here. Mostly setting the current directory. * Does an early init of logging to ensure logging is around, but config values won't be ready. 2. "Init Configuration code" that loads config files and parses command lines that may override them. * I isolated two locations in startup that parsed long sets of switches and moved ones that trivially affected BuildConfiguration and UEBuildConfiguration in here. Those two locations seemed to have mostly copies of the same switches, indicating serious param parsing issues at some point in time. * This allows switches to override config files more easily than the patchwork of re-parsing that was currently used (particularly for -verbose). * I did a cursory examination of later code that indicated this double (actually, triple) parsing was no longer necessary with the refactors above. Any insight into why things may have ended up this way would be helpful. 3. "Post Init code" that is actually the meat of UBT. * I left this code largely untouched. * Removed 2 of 3 different command line logging statements. * Removed two redundant parses of config overrides (ParseBuildConfigurationFlags). * Guarded all of main in a try/catch block to ensure no exceptions can leak from UBT without returning a valid error code. It ALMOST already did this, but only covered the part surrounded by the Mutex. * There was a perplexing bit that redundantly called XmlConfigLoader.Reset<> (line 683) that I struggled to understand. It turns out UEBuildConfiguration was sensitive to the current directory being set before files were loaded, and the old code called XmlConfigLoader.Init() super early, which required it to be called again after the current directory was set (see UEBuldConfiguration.UEThirdPartySourceDirectory for the cause). After my changes, I verified as best I could that these calls are no longer needed and removed them. XmlConfigLoader.cs * Add support for Properties in XmlConfigLoader. AutomationTool Program.cs * Guard logging shutdown code in try/finally so it can't be missed. AutomationTool Log.cs * Uses new logging system from UBT * Removed unnecessary classes (VerbosityFilter, AutomationConsoleTraceListener, and AutomationFileTraceListener) * Console trace logic is handled by UBT code now, moved UTF8Output handling to InitLogging. * A custom TraceListener for file logging was unnecessary. * Logic to handle creating the log file and retry loops was move into InitLogging, and the result passed to a regular TextFileTraceListener. * Logic to handle copying the log on shutdown was moved to a ShutdownLogging function. #codereview:robert.manuszewski,michael.trepka,kellan.carr [CL 2526245 by Wes Hunt in Main branch]
2015-04-26 18:19:28 -04:00
var Version = InternalUtils.ExecutableVersion;
Log.WriteLine(TraceEventType.Verbose, "{0} ver. {1}", Version.ProductName, Version.ProductVersion);
UBT Utils.cs (New logging system) * Allows us to use built-in Trace providers (console, file, etc) directly and still use our custom formatting. * Fat comments explaining why Trace.WriteXXX functions should not be used directly in our system. * Fixes thread safety by using Trace.WriteXXX under the hood after formatting, which uses a global lock (except on Mono, where a bug appears to be preventing this. Simulating the call on that platform). * No need for TraceEvent overloads, which saves us the extra parameter cruft. * Removed non-varargs overloads of Log functions (technically a bit slower, but these are already small messages). * No longer needed VerbosityFilter and ConsoleListener classes. * Avoid calling GetSource() if we aren't outputting the source. * Avoid formatting the string if it won't pass the verbosity level. * Consolidated all of UAT and UBT options into this class, so they could fully share the implementation. UBT BuildConfiguration.cs * Added LogFilename (and --log=<file> arg) that enables logging to a file. * Added static ctor guard that asserts if someone tries to read a config before we have loaded config files and parsed config-override commandlines. It's a poor man's hack, but better than nothing! UBT UEBuildConfiguration.cs * Same static ctor guard as above. UBT UnrealBuildTools.cs (initialization refactoring) * In general I tried to de-mystify some of the rationale behind our startup code via fat comments. * Broke main into 3 stages: 1. "early code" that should not try to read a config value. * Very little code here. Mostly setting the current directory. * Does an early init of logging to ensure logging is around, but config values won't be ready. 2. "Init Configuration code" that loads config files and parses command lines that may override them. * I isolated two locations in startup that parsed long sets of switches and moved ones that trivially affected BuildConfiguration and UEBuildConfiguration in here. Those two locations seemed to have mostly copies of the same switches, indicating serious param parsing issues at some point in time. * This allows switches to override config files more easily than the patchwork of re-parsing that was currently used (particularly for -verbose). * I did a cursory examination of later code that indicated this double (actually, triple) parsing was no longer necessary with the refactors above. Any insight into why things may have ended up this way would be helpful. 3. "Post Init code" that is actually the meat of UBT. * I left this code largely untouched. * Removed 2 of 3 different command line logging statements. * Removed two redundant parses of config overrides (ParseBuildConfigurationFlags). * Guarded all of main in a try/catch block to ensure no exceptions can leak from UBT without returning a valid error code. It ALMOST already did this, but only covered the part surrounded by the Mutex. * There was a perplexing bit that redundantly called XmlConfigLoader.Reset<> (line 683) that I struggled to understand. It turns out UEBuildConfiguration was sensitive to the current directory being set before files were loaded, and the old code called XmlConfigLoader.Init() super early, which required it to be called again after the current directory was set (see UEBuldConfiguration.UEThirdPartySourceDirectory for the cause). After my changes, I verified as best I could that these calls are no longer needed and removed them. XmlConfigLoader.cs * Add support for Properties in XmlConfigLoader. AutomationTool Program.cs * Guard logging shutdown code in try/finally so it can't be missed. AutomationTool Log.cs * Uses new logging system from UBT * Removed unnecessary classes (VerbosityFilter, AutomationConsoleTraceListener, and AutomationFileTraceListener) * Console trace logic is handled by UBT code now, moved UTF8Output handling to InitLogging. * A custom TraceListener for file logging was unnecessary. * Logic to handle creating the log file and retry loops was move into InitLogging, and the result passed to a regular TextFileTraceListener. * Logic to handle copying the log on shutdown was moved to a ShutdownLogging function. #codereview:robert.manuszewski,michael.trepka,kellan.carr [CL 2526245 by Wes Hunt in Main branch]
2015-04-26 18:19:28 -04:00
try
{
// Don't allow simultaneous execution of AT (in the same branch)
ReturnCode = InternalUtils.RunSingleInstance(MainProc, CommandLine);
}
catch (Exception Ex)
{
Log.WriteLine(TraceEventType.Error, "AutomationTool terminated with exception:");
Log.WriteLine(TraceEventType.Error, LogUtils.FormatException(Ex));
Log.WriteLine(TraceEventType.Error, Ex.Message);
if (ReturnCode == 0)
{
ReturnCode = (int)ErrorCodes.Error_Unknown;
}
}
UBT Utils.cs (New logging system) * Allows us to use built-in Trace providers (console, file, etc) directly and still use our custom formatting. * Fat comments explaining why Trace.WriteXXX functions should not be used directly in our system. * Fixes thread safety by using Trace.WriteXXX under the hood after formatting, which uses a global lock (except on Mono, where a bug appears to be preventing this. Simulating the call on that platform). * No need for TraceEvent overloads, which saves us the extra parameter cruft. * Removed non-varargs overloads of Log functions (technically a bit slower, but these are already small messages). * No longer needed VerbosityFilter and ConsoleListener classes. * Avoid calling GetSource() if we aren't outputting the source. * Avoid formatting the string if it won't pass the verbosity level. * Consolidated all of UAT and UBT options into this class, so they could fully share the implementation. UBT BuildConfiguration.cs * Added LogFilename (and --log=<file> arg) that enables logging to a file. * Added static ctor guard that asserts if someone tries to read a config before we have loaded config files and parsed config-override commandlines. It's a poor man's hack, but better than nothing! UBT UEBuildConfiguration.cs * Same static ctor guard as above. UBT UnrealBuildTools.cs (initialization refactoring) * In general I tried to de-mystify some of the rationale behind our startup code via fat comments. * Broke main into 3 stages: 1. "early code" that should not try to read a config value. * Very little code here. Mostly setting the current directory. * Does an early init of logging to ensure logging is around, but config values won't be ready. 2. "Init Configuration code" that loads config files and parses command lines that may override them. * I isolated two locations in startup that parsed long sets of switches and moved ones that trivially affected BuildConfiguration and UEBuildConfiguration in here. Those two locations seemed to have mostly copies of the same switches, indicating serious param parsing issues at some point in time. * This allows switches to override config files more easily than the patchwork of re-parsing that was currently used (particularly for -verbose). * I did a cursory examination of later code that indicated this double (actually, triple) parsing was no longer necessary with the refactors above. Any insight into why things may have ended up this way would be helpful. 3. "Post Init code" that is actually the meat of UBT. * I left this code largely untouched. * Removed 2 of 3 different command line logging statements. * Removed two redundant parses of config overrides (ParseBuildConfigurationFlags). * Guarded all of main in a try/catch block to ensure no exceptions can leak from UBT without returning a valid error code. It ALMOST already did this, but only covered the part surrounded by the Mutex. * There was a perplexing bit that redundantly called XmlConfigLoader.Reset<> (line 683) that I struggled to understand. It turns out UEBuildConfiguration was sensitive to the current directory being set before files were loaded, and the old code called XmlConfigLoader.Init() super early, which required it to be called again after the current directory was set (see UEBuldConfiguration.UEThirdPartySourceDirectory for the cause). After my changes, I verified as best I could that these calls are no longer needed and removed them. XmlConfigLoader.cs * Add support for Properties in XmlConfigLoader. AutomationTool Program.cs * Guard logging shutdown code in try/finally so it can't be missed. AutomationTool Log.cs * Uses new logging system from UBT * Removed unnecessary classes (VerbosityFilter, AutomationConsoleTraceListener, and AutomationFileTraceListener) * Console trace logic is handled by UBT code now, moved UTF8Output handling to InitLogging. * A custom TraceListener for file logging was unnecessary. * Logic to handle creating the log file and retry loops was move into InitLogging, and the result passed to a regular TextFileTraceListener. * Logic to handle copying the log on shutdown was moved to a ShutdownLogging function. #codereview:robert.manuszewski,michael.trepka,kellan.carr [CL 2526245 by Wes Hunt in Main branch]
2015-04-26 18:19:28 -04:00
// Make sure there's no directiories on the stack.
CommandUtils.ClearDirStack();
Environment.ExitCode = ReturnCode;
UBT Utils.cs (New logging system) * Allows us to use built-in Trace providers (console, file, etc) directly and still use our custom formatting. * Fat comments explaining why Trace.WriteXXX functions should not be used directly in our system. * Fixes thread safety by using Trace.WriteXXX under the hood after formatting, which uses a global lock (except on Mono, where a bug appears to be preventing this. Simulating the call on that platform). * No need for TraceEvent overloads, which saves us the extra parameter cruft. * Removed non-varargs overloads of Log functions (technically a bit slower, but these are already small messages). * No longer needed VerbosityFilter and ConsoleListener classes. * Avoid calling GetSource() if we aren't outputting the source. * Avoid formatting the string if it won't pass the verbosity level. * Consolidated all of UAT and UBT options into this class, so they could fully share the implementation. UBT BuildConfiguration.cs * Added LogFilename (and --log=<file> arg) that enables logging to a file. * Added static ctor guard that asserts if someone tries to read a config before we have loaded config files and parsed config-override commandlines. It's a poor man's hack, but better than nothing! UBT UEBuildConfiguration.cs * Same static ctor guard as above. UBT UnrealBuildTools.cs (initialization refactoring) * In general I tried to de-mystify some of the rationale behind our startup code via fat comments. * Broke main into 3 stages: 1. "early code" that should not try to read a config value. * Very little code here. Mostly setting the current directory. * Does an early init of logging to ensure logging is around, but config values won't be ready. 2. "Init Configuration code" that loads config files and parses command lines that may override them. * I isolated two locations in startup that parsed long sets of switches and moved ones that trivially affected BuildConfiguration and UEBuildConfiguration in here. Those two locations seemed to have mostly copies of the same switches, indicating serious param parsing issues at some point in time. * This allows switches to override config files more easily than the patchwork of re-parsing that was currently used (particularly for -verbose). * I did a cursory examination of later code that indicated this double (actually, triple) parsing was no longer necessary with the refactors above. Any insight into why things may have ended up this way would be helpful. 3. "Post Init code" that is actually the meat of UBT. * I left this code largely untouched. * Removed 2 of 3 different command line logging statements. * Removed two redundant parses of config overrides (ParseBuildConfigurationFlags). * Guarded all of main in a try/catch block to ensure no exceptions can leak from UBT without returning a valid error code. It ALMOST already did this, but only covered the part surrounded by the Mutex. * There was a perplexing bit that redundantly called XmlConfigLoader.Reset<> (line 683) that I struggled to understand. It turns out UEBuildConfiguration was sensitive to the current directory being set before files were loaded, and the old code called XmlConfigLoader.Init() super early, which required it to be called again after the current directory was set (see UEBuldConfiguration.UEThirdPartySourceDirectory for the cause). After my changes, I verified as best I could that these calls are no longer needed and removed them. XmlConfigLoader.cs * Add support for Properties in XmlConfigLoader. AutomationTool Program.cs * Guard logging shutdown code in try/finally so it can't be missed. AutomationTool Log.cs * Uses new logging system from UBT * Removed unnecessary classes (VerbosityFilter, AutomationConsoleTraceListener, and AutomationFileTraceListener) * Console trace logic is handled by UBT code now, moved UTF8Output handling to InitLogging. * A custom TraceListener for file logging was unnecessary. * Logic to handle creating the log file and retry loops was move into InitLogging, and the result passed to a regular TextFileTraceListener. * Logic to handle copying the log on shutdown was moved to a ShutdownLogging function. #codereview:robert.manuszewski,michael.trepka,kellan.carr [CL 2526245 by Wes Hunt in Main branch]
2015-04-26 18:19:28 -04:00
// Try to kill process before app domain exits to leave the other KillAll call to extreme edge cases
if (ShouldKillProcesses && !Utils.IsRunningOnMono)
{
ProcessManager.KillAll();
}
UBT Utils.cs (New logging system) * Allows us to use built-in Trace providers (console, file, etc) directly and still use our custom formatting. * Fat comments explaining why Trace.WriteXXX functions should not be used directly in our system. * Fixes thread safety by using Trace.WriteXXX under the hood after formatting, which uses a global lock (except on Mono, where a bug appears to be preventing this. Simulating the call on that platform). * No need for TraceEvent overloads, which saves us the extra parameter cruft. * Removed non-varargs overloads of Log functions (technically a bit slower, but these are already small messages). * No longer needed VerbosityFilter and ConsoleListener classes. * Avoid calling GetSource() if we aren't outputting the source. * Avoid formatting the string if it won't pass the verbosity level. * Consolidated all of UAT and UBT options into this class, so they could fully share the implementation. UBT BuildConfiguration.cs * Added LogFilename (and --log=<file> arg) that enables logging to a file. * Added static ctor guard that asserts if someone tries to read a config before we have loaded config files and parsed config-override commandlines. It's a poor man's hack, but better than nothing! UBT UEBuildConfiguration.cs * Same static ctor guard as above. UBT UnrealBuildTools.cs (initialization refactoring) * In general I tried to de-mystify some of the rationale behind our startup code via fat comments. * Broke main into 3 stages: 1. "early code" that should not try to read a config value. * Very little code here. Mostly setting the current directory. * Does an early init of logging to ensure logging is around, but config values won't be ready. 2. "Init Configuration code" that loads config files and parses command lines that may override them. * I isolated two locations in startup that parsed long sets of switches and moved ones that trivially affected BuildConfiguration and UEBuildConfiguration in here. Those two locations seemed to have mostly copies of the same switches, indicating serious param parsing issues at some point in time. * This allows switches to override config files more easily than the patchwork of re-parsing that was currently used (particularly for -verbose). * I did a cursory examination of later code that indicated this double (actually, triple) parsing was no longer necessary with the refactors above. Any insight into why things may have ended up this way would be helpful. 3. "Post Init code" that is actually the meat of UBT. * I left this code largely untouched. * Removed 2 of 3 different command line logging statements. * Removed two redundant parses of config overrides (ParseBuildConfigurationFlags). * Guarded all of main in a try/catch block to ensure no exceptions can leak from UBT without returning a valid error code. It ALMOST already did this, but only covered the part surrounded by the Mutex. * There was a perplexing bit that redundantly called XmlConfigLoader.Reset<> (line 683) that I struggled to understand. It turns out UEBuildConfiguration was sensitive to the current directory being set before files were loaded, and the old code called XmlConfigLoader.Init() super early, which required it to be called again after the current directory was set (see UEBuldConfiguration.UEThirdPartySourceDirectory for the cause). After my changes, I verified as best I could that these calls are no longer needed and removed them. XmlConfigLoader.cs * Add support for Properties in XmlConfigLoader. AutomationTool Program.cs * Guard logging shutdown code in try/finally so it can't be missed. AutomationTool Log.cs * Uses new logging system from UBT * Removed unnecessary classes (VerbosityFilter, AutomationConsoleTraceListener, and AutomationFileTraceListener) * Console trace logic is handled by UBT code now, moved UTF8Output handling to InitLogging. * A custom TraceListener for file logging was unnecessary. * Logic to handle creating the log file and retry loops was move into InitLogging, and the result passed to a regular TextFileTraceListener. * Logic to handle copying the log on shutdown was moved to a ShutdownLogging function. #codereview:robert.manuszewski,michael.trepka,kellan.carr [CL 2526245 by Wes Hunt in Main branch]
2015-04-26 18:19:28 -04:00
Log.WriteLine(TraceEventType.Information, "AutomationTool exiting with ExitCode={0}", ReturnCode);
}
finally
{
// ensure that logging is always shut down cleanly, as this potentially copies the log to a final resting place.
LogUtils.ShutdownLogging();
}
return ReturnCode;
}
static bool CtrlHandler(CtrlTypes EventType)
{
Domain_ProcessExit(null, null);
if (EventType == CtrlTypes.CTRL_C_EVENT)
{
// Force exit
Environment.Exit(3);
}
return true;
}
static void Domain_ProcessExit(object sender, EventArgs e)
{
// Kill all spawned processes (Console instead of Log because logging is closed at this time anyway)
Console.WriteLine("Domain_ProcessExit");
if (ShouldKillProcesses && !Utils.IsRunningOnMono)
{
ProcessManager.KillAll();
}
Trace.Close();
}
static int MainProc(object Param)
{
Automation.Process((string[])Param);
ShouldKillProcesses = Automation.ShouldKillProcesses;
return 0;
}
static bool ShouldKillProcesses = true;
}
}