Пример #1
0
        public static int Main()
        {
            var CommandLine = SharedUtils.ParseCommandLine();

            LogUtils.InitLogging(CommandLine);

            ExitCode ReturnCode = ExitCode.Success;

            try
            {
                // ensure we can resolve any external assemblies as necessary.
                AssemblyUtils.InstallAssemblyResolver(Path.GetDirectoryName(Assembly.GetEntryAssembly().GetOriginalLocation()));
                HostPlatform.Initialize();

                Log.TraceVerbose("{2}: Running on {0} as a {1}-bit process.", HostPlatform.Current.GetType().Name, Environment.Is64BitProcess ? 64 : 32, DateTime.UtcNow.ToString("o"));

                XmlConfigLoader.Init();

                // Log if we're running from the launcher
                var 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
                var Domain = AppDomain.CurrentDomain;
                Domain.ProcessExit  += Domain_ProcessExit;
                Domain.DomainUnload += Domain_ProcessExit;
                HostPlatform.Current.SetConsoleCtrlHandler(CtrlHandlerDelegateInstance);

                var 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, CommandLine);
            }
            catch (AutomationException Ex)
            {
                Log.TraceError("AutomationTool terminated with exception: {0}", Ex);
                ReturnCode = Ex.ErrorCode;
            }
            catch (Exception Ex)
            {
                // Catch all exceptions and propagate the ErrorCode if we are given one.
                Log.TraceError("AutomationTool terminated with exception: {0}", Ex);
                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");

                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!
                LogUtils.ShutdownLogging();
            }

            // STOP: No code beyond the return statement should go beyond this point!
            // Nothing should happen after the finally block above is finished.
            return((int)ReturnCode);
        }
Пример #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);
        }
