Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
        public static List <string> FindTempStorageManifests(CommandEnvironment Env, string StorageBlockName, bool LocalOnly = false, bool SharedOnly = false, string GameFolder = "")
        {
            var Files = new List <string>();

            var LocalFiles  = LocalTempStorageManifestFilename(Env, StorageBlockName);
            var LocalParent = Path.GetDirectoryName(LocalFiles);
            var WildCard    = Path.GetFileName(LocalFiles);

            int IndexOfStar = WildCard.IndexOf("*");

            if (IndexOfStar < 0 || WildCard.LastIndexOf("*") != IndexOfStar)
            {
                throw new AutomationException("Wildcard {0} either has no star or it has more than one.", WildCard);
            }

            string PreStarWildcard  = WildCard.Substring(0, IndexOfStar);
            string PostStarWildcard = Path.GetFileNameWithoutExtension(WildCard.Substring(IndexOfStar + 1));

            if (!SharedOnly && DirectoryExists_NoExceptions(LocalParent))
            {
                foreach (var ThisFile in CommandUtils.FindFiles_NoExceptions(WildCard, true, LocalParent))
                {
                    Log("  Found local file {0}", ThisFile);
                    int IndexOfWildcard = ThisFile.IndexOf(PreStarWildcard);
                    if (IndexOfWildcard < 0)
                    {
                        throw new AutomationException("File {0} didn't contain {1}.", ThisFile, PreStarWildcard);
                    }
                    int LastIndexOfWildcardTail = ThisFile.LastIndexOf(PostStarWildcard);
                    if (LastIndexOfWildcardTail < 0 || LastIndexOfWildcardTail < IndexOfWildcard + PreStarWildcard.Length)
                    {
                        throw new AutomationException("File {0} didn't contain {1} or it was before the prefix", ThisFile, PostStarWildcard);
                    }
                    string StarReplacement = ThisFile.Substring(IndexOfWildcard + PreStarWildcard.Length, LastIndexOfWildcardTail - IndexOfWildcard - PreStarWildcard.Length);
                    if (StarReplacement.Length < 1)
                    {
                        throw new AutomationException("Dir {0} didn't have any string to fit the star in the wildcard {1}", ThisFile, WildCard);
                    }
                    if (!Files.Contains(StarReplacement))
                    {
                        Files.Add(StarReplacement);
                    }
                }
            }

            if (!LocalOnly)
            {
                var SharedFiles  = SharedTempStorageManifestFilename(Env, StorageBlockName, GameFolder);
                var SharedParent = Path.GetDirectoryName(Path.GetDirectoryName(SharedFiles));

                if (DirectoryExists_NoExceptions(SharedParent))
                {
                    string[] Dirs = null;

                    try
                    {
                        Dirs = Directory.GetDirectories(SharedParent, Path.GetFileNameWithoutExtension(SharedFiles), SearchOption.TopDirectoryOnly);
                    }
                    catch (Exception Ex)
                    {
                        Log("Unable to Find Directories in {0} with wildcard {1}", SharedParent, Path.GetFileNameWithoutExtension(SharedFiles));
                        Log(" Exception was {0}", LogUtils.FormatException(Ex));
                    }
                    if (Dirs != null)
                    {
                        foreach (var ThisSubDir in Dirs)
                        {
                            int IndexOfWildcard = ThisSubDir.IndexOf(PreStarWildcard);
                            if (IndexOfWildcard < 0)
                            {
                                throw new AutomationException("Dir {0} didn't contain {1}.", ThisSubDir, PreStarWildcard);
                            }
                            int LastIndexOfWildcardTail = ThisSubDir.LastIndexOf(PostStarWildcard);
                            if (LastIndexOfWildcardTail < 0 || LastIndexOfWildcardTail < IndexOfWildcard + PreStarWildcard.Length)
                            {
                                throw new AutomationException("Dir {0} didn't contain {1} or it was before the prefix", ThisSubDir, PostStarWildcard);
                            }
                            string StarReplacement = ThisSubDir.Substring(IndexOfWildcard + PreStarWildcard.Length, LastIndexOfWildcardTail - IndexOfWildcard - PreStarWildcard.Length);
                            if (StarReplacement.Length < 1)
                            {
                                throw new AutomationException("Dir {0} didn't have any string to fit the star in the wildcard {1}", ThisSubDir, WildCard);
                            }
                            // these are a bunch of false positives
                            if (StarReplacement.Contains("-"))
                            {
                                continue;
                            }
                            if (!Files.Contains(StarReplacement))
                            {
                                Files.Add(StarReplacement);
                            }
                        }
                    }
                }
            }

            var OutFiles = new List <string>();

            foreach (var StarReplacement in Files)
            {
                var NewBlock = StorageBlockName.Replace("*", StarReplacement);

                if (TempStorageExists(Env, NewBlock, GameFolder, LocalOnly, true))
                {
                    OutFiles.Add(StarReplacement);
                }
            }
            return(OutFiles);
        }