Esempio n. 1
0
        static ExitCode MainProc(string[] Arguments, StartupTraceListener StartupListener)
        {
            ExitCode Result = Automation.Process(Arguments, StartupListener);

            ShouldKillProcesses = Automation.ShouldKillProcesses;
            return(Result);
        }
Esempio n. 2
0
        public static int Main(string[] Arguments)
        {
            // Ensure UTF8Output flag is respected, since we are initializing logging early in the program.
            if (CommandUtils.ParseParam(Arguments, "-Utf8output"))
            {
                Console.OutputEncoding = new System.Text.UTF8Encoding(false, false);
            }

            // Parse the log level argument
            if (CommandUtils.ParseParam(Arguments, "-Verbose"))
            {
                Log.OutputLevel = LogEventType.Verbose;
            }
            if (CommandUtils.ParseParam(Arguments, "-VeryVerbose"))
            {
                Log.OutputLevel = LogEventType.VeryVerbose;
            }

            // Initialize the log system, buffering the output until we can create the log file
            StartupTraceListener StartupListener = new StartupTraceListener();

            Trace.Listeners.Add(StartupListener);

            // Configure log timestamps
            Log.IncludeTimestamps = CommandUtils.ParseParam(Arguments, "-Timestamps");

            // Enter the main program section
            ExitCode ReturnCode = ExitCode.Success;

            try
            {
                // Set the working directory to the UE4 root
                Environment.CurrentDirectory = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetOriginalLocation()), "..", "..", ".."));

                // Ensure we can resolve any external assemblies as necessary.
                string PathToBinariesDotNET = Path.GetDirectoryName(Assembly.GetEntryAssembly().GetOriginalLocation());
                AssemblyUtils.InstallAssemblyResolver(PathToBinariesDotNET);
                AssemblyUtils.InstallRecursiveAssemblyResolver(PathToBinariesDotNET);

                // Initialize the host platform layer
                HostPlatform.Initialize();

                // Log the operating environment. Since we usually compile to AnyCPU, we may be executed using different system paths under WOW64.
                Log.TraceVerbose("{2}: Running on {0} as a {1}-bit process.", HostPlatform.Current.GetType().Name, Environment.Is64BitProcess ? 64 : 32, DateTime.UtcNow.ToString("o"));

                // Log if we're running from the launcher
                string ExecutingAssemblyLocation = Assembly.GetExecutingAssembly().Location;
                if (string.Compare(ExecutingAssemblyLocation, Assembly.GetEntryAssembly().GetOriginalLocation(), StringComparison.OrdinalIgnoreCase) != 0)
                {
                    Log.TraceVerbose("Executed from AutomationToolLauncher ({0})", ExecutingAssemblyLocation);
                }
                Log.TraceVerbose("CWD={0}", Environment.CurrentDirectory);

                // Hook up exit callbacks
                AppDomain Domain = AppDomain.CurrentDomain;
                Domain.ProcessExit  += Domain_ProcessExit;
                Domain.DomainUnload += Domain_ProcessExit;
                HostPlatform.Current.SetConsoleCtrlHandler(CtrlHandlerDelegateInstance);

                // Log the application version
                FileVersionInfo Version = AssemblyUtils.ExecutableVersion;
                Log.TraceVerbose("{0} ver. {1}", Version.ProductName, Version.ProductVersion);

                // Don't allow simultaneous execution of AT (in the same branch)
                ReturnCode = InternalUtils.RunSingleInstance(() => MainProc(Arguments, StartupListener));
            }
            catch (AutomationException Ex)
            {
                // Output the message in the desired format
                if (Ex.OutputFormat == AutomationExceptionOutputFormat.Silent)
                {
                    Log.TraceLog("{0}", ExceptionUtils.FormatExceptionDetails(Ex));
                }
                else if (Ex.OutputFormat == AutomationExceptionOutputFormat.Minimal)
                {
                    Log.TraceInformation("{0}", Ex.ToString().Replace("\n", "\n  "));
                    Log.TraceLog("{0}", ExceptionUtils.FormatExceptionDetails(Ex));
                }
                else
                {
                    Log.WriteException(Ex, LogUtils.FinalLogFileName);
                }

                // Take the exit code from the exception
                ReturnCode = Ex.ErrorCode;
            }
            catch (Exception Ex)
            {
                // Use a default exit code
                Log.WriteException(Ex, LogUtils.FinalLogFileName);
                ReturnCode = ExitCode.Error_Unknown;
            }
            finally
            {
                // In all cases, do necessary shut down stuff, but don't let any additional exceptions leak out while trying to shut down.

                // Make sure there's no directories on the stack.
                NoThrow(() => CommandUtils.ClearDirStack(), "Clear Dir Stack");

                // Try to kill process before app domain exits to leave the other KillAll call to extreme edge cases
                NoThrow(() => { if (ShouldKillProcesses && !Utils.IsRunningOnMono)
                                {
                                    ProcessManager.KillAll();
                                }
                        }, "Kill All Processes");

                // Write the exit code
                Log.TraceInformation("AutomationTool exiting with ExitCode={0} ({1})", (int)ReturnCode, ReturnCode);

                // Can't use NoThrow here because the code logs exceptions. We're shutting down logging!
                Trace.Close();
            }
            return((int)ReturnCode);
        }
Esempio n. 3
0
        /// <summary>
        /// Main method.
        /// </summary>
        /// <param name="Arguments">Command line</param>
        public static ExitCode Process(string[] Arguments, StartupTraceListener StartupListener)
        {
            // Initial check for local or build machine runs BEFORE we parse the command line (We need this value set
            // in case something throws the exception while parsing the command line)
            IsBuildMachine = !String.IsNullOrEmpty(Environment.GetEnvironmentVariable("uebp_LOCAL_ROOT")) || Arguments.Any(x => x.Equals("-BuildMachine", StringComparison.InvariantCultureIgnoreCase));

            // Scan the command line for commands to execute.
            var    CommandsToExecute = new List <CommandInfo>();
            string OutScriptsForProjectFileName;
            var    AdditionalScriptsFolders = new List <string>();

            ParseCommandLine(Arguments, CommandsToExecute, out OutScriptsForProjectFileName, AdditionalScriptsFolders);

            // Get the path to the telemetry file, if present
            string TelemetryFile = CommandUtils.ParseParamValue(Arguments, "-Telemetry");

            Log.TraceVerbose("IsBuildMachine={0}", IsBuildMachine);
            Environment.SetEnvironmentVariable("IsBuildMachine", IsBuildMachine ? "1" : "0");

            // should we kill processes on exit
            ShouldKillProcesses = !GlobalCommandLine.NoKill;
            Log.TraceVerbose("ShouldKillProcesses={0}", ShouldKillProcesses);

            if (CommandsToExecute.Count == 0 && GlobalCommandLine.Help)
            {
                DisplayHelp();
                return(ExitCode.Success);
            }

            // Disable AutoSDKs if specified on the command line
            if (GlobalCommandLine.NoAutoSDK)
            {
                PlatformExports.PreventAutoSDKSwitching();
            }

            // Setup environment
            Log.TraceLog("Setting up command environment.");
            CommandUtils.InitCommandEnvironment();

            // Create the log file, and flush the startup listener to it
            TraceListener LogTraceListener = LogUtils.AddLogFileListener(CommandUtils.CmdEnv.LogFolder, CommandUtils.CmdEnv.FinalLogFolder);

            StartupListener.CopyTo(LogTraceListener);
            Trace.Listeners.Remove(StartupListener);

            // Initialize UBT
            if (!UnrealBuildTool.PlatformExports.Initialize())
            {
                Log.TraceInformation("Failed to initialize UBT");
                return(ExitCode.Error_Unknown);
            }

            // Clean rules folders up
            ProjectUtils.CleanupFolders();

            // Compile scripts.
            Compiler = new ScriptCompiler();
            using (TelemetryStopwatch ScriptCompileStopwatch = new TelemetryStopwatch("ScriptCompile"))
            {
                Compiler.FindAndCompileAllScripts(OutScriptsForProjectFileName, AdditionalScriptsFolders);
            }

            if (GlobalCommandLine.CompileOnly)
            {
                Log.TraceInformation("Compilation successful, exiting (CompileOnly)");
                return(ExitCode.Success);
            }

            if (GlobalCommandLine.List)
            {
                ListAvailableCommands(Compiler.Commands);
                return(ExitCode.Success);
            }

            if (GlobalCommandLine.Help)
            {
                DisplayHelp(CommandsToExecute, Compiler.Commands);
                return(ExitCode.Success);
            }

            // Enable or disable P4 support
            CommandUtils.InitP4Support(CommandsToExecute, Compiler.Commands);
            if (CommandUtils.P4Enabled)
            {
                Log.TraceLog("Setting up Perforce environment.");
                CommandUtils.InitP4Environment();
                CommandUtils.InitDefaultP4Connection();
            }

            // Find and execute commands.
            ExitCode Result = Execute(CommandsToExecute, Compiler.Commands);

            if (TelemetryFile != null)
            {
                Directory.CreateDirectory(Path.GetDirectoryName(TelemetryFile));
                CommandUtils.Telemetry.Write(TelemetryFile);
            }
            return(Result);
        }