public override void SetupOptionsForRun(ref string AppName, ref CommandUtils.ERunOptions Options, ref string CommandLine) { if (AppName == "sh" || AppName == "xbuild" || AppName == "codesign") { Options &= ~CommandUtils.ERunOptions.AppMustExist; } if (AppName == "xbuild") { AppName = "sh"; CommandLine = "-c 'xbuild " + (String.IsNullOrEmpty(CommandLine) ? "" : CommandLine) + " /p:DefineConstants=MONO /verbosity:quiet /nologo |grep -i error; if [ $? -ne 1 ]; then exit 1; else exit 0; fi'"; } if (AppName.EndsWith(".exe") || ((AppName.Contains("/Binaries/Win64/") || AppName.Contains("/Binaries/Mac/")) && string.IsNullOrEmpty(Path.GetExtension(AppName)))) { if (AppName.Contains("/Binaries/Win64/") || AppName.Contains("/Binaries/Mac/")) { AppName = AppName.Replace("/Binaries/Win64/", "/Binaries/Mac/"); AppName = AppName.Replace("-cmd.exe", ""); AppName = AppName.Replace("-Cmd.exe", ""); AppName = AppName.Replace(".exe", ""); string AppFilename = Path.GetFileName(AppName); if (!CommandUtils.FileExists(AppName)) { AppName = AppName + ".app/Contents/MacOS/" + AppFilename; } } else { // It's a C# app, so run it with Mono CommandLine = "\"" + AppName + "\" " + (String.IsNullOrEmpty(CommandLine) ? "" : CommandLine); AppName = "mono"; Options &= ~CommandUtils.ERunOptions.AppMustExist; } } }
/// <summary> /// Builds a script module (csproj file) /// </summary> /// <param name="ProjectFile"></param> /// <returns></returns> private static bool CompileScriptModule(string ProjectFile) { if (!ProjectFile.EndsWith(".csproj", StringComparison.InvariantCultureIgnoreCase)) { throw new AutomationException(String.Format("Unable to build Project {0}. Not a valid .csproj file.", ProjectFile)); } if (!CommandUtils.FileExists(ProjectFile)) { throw new AutomationException(String.Format("Unable to build Project {0}. Project file not found.", ProjectFile)); } var CmdLine = String.Format("\"{0}\" /verbosity:quiet /nologo /target:Build /property:Configuration={1} /property:Platform=AnyCPU /p:TreatWarningsAsErrors=false /p:NoWarn=\"612,618,672\" /p:BuildProjectReferences=true", ProjectFile, BuildConfig); // Compile the project var Result = CommandUtils.Run(CommandUtils.CmdEnv.MsBuildExe, CmdLine); if (Result.ExitCode != 0) { throw new AutomationException(String.Format("Failed to build \"{0}\":{1}{2}", ProjectFile, Environment.NewLine, Result.Output)); } else { // Remove .Automation.csproj and copy to target dir Log.TraceVerbose("Successfully compiled {0}", ProjectFile); } return(Result.ExitCode == 0); }
/// <summary> /// Sets the location of the exe. /// </summary> protected void SetUATLocation() { if (String.IsNullOrEmpty(UATExe)) { UATExe = Assembly.GetEntryAssembly().GetOriginalLocation(); } if (!CommandUtils.FileExists(UATExe)) { throw new AutomationException("Could not find AutomationTool.exe. Reflection indicated it was here: {0}", UATExe); } }
/// <summary> /// Checks whether a path exists /// </summary> /// <param name="Scalar">The path to check for</param> /// <returns>True if the path exists, false otherwise.</returns> static bool Exists(string Scalar) { try { string FullPath = Path.Combine(CommandUtils.RootDirectory.FullName, Scalar); return(CommandUtils.FileExists(FullPath) || CommandUtils.DirectoryExists(FullPath)); } catch { return(false); } }
/// <summary> /// Returns the path to an executable in the System Directory. /// To help support running 32-bit assemblies on a 64-bit operating system, if the executable /// can't be found in System32, we also search Sysnative. /// </summary> /// <param name="ExeName">The name of the executable to find</param> /// <returns>The path to the executable within the system folder</returns> string GetSystemExePath(string ExeName) { var Result = CommandUtils.CombinePaths(Environment.SystemDirectory, ExeName); if (!CommandUtils.FileExists(Result)) { // Use Regex.Replace so we can do a case-insensitive replacement of System32 var SysNativeDirectory = Regex.Replace(Environment.SystemDirectory, "System32", "Sysnative", RegexOptions.IgnoreCase); var SysNativeExe = CommandUtils.CombinePaths(SysNativeDirectory, ExeName); if (CommandUtils.FileExists(SysNativeExe)) { Result = SysNativeExe; } } return(Result); }
/// <summary> /// Initializes the environment. /// </summary> internal CommandEnvironment() { // Get the path to the UAT executable UATExe = Assembly.GetEntryAssembly().GetOriginalLocation(); if (!CommandUtils.FileExists(UATExe)) { throw new AutomationException("Could not find AutomationTool.exe. Reflection indicated it was here: {0}", UATExe); } // Find the root directory (containing the Engine folder) LocalRoot = CommandUtils.GetEnvVar(EnvVarNames.LocalRoot); if (String.IsNullOrEmpty(LocalRoot)) { LocalRoot = CommandUtils.ConvertSeparators(PathSeparator.Slash, Path.GetFullPath(Path.Combine(Path.GetDirectoryName(UATExe), "..", "..", ".."))); CommandUtils.ConditionallySetEnvVar(EnvVarNames.LocalRoot, LocalRoot); } string SavedPath = CommandUtils.GetEnvVar(EnvVarNames.EngineSavedFolder); if (String.IsNullOrEmpty(SavedPath)) { SavedPath = CommandUtils.CombinePaths(PathSeparator.Slash, LocalRoot, "Engine", "Programs", "AutomationTool", "Saved"); CommandUtils.SetEnvVar(EnvVarNames.EngineSavedFolder, SavedPath); } EngineSavedFolder = CommandUtils.GetEnvVar(EnvVarNames.EngineSavedFolder); CSVFile = CommandUtils.GetEnvVar(EnvVarNames.CSVFile); LogFolder = CommandUtils.GetEnvVar(EnvVarNames.LogFolder); if (String.IsNullOrEmpty(LogFolder)) { if (GlobalCommandLine.Installed) { LogFolder = GetInstalledLogFolder(); } else { LogFolder = CommandUtils.CombinePaths(PathSeparator.Slash, EngineSavedFolder, "Logs"); } CommandUtils.SetEnvVar(EnvVarNames.LogFolder, LogFolder); } // clear the logfolder if we're the only running instance if (InternalUtils.IsSoleInstance) { ClearLogFolder(LogFolder); } FinalLogFolder = CommandUtils.GetEnvVar(EnvVarNames.FinalLogFolder); if (String.IsNullOrEmpty(FinalLogFolder)) { FinalLogFolder = LogFolder; CommandUtils.SetEnvVar(EnvVarNames.FinalLogFolder, FinalLogFolder); } RobocopyExe = GetSystemExePath("robocopy.exe"); MountExe = GetSystemExePath("mount.exe"); CmdExe = Utils.IsRunningOnMono ? "/bin/sh" : GetSystemExePath("cmd.exe"); MallocNanoZone = "0"; CommandUtils.SetEnvVar(EnvVarNames.MacMallocNanoZone, MallocNanoZone); int IsChildInstanceInt; int.TryParse(CommandUtils.GetEnvVar("uebp_UATChildInstance", "0"), out IsChildInstanceInt); IsChildInstance = (IsChildInstanceInt != 0); // Setup the timestamp string DateTime LocalTime = DateTime.Now; string TimeStamp = LocalTime.Year + "-" + LocalTime.Month.ToString("00") + "-" + LocalTime.Day.ToString("00") + "_" + LocalTime.Hour.ToString("00") + "." + LocalTime.Minute.ToString("00") + "." + LocalTime.Second.ToString("00"); TimestampAsString = TimeStamp; SetupBuildEnvironment(); LogSettings(); }