/// <summary> /// Runs UAT recursively /// </summary> /// <param name="Env">Environment to use.</param> /// <param name="CommandLine">Commandline to pass on to the executable</param> public static string RunUAT(CommandEnvironment Env, string CommandLine) { // this doesn't do much, but it does need to make sure log folders are reasonable and don't collide string BaseLogSubdir = "Recur"; if (!String.IsNullOrEmpty(CommandLine)) { int Space = CommandLine.IndexOf(" "); if (Space > 0) { BaseLogSubdir = BaseLogSubdir + "_" + CommandLine.Substring(0, Space); } else { BaseLogSubdir = BaseLogSubdir + "_" + CommandLine; } } int Index = 0; BaseLogSubdir = BaseLogSubdir.Trim(); string DirOnlyName = BaseLogSubdir; string LogSubdir = CombinePaths(CmdEnv.LogFolder, DirOnlyName, ""); while (true) { var ExistingFiles = FindFiles(DirOnlyName + "*", false, CmdEnv.LogFolder); if (ExistingFiles.Length == 0) { break; } Index++; if (Index == 1000) { throw new AutomationException("Couldn't seem to create a log subdir {0}", LogSubdir); } DirOnlyName = String.Format("{0}_{1}_", BaseLogSubdir, Index); LogSubdir = CombinePaths(CmdEnv.LogFolder, DirOnlyName, ""); } string LogFile = CombinePaths(CmdEnv.LogFolder, DirOnlyName + ".log"); Log("Recursive UAT Run, in log folder {0}, main log file {1}", LogSubdir, LogFile); CreateDirectory(LogSubdir); CommandLine = CommandLine + " -NoCompile"; string App = CmdEnv.UATExe; Log("Running {0} {1}", App, CommandLine); var OSEnv = new Dictionary <string, string>(); OSEnv.Add(AutomationTool.EnvVarNames.LogFolder, LogSubdir); OSEnv.Add("uebp_UATMutexNoWait", "1"); if (!IsBuildMachine) { OSEnv.Add(AutomationTool.EnvVarNames.LocalRoot, ""); // if we don't clear this out, it will think it is a build machine; it will rederive everything } ProcessResult Result = Run(App, CommandLine, null, ERunOptions.Default, OSEnv); if (Result.Output.Length > 0) { WriteToFile(LogFile, Result.Output); } else { WriteToFile(LogFile, "[None!, no output produced]"); } Log("Flattening log folder {0}", LogSubdir); var Files = FindFiles("*", true, LogSubdir); string MyLogFolder = CombinePaths(CmdEnv.LogFolder, ""); foreach (var ThisFile in Files) { if (!ThisFile.StartsWith(MyLogFolder, StringComparison.InvariantCultureIgnoreCase)) { throw new AutomationException("Can't rebase {0} because it doesn't start with {1}", ThisFile, MyLogFolder); } string NewFilename = ThisFile.Substring(MyLogFolder.Length).Replace("/", "_").Replace("\\", "_"); NewFilename = CombinePaths(CmdEnv.LogFolder, NewFilename); if (FileExists_NoExceptions(NewFilename)) { throw new AutomationException("Destination log file already exists? {0}", NewFilename); } CopyFile(ThisFile, NewFilename); if (!FileExists_NoExceptions(NewFilename)) { throw new AutomationException("Destination log file could not be copied {0}", NewFilename); } DeleteFile_NoExceptions(ThisFile); } DeleteDirectory_NoExceptions(LogSubdir); if (Result != 0) { throw new AutomationException(String.Format("Recursive UAT Command failed (Result:{3}): {0} {1}. See logfile for details: '{2}' ", App, CommandLine, Path.GetFileName(LogFile), Result.ExitCode)); } return(LogFile); }
/// <summary> /// Runs UAT recursively /// </summary> /// <param name="Env">Environment to use.</param> /// <param name="CommandLine">Commandline to pass on to the executable</param> public static string RunUAT(CommandEnvironment Env, string CommandLine) { // We want to redirect the output from recursive UAT calls into our normal log folder, but prefix everything with a unique identifier. To do so, we set the EnvVarNames.LogFolder environment // variable to a subfolder of it, then copy its contents into the main folder with a prefix after it's finished. Start by finding a base name we can use to identify the output of this run. string BaseLogSubdir = "Recur"; if (!String.IsNullOrEmpty(CommandLine)) { int Space = CommandLine.IndexOf(" "); if (Space > 0) { BaseLogSubdir = BaseLogSubdir + "_" + CommandLine.Substring(0, Space); } else if (CommandLine.Contains("-profile")) { string PathToProfile = CommandLine.Substring(CommandLine.IndexOf('=') + 1); BaseLogSubdir = BaseLogSubdir + "_" + (Path.GetFileNameWithoutExtension(PathToProfile)); } else { BaseLogSubdir = BaseLogSubdir + "_" + CommandLine; } } BaseLogSubdir = BaseLogSubdir.Trim(); // Check if there are already log files which start with this prefix, and try to uniquify it if until there aren't. int Index = 0; string DirOnlyName = BaseLogSubdir; string LogSubdir = CombinePaths(CmdEnv.LogFolder, DirOnlyName, ""); while (true) { var ExistingFiles = FindFiles(DirOnlyName + "*", false, CmdEnv.LogFolder); if (ExistingFiles.Length == 0) { break; } Index++; if (Index == 1000) { throw new AutomationException("Couldn't seem to create a log subdir {0}", LogSubdir); } DirOnlyName = String.Format("{0}_{1}_", BaseLogSubdir, Index); LogSubdir = CombinePaths(CmdEnv.LogFolder, DirOnlyName, ""); } // Get the stdout log file for this run, and create the subdirectory for all the other log output string LogFile = CombinePaths(CmdEnv.LogFolder, DirOnlyName + ".log"); LogVerbose("Recursive UAT Run, in log folder {0}, main log file {1}", LogSubdir, LogFile); CreateDirectory(LogSubdir); // Run UAT with the log folder redirected through the environment string App = CmdEnv.UATExe; Log("Running {0} {1}", App, CommandLine); var OSEnv = new Dictionary <string, string>(); OSEnv.Add(AutomationTool.EnvVarNames.LogFolder, LogSubdir); OSEnv.Add("uebp_UATMutexNoWait", "1"); if (!IsBuildMachine) { OSEnv.Add(AutomationTool.EnvVarNames.LocalRoot, ""); // if we don't clear this out, it will think it is a build machine; it will rederive everything } ProcessResult Result = Run(App, CommandLine, null, ERunOptions.Default, OSEnv); if (Result.Output.Length > 0) { WriteToFile(LogFile, Result.Output); } else { WriteToFile(LogFile, "[None!, no output produced]"); } // Copy everything into the main log folder, using the prefix we decided on earlier. LogVerbose("Flattening log folder {0}", LogSubdir); var Files = FindFiles("*", true, LogSubdir); string MyLogFolder = CombinePaths(CmdEnv.LogFolder, ""); foreach (var ThisFile in Files) { if (!ThisFile.StartsWith(MyLogFolder, StringComparison.InvariantCultureIgnoreCase)) { throw new AutomationException("Can't rebase {0} because it doesn't start with {1}", ThisFile, MyLogFolder); } string NewFilename = ThisFile.Substring(MyLogFolder.Length).Replace("/", "_").Replace("\\", "_"); NewFilename = CombinePaths(CmdEnv.LogFolder, NewFilename); if (FileExists_NoExceptions(NewFilename)) { throw new AutomationException("Destination log file already exists? {0}", NewFilename); } CopyFile(ThisFile, NewFilename); if (!FileExists_NoExceptions(NewFilename)) { throw new AutomationException("Destination log file could not be copied {0}", NewFilename); } DeleteFile_NoExceptions(ThisFile); } DeleteDirectory_NoExceptions(LogSubdir); if (Result != 0) { throw new AutomationException(String.Format("Recursive UAT Command failed (Result:{3}): {0} {1}. See logfile for details: '{2}' ", App, CommandLine, Path.GetFileName(LogFile), Result.ExitCode)); } return(LogFile); }