Пример #1
0
 public ProcessResult(string InAppName, Process InProc, bool bAllowSpew, string LogName, UnrealBuildTool.LogEventType SpewVerbosity = UnrealBuildTool.LogEventType.Console)
 {
     AppName            = InAppName;
     ProcSyncObject     = new object();
     Proc               = InProc;
     Source             = LogName;
     AllowSpew          = bAllowSpew;
     this.SpewVerbosity = SpewVerbosity;
     if (Proc != null)
     {
         Proc.EnableRaisingEvents = false;
     }
 }
Пример #2
0
 public ProcessResult(string InAppName, Process InProc, bool bAllowSpew, UnrealBuildTool.LogEventType SpewVerbosity = UnrealBuildTool.LogEventType.Console, SpewFilterCallbackType InSpewFilterCallback = null)
 {
     AppName            = InAppName;
     ProcSyncObject     = new object();
     Proc               = InProc;
     AllowSpew          = bAllowSpew;
     this.SpewVerbosity = SpewVerbosity;
     SpewFilterCallback = InSpewFilterCallback;
     if (Proc != null)
     {
         Proc.EnableRaisingEvents = false;
     }
 }
Пример #3
0
 public ProcessResult(string InAppName, Process InProc, bool bAllowSpew, bool bCaptureSpew = true, UnrealBuildTool.LogEventType SpewVerbosity = UnrealBuildTool.LogEventType.Console, SpewFilterCallbackType InSpewFilterCallback = null)
 {
     AppName        = InAppName;
     ProcSyncObject = new object();
     Proc           = InProc;
     AllowSpew      = bAllowSpew;
     if (bCaptureSpew)
     {
         ProcessOutput = new StringBuilder();
     }
     else
     {
         OutputWaitHandle.Set();
         ErrorWaitHandle.Set();
     }
     this.SpewVerbosity = SpewVerbosity;
     SpewFilterCallback = InSpewFilterCallback;
     if (Proc != null)
     {
         Proc.EnableRaisingEvents = false;
     }
 }
Пример #4
0
        /// <summary>
        /// Runs external program.
        /// </summary>
        /// <param name="App">Program filename.</param>
        /// <param name="CommandLine">Commandline</param>
        /// <param name="Input">Optional Input for the program (will be provided as stdin)</param>
        /// <param name="Options">Defines the options how to run. See ERunOptions.</param>
        /// <param name="Env">Environment to pass to program.</param>
        /// <returns>Object containing the exit code of the program as well as it's stdout output.</returns>
        public static ProcessResult Run(string App, string CommandLine = null, string Input = null, ERunOptions Options = ERunOptions.Default, Dictionary <string, string> Env = null)
        {
            App = ConvertSeparators(PathSeparator.Default, App);
            HostPlatform.Current.SetupOptionsForRun(ref App, ref Options, ref CommandLine);
            if (App == "ectool" || App == "zip" || App == "xcodebuild")
            {
                Options &= ~ERunOptions.AppMustExist;
            }

            if (Options.HasFlag(ERunOptions.AppMustExist) && !FileExists(Options.HasFlag(ERunOptions.NoLoggingOfRunCommand) ? true : false, App))
            {
                throw new AutomationException("BUILD FAILED: Couldn't find the executable to Run: {0}", App);
            }
            var StartTime = DateTime.UtcNow;

            UnrealBuildTool.LogEventType SpewVerbosity = Options.HasFlag(ERunOptions.SpewIsVerbose) ? UnrealBuildTool.LogEventType.Verbose : UnrealBuildTool.LogEventType.Console;
            if (!Options.HasFlag(ERunOptions.NoLoggingOfRunCommand))
            {
                LogWithVerbosity(SpewVerbosity, "Run: " + App + " " + (String.IsNullOrEmpty(CommandLine) ? "" : CommandLine));
            }
            ProcessResult Result = ProcessManager.CreateProcess(App, Options.HasFlag(ERunOptions.AllowSpew), Path.GetFileNameWithoutExtension(App), Env, SpewVerbosity: SpewVerbosity);
            Process       Proc   = Result.ProcessObject;

            bool bRedirectStdOut = (Options & ERunOptions.NoStdOutRedirect) != ERunOptions.NoStdOutRedirect;

            Proc.StartInfo.FileName        = App;
            Proc.StartInfo.Arguments       = String.IsNullOrEmpty(CommandLine) ? "" : CommandLine;
            Proc.StartInfo.UseShellExecute = false;
            if (bRedirectStdOut)
            {
                Proc.StartInfo.RedirectStandardOutput = true;
                Proc.StartInfo.RedirectStandardError  = true;
                Proc.OutputDataReceived += Result.StdOut;
                Proc.ErrorDataReceived  += Result.StdErr;
            }
            Proc.StartInfo.RedirectStandardInput = Input != null;
            Proc.StartInfo.CreateNoWindow        = true;
            if ((Options & ERunOptions.UTF8Output) == ERunOptions.UTF8Output)
            {
                Proc.StartInfo.StandardOutputEncoding = new System.Text.UTF8Encoding(false, false);
            }
            Proc.Start();

            if (bRedirectStdOut)
            {
                Proc.BeginOutputReadLine();
                Proc.BeginErrorReadLine();
            }

            if (String.IsNullOrEmpty(Input) == false)
            {
                Proc.StandardInput.WriteLine(Input);
                Proc.StandardInput.Close();
            }

            if (!Options.HasFlag(ERunOptions.NoWaitForExit))
            {
                Result.WaitForExit();
                var BuildDuration = (DateTime.UtcNow - StartTime).TotalMilliseconds;
                AddRunTime(App, (int)(BuildDuration));
                Result.ExitCode = Proc.ExitCode;
                if (!Options.HasFlag(ERunOptions.NoLoggingOfRunCommand) || Options.HasFlag(ERunOptions.LoggingOfRunDuration))
                {
                    LogWithVerbosity(SpewVerbosity, "Run: Took {0}s to run {1}, ExitCode={2}", BuildDuration / 1000, Path.GetFileName(App), Result.ExitCode);
                }
                Result.OnProcessExited();
                Result.DisposeProcess();
            }
            else
            {
                Result.ExitCode = -1;
            }

            return(Result);
        }