Пример #3
0
        /// <summary>
        /// Constructor. Derives the Perforce environment settings.
        /// </summary>
        internal P4Environment(CommandEnvironment CmdEnv)
        {
            // Get the Perforce port setting
            ServerAndPort = CommandUtils.GetEnvVar(EnvVarNames.P4Port);
            if (String.IsNullOrEmpty(ServerAndPort))
            {
                ServerAndPort = DetectP4Port();
                CommandUtils.SetEnvVar(EnvVarNames.P4Port, ServerAndPort);
            }

            // Get the Perforce user setting
            User = CommandUtils.GetEnvVar(EnvVarNames.User);
            if (String.IsNullOrEmpty(User))
            {
                P4Connection DefaultConnection = new P4Connection(User: null, Client: null, ServerAndPort: ServerAndPort);
                User = DetectUserName(DefaultConnection);
                CommandUtils.SetEnvVar(EnvVarNames.User, User);
            }

            // Get the Perforce client setting
            Client = CommandUtils.GetEnvVar(EnvVarNames.Client);
            if (String.IsNullOrEmpty(Client))
            {
                P4Connection DefaultConnection = new P4Connection(User: User, Client: null, ServerAndPort: ServerAndPort);
                P4ClientInfo ThisClient        = DetectClient(DefaultConnection, User, Environment.MachineName.ToLower(), CmdEnv.UATExe);
                Log.TraceInformation("Using user {0} clientspec {1} {2}", User, ThisClient.Name, ThisClient.RootPath);

                string       BranchPath;
                string       ClientRootPath;
                P4Connection ClientConnection = new P4Connection(User: User, Client: ThisClient.Name, ServerAndPort: ServerAndPort);
                DetectRootPaths(ClientConnection, CmdEnv.LocalRoot, ThisClient, out BranchPath, out ClientRootPath);

                Client = ThisClient.Name;
                CommandUtils.SetEnvVar(EnvVarNames.Client, Client);

                Branch = BranchPath;
                CommandUtils.SetEnvVar(EnvVarNames.BuildRootP4, Branch);

                ClientRoot = ClientRootPath;
                CommandUtils.SetEnvVar(EnvVarNames.ClientRoot, ClientRootPath);
            }
            else
            {
                Branch     = CommandUtils.GetEnvVar(EnvVarNames.BuildRootP4);
                ClientRoot = CommandUtils.GetEnvVar(EnvVarNames.ClientRoot);
                if (String.IsNullOrEmpty(Branch) || String.IsNullOrEmpty(ClientRoot))
                {
                    throw new AutomationException("{0} and {1} must also be set with {2}", EnvVarNames.ClientRoot, EnvVarNames.BuildRootP4, EnvVarNames.Client);
                }
            }

            // We expect the build root to not end with a path separator
            if (Branch.EndsWith("/"))
            {
                Branch = Branch.TrimEnd('/');
                CommandUtils.SetEnvVar(EnvVarNames.BuildRootP4, Branch);
            }

            // Set the current changelist
            string ChangelistString = CommandUtils.GetEnvVar(EnvVarNames.Changelist, null);

            if (String.IsNullOrEmpty(ChangelistString) && CommandUtils.P4CLRequired)
            {
                P4Connection Connection = new P4Connection(User, Client, ServerAndPort);
                ChangelistString = DetectCurrentCL(Connection, ClientRoot);
                CommandUtils.SetEnvVar(EnvVarNames.Changelist, ChangelistString);
            }
            if (!String.IsNullOrEmpty(ChangelistString))
            {
                Changelist = int.Parse(ChangelistString);
            }

            // Set the current code changelist
            string CodeChangelistString = CommandUtils.GetEnvVar(EnvVarNames.CodeChangelist);

            if (String.IsNullOrEmpty(CodeChangelistString) && CommandUtils.P4CLRequired)
            {
                P4Connection Connection = new P4Connection(User, Client, ServerAndPort);
                CodeChangelistString = DetectCurrentCodeCL(Connection, ClientRoot);
                CommandUtils.SetEnvVar(EnvVarNames.CodeChangelist, CodeChangelistString);
            }
            if (!String.IsNullOrEmpty(CodeChangelistString))
            {
                CodeChangelist = int.Parse(CodeChangelistString);
            }

            // Set the standard environment variables based on the values we've found
            CommandUtils.SetEnvVar("P4PORT", ServerAndPort);
            CommandUtils.SetEnvVar("P4USER", User);
            CommandUtils.SetEnvVar("P4CLIENT", Client);

            // Write a summary of the settings to the output window
            if (!CommandUtils.CmdEnv.IsChildInstance)
            {
                Log.TraceInformation("Detected Perforce Settings:");
                Log.TraceInformation("  Server: {0}", ServerAndPort);
                Log.TraceInformation("  User: {0}", User);
                Log.TraceInformation("  Client: {0}", Client);
                Log.TraceInformation("  Branch: {0}", Branch);
                if (ChangelistInternal != -1)
                {
                    Log.TraceInformation("  Last Change: {0}", Changelist);
                }
                if (CodeChangelistInternal != -1)
                {
                    Log.TraceInformation("  Last Code Change: {0}", CodeChangelist);
                }
            }

            // Write all the environment variables to the log
            Log.TraceLog("Perforce Environment Variables:");
            Log.TraceLog("  {0}={1}", EnvVarNames.P4Port, InternalUtils.GetEnvironmentVariable(EnvVarNames.P4Port, "", true));
            Log.TraceLog("  {0}={1}", EnvVarNames.User, InternalUtils.GetEnvironmentVariable(EnvVarNames.User, "", true));
            Log.TraceLog("  {0}={1}", EnvVarNames.Client, InternalUtils.GetEnvironmentVariable(EnvVarNames.Client, "", true));
            Log.TraceLog("  {0}={1}", EnvVarNames.BuildRootP4, InternalUtils.GetEnvironmentVariable(EnvVarNames.BuildRootP4, "", true));
            Log.TraceLog("  {0}={1}", EnvVarNames.BuildRootEscaped, InternalUtils.GetEnvironmentVariable(EnvVarNames.BuildRootEscaped, "", true));
            Log.TraceLog("  {0}={1}", EnvVarNames.ClientRoot, InternalUtils.GetEnvironmentVariable(EnvVarNames.ClientRoot, "", true));
            Log.TraceLog("  {0}={1}", EnvVarNames.Changelist, InternalUtils.GetEnvironmentVariable(EnvVarNames.Changelist, "", true));
            Log.TraceLog("  {0}={1}", EnvVarNames.CodeChangelist, InternalUtils.GetEnvironmentVariable(EnvVarNames.CodeChangelist, "", true));
            Log.TraceLog("  {0}={1}", "P4PORT", InternalUtils.GetEnvironmentVariable("P4PORT", "", true));
            Log.TraceLog("  {0}={1}", "P4USER", InternalUtils.GetEnvironmentVariable("P4USER", "", true));
            Log.TraceLog("  {0}={1}", "P4CLIENT", InternalUtils.GetEnvironmentVariable("P4CLIENT", "", true));
        }
Пример #4
0
        public static int Main()
        {
            var CommandLine = SharedUtils.ParseCommandLine();

            HostPlatform.Initialize();

            LogUtils.InitLogging(CommandLine);
            Log.WriteLine(TraceEventType.Information, "Running on {0}", HostPlatform.Current.GetType().Name);

            XmlConfigLoader.Init();

            // 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);

            // Hook up exit callbacks
            var Domain = AppDomain.CurrentDomain;

            Domain.ProcessExit  += Domain_ProcessExit;
            Domain.DomainUnload += Domain_ProcessExit;
            HostPlatform.Current.SetConsoleCtrlHandler(ProgramCtrlHandler);

            var Version = InternalUtils.ExecutableVersion;

            Log.WriteLine(TraceEventType.Verbose, "{0} ver. {1}", Version.ProductName, Version.ProductVersion);

            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;
                }
            }

            // Make sure there's no directiories on the stack.
            CommandUtils.ClearDirStack();
            Environment.ExitCode = ReturnCode;

            // Try to kill process before app domain exits to leave the other KillAll call to extreme edge cases
            if (ShouldKillProcesses)
            {
                ProcessManager.KillAll();
            }

            Log.WriteLine(TraceEventType.Information, "AutomationTool exiting with ExitCode={0}", ReturnCode);
            LogUtils.CloseFileLogging();

            return(ReturnCode);
        }