Пример #5
0
        /// <summary>
        /// Creates a new process and adds it to the tracking list.
        /// </summary>
        /// <returns>New Process objects</returns>
        public static ProcessResult CreateProcess(string AppName, bool bAllowSpew, string LogName, Dictionary <string, string> Env = null, UnrealBuildTool.LogEventType SpewVerbosity = UnrealBuildTool.LogEventType.Console)
        {
            var NewProcess = HostPlatform.Current.CreateProcess(LogName);

            if (Env != null)
            {
                foreach (var EnvPair in Env)
                {
                    if (NewProcess.StartInfo.EnvironmentVariables.ContainsKey(EnvPair.Key))
                    {
                        NewProcess.StartInfo.EnvironmentVariables.Remove(EnvPair.Key);
                    }
                    if (!String.IsNullOrEmpty(EnvPair.Value))
                    {
                        NewProcess.StartInfo.EnvironmentVariables.Add(EnvPair.Key, EnvPair.Value);
                    }
                }
            }
            var Result = new ProcessResult(AppName, NewProcess, bAllowSpew, LogName, SpewVerbosity: SpewVerbosity);

            AddProcess(Result);
            return(Result);
        }
Пример #6
0
 private void LogOutput(UnrealBuildTool.LogEventType Verbosity, string Message)
 {
     UnrealBuildTool.Log.WriteLine(1, Source, Verbosity, Message);
 }
Пример #7
0
		public ProcessResult(string InAppName, Process InProc, bool bAllowSpew, string LogName, UnrealBuildTool.LogEventType SpewVerbosity = UnrealBuildTool.LogEventType.Console)
		{
			AppName = InAppName;
			ProcSyncObject = new object();
			Proc = InProc;
			Source = LogName;
			AllowSpew = bAllowSpew;
			this.SpewVerbosity = SpewVerbosity;
			if (Proc != null)
			{
				Proc.EnableRaisingEvents = false;
			}
		}
        /// <summary>
        /// Runs external program.
        /// </summary>
        /// <param name="App">Program filename.</param>
        /// <param name="CommandLine">Commandline</param>
        /// <param name="Input">Optional Input for the program (will be provided as stdin)</param>
        /// <param name="Options">Defines the options how to run. See ERunOptions.</param>
        /// <param name="Env">Environment to pass to program.</param>
        /// <param name="FilterCallback">Callback to filter log spew before output.</param>
        /// <returns>Object containing the exit code of the program as well as it's stdout output.</returns>
        public static IProcessResult Run(string App, string CommandLine = null, string Input = null, ERunOptions Options = ERunOptions.Default, Dictionary <string, string> Env = null, ProcessResult.SpewFilterCallbackType SpewFilterCallback = null)
        {
            App = ConvertSeparators(PathSeparator.Default, App);

            // Get the log name before allowing the platform to modify the app/command-line. We want mono apps to be written to a log named after the application and appear with the application prefix rather than "mono:".
            string LogName = Path.GetFileNameWithoutExtension(App);

            HostPlatform.Current.SetupOptionsForRun(ref App, ref Options, ref CommandLine);
            if (App == "ectool" || App == "zip" || App == "xcodebuild")
            {
                Options &= ~ERunOptions.AppMustExist;
            }

            // Check if the application exists, including the PATH directories.
            if (Options.HasFlag(ERunOptions.AppMustExist) && !FileExists(Options.HasFlag(ERunOptions.NoLoggingOfRunCommand) ? true : false, App))
            {
                bool bExistsInPath = false;
                if (!App.Contains(Path.DirectorySeparatorChar) && !App.Contains(Path.AltDirectorySeparatorChar))
                {
                    string[] PathDirectories = Environment.GetEnvironmentVariable("PATH").Split(Path.PathSeparator);
                    foreach (string PathDirectory in PathDirectories)
                    {
                        string TryApp = Path.Combine(PathDirectory, App);
                        if (FileExists(Options.HasFlag(ERunOptions.NoLoggingOfRunCommand), TryApp))
                        {
                            App           = TryApp;
                            bExistsInPath = true;
                            break;
                        }
                    }
                }
                if (!bExistsInPath)
                {
                    throw new AutomationException("BUILD FAILED: Couldn't find the executable to Run: {0}", App);
                }
            }
            var StartTime = DateTime.UtcNow;

            UnrealBuildTool.LogEventType SpewVerbosity = Options.HasFlag(ERunOptions.SpewIsVerbose) ? UnrealBuildTool.LogEventType.Verbose : UnrealBuildTool.LogEventType.Console;
            if (!Options.HasFlag(ERunOptions.NoLoggingOfRunCommand))
            {
                LogWithVerbosity(SpewVerbosity, "Run: " + App + " " + (String.IsNullOrEmpty(CommandLine) ? "" : CommandLine));
            }
            IProcessResult Result = ProcessManager.CreateProcess(App, Options.HasFlag(ERunOptions.AllowSpew), LogName, Env, SpewVerbosity: SpewVerbosity, SpewFilterCallback: SpewFilterCallback);
            Process        Proc   = Result.ProcessObject;

            bool bRedirectStdOut = (Options & ERunOptions.NoStdOutRedirect) != ERunOptions.NoStdOutRedirect;

            Proc.StartInfo.FileName        = App;
            Proc.StartInfo.Arguments       = String.IsNullOrEmpty(CommandLine) ? "" : CommandLine;
            Proc.StartInfo.UseShellExecute = false;
            if (bRedirectStdOut)
            {
                Proc.StartInfo.RedirectStandardOutput = true;
                Proc.StartInfo.RedirectStandardError  = true;
                Proc.OutputDataReceived += Result.StdOut;
                Proc.ErrorDataReceived  += Result.StdErr;
            }
            Proc.StartInfo.RedirectStandardInput = Input != null;
            Proc.StartInfo.CreateNoWindow        = true;
            if ((Options & ERunOptions.UTF8Output) == ERunOptions.UTF8Output)
            {
                Proc.StartInfo.StandardOutputEncoding = new System.Text.UTF8Encoding(false, false);
            }
            Proc.Start();

            if (bRedirectStdOut)
            {
                Proc.BeginOutputReadLine();
                Proc.BeginErrorReadLine();
            }

            if (String.IsNullOrEmpty(Input) == false)
            {
                Proc.StandardInput.WriteLine(Input);
                Proc.StandardInput.Close();
            }

            if (!Options.HasFlag(ERunOptions.NoWaitForExit))
            {
                Result.WaitForExit();
                var BuildDuration = (DateTime.UtcNow - StartTime).TotalMilliseconds;
                AddRunTime(App, (int)(BuildDuration));
                Result.ExitCode = Proc.ExitCode;
                if (!Options.HasFlag(ERunOptions.NoLoggingOfRunCommand) || Options.HasFlag(ERunOptions.LoggingOfRunDuration))
                {
                    LogWithVerbosity(SpewVerbosity, "Run: Took {0}s to run {1}, ExitCode={2}", BuildDuration / 1000, Path.GetFileName(App), Result.ExitCode);
                }
                Result.OnProcessExited();
                Result.DisposeProcess();
            }
            else
            {
                Result.ExitCode = -1;
            }

            return(Result);
        }