virtual protected bool ResolveBuildReference(string InBuildReference, Func <string, string> ResolutionDelegate, out IEnumerable <string> OutBuildPaths, out string OutBuildName) { OutBuildName = null; OutBuildPaths = null; if (string.IsNullOrEmpty(InBuildReference)) { return(false); } if (InBuildReference.Equals("AutoP4", StringComparison.InvariantCultureIgnoreCase)) { if (!CommandUtils.P4Enabled) { throw new AutomationException("-Build=AutoP4 requires -P4"); } if (CommandUtils.P4Env.Changelist < 1000) { throw new AutomationException("-Build=AutoP4 requires a CL from P4 and we have {0}", CommandUtils.P4Env.Changelist); } string BuildRoot = CommandUtils.CombinePaths(CommandUtils.RootBuildStorageDirectory()); string CachePath = InternalUtils.GetEnvironmentVariable("UE-BuildCachePath", ""); string SrcBuildPath = CommandUtils.CombinePaths(BuildRoot, ProjectName); string SrcBuildPath2 = CommandUtils.CombinePaths(BuildRoot, ProjectName.Replace("Game", "").Replace("game", "")); string SrcBuildPath_Cache = CommandUtils.CombinePaths(CachePath, ProjectName); string SrcBuildPath2_Cache = CommandUtils.CombinePaths(CachePath, ProjectName.Replace("Game", "").Replace("game", "")); if (!InternalUtils.SafeDirectoryExists(SrcBuildPath)) { if (!InternalUtils.SafeDirectoryExists(SrcBuildPath2)) { throw new AutomationException("-Build=AutoP4: Neither {0} nor {1} exists.", SrcBuildPath, SrcBuildPath2); } SrcBuildPath = SrcBuildPath2; SrcBuildPath_Cache = SrcBuildPath2_Cache; } string SrcCLPath = CommandUtils.CombinePaths(SrcBuildPath, CommandUtils.EscapePath(CommandUtils.P4Env.Branch) + "-CL-" + CommandUtils.P4Env.Changelist.ToString()); string SrcCLPath_Cache = CommandUtils.CombinePaths(SrcBuildPath_Cache, CommandUtils.EscapePath(CommandUtils.P4Env.Branch) + "-CL-" + CommandUtils.P4Env.Changelist.ToString()); if (!InternalUtils.SafeDirectoryExists(SrcCLPath)) { throw new AutomationException("-Build=AutoP4: {0} does not exist.", SrcCLPath); } if (InternalUtils.SafeDirectoryExists(SrcCLPath_Cache)) { InBuildReference = SrcCLPath_Cache; } else { InBuildReference = SrcCLPath; } Log.Verbose("Using AutoP4 path {0}", InBuildReference); } // BuildParam could be a path, a name that we should resolve to a path, Staged, or Editor DirectoryInfo BuildDir = new DirectoryInfo(InBuildReference); if (BuildDir.Exists) { // Easy option first - is this a full path? OutBuildName = BuildDir.Name; OutBuildPaths = new string[] { BuildDir.FullName }; } else if (BuildDir.Name.Equals("local", StringComparison.OrdinalIgnoreCase) || BuildDir.Name.Equals("staged", StringComparison.OrdinalIgnoreCase)) { // First special case - "Staged" means use whats locally staged OutBuildName = "Local"; string StagedPath = Path.Combine(ProjectPath.Directory.FullName, "Saved", "StagedBuilds"); if (Directory.Exists(StagedPath) == false) { Log.Error("BuildReference was Staged but staged directory {0} not found", StagedPath); return(false); } // include binaries path for packaged builds if it exists string BinariesPath = Path.Combine(ProjectPath.Directory.FullName, "Binaries"); OutBuildPaths = Directory.Exists(BinariesPath) ? new string[] { StagedPath, BinariesPath } : new string[] { StagedPath }; } else if (BuildDir.Name.Equals("editor", StringComparison.OrdinalIgnoreCase)) { // Second special case - "Editor" means run using the editor, no path needed OutBuildName = "Editor"; OutBuildPaths = new string[] { Environment.CurrentDirectory }; } else { // todo - make this more generic if (BuildDir.Name.Equals("usesyncedbuild", StringComparison.OrdinalIgnoreCase)) { BuildVersion Version; if (BuildVersion.TryRead(BuildVersion.GetDefaultFileName(), out Version)) { InBuildReference = Version.BranchName + "-CL-" + Version.Changelist.ToString(); } } // See if it's in the passed locations if (ResolutionDelegate != null) { string FullPath = ResolutionDelegate(InBuildReference); if (string.IsNullOrEmpty(FullPath) == false) { DirectoryInfo Di = new DirectoryInfo(FullPath); if (Di.Exists == false) { throw new AutomationException("Resolution delegate returned non existent path"); } OutBuildName = Di.Name; OutBuildPaths = new string[] { Di.FullName }; } } } if (string.IsNullOrEmpty(OutBuildName) || (OutBuildPaths == null || OutBuildPaths.Count() == 0)) { Log.Error("Unable to resolve build argument '{0}'", InBuildReference); return(false); } return(true); }
/// <summary> /// For not-installed runs, returns a temp log folder to make sure it doesn't fall into sandbox paths /// </summary> /// <returns></returns> private static string GetLogFolderOutsideOfSandbox() { return(GlobalCommandLine.Installed ? CmdEnv.LogFolder : CombinePaths(Path.GetTempPath(), CommandUtils.EscapePath(CmdEnv.LocalRoot), "Logs")); }
protected void InitBuildSource(string InProjectName, bool InUsesSharedBuildType, string InUnrealPath, string InBuildArgument, Func <string, string> ResolutionDelegate) { if (InBuildArgument.Equals("AutoP4", StringComparison.InvariantCultureIgnoreCase)) { if (!CommandUtils.P4Enabled) { throw new AutomationException("-Build=AutoP4 requires -P4"); } if (CommandUtils.P4Env.Changelist < 1000) { throw new AutomationException("-Build=AutoP4 requires a CL from P4 and we have {0}", CommandUtils.P4Env.Changelist); } string BuildRoot = CommandUtils.CombinePaths(CommandUtils.RootBuildStorageDirectory()); string CachePath = InternalUtils.GetEnvironmentVariable("UE-BuildCachePath", ""); string SrcBuildPath = CommandUtils.CombinePaths(BuildRoot, InProjectName); string SrcBuildPath2 = CommandUtils.CombinePaths(BuildRoot, InProjectName.Replace("Game", "").Replace("game", "")); string SrcBuildPath_Cache = CommandUtils.CombinePaths(CachePath, InProjectName); string SrcBuildPath2_Cache = CommandUtils.CombinePaths(CachePath, InProjectName.Replace("Game", "").Replace("game", "")); if (!InternalUtils.SafeDirectoryExists(SrcBuildPath)) { if (!InternalUtils.SafeDirectoryExists(SrcBuildPath2)) { throw new AutomationException("-Build=AutoP4: Neither {0} nor {1} exists.", SrcBuildPath, SrcBuildPath2); } SrcBuildPath = SrcBuildPath2; SrcBuildPath_Cache = SrcBuildPath2_Cache; } string SrcCLPath = CommandUtils.CombinePaths(SrcBuildPath, CommandUtils.EscapePath(CommandUtils.P4Env.Branch) + "-CL-" + CommandUtils.P4Env.Changelist.ToString()); string SrcCLPath_Cache = CommandUtils.CombinePaths(SrcBuildPath_Cache, CommandUtils.EscapePath(CommandUtils.P4Env.Branch) + "-CL-" + CommandUtils.P4Env.Changelist.ToString()); if (!InternalUtils.SafeDirectoryExists(SrcCLPath)) { throw new AutomationException("-Build=AutoP4: {0} does not exist.", SrcCLPath); } if (InternalUtils.SafeDirectoryExists(SrcCLPath_Cache)) { InBuildArgument = SrcCLPath_Cache; } else { InBuildArgument = SrcCLPath; } Log.Verbose("Using AutoP4 path {0}", InBuildArgument); } UnrealPath = InUnrealPath; UsesSharedBuildType = InUsesSharedBuildType; ResolveProjectName(InProjectName); // Resolve the build argument into something meaningful string ResolvedBuildPath, ResolvedBuildName; if (!ResolveBuildReference(InBuildArgument, ResolutionDelegate, out ResolvedBuildPath, out ResolvedBuildName)) { throw new AutomationException("Unable to resolve {0} to a valid build", InBuildArgument); } BuildName = ResolvedBuildName; BuildPath = ResolvedBuildPath; DiscoveredBuilds = DiscoverBuilds(); if (DiscoveredBuilds.Count() == 0) { throw new AutomationException("No builds were discovered from resolved build argument {0}", InBuildArgument); } // any Branch/CL info? Match M = Regex.Match(BuildName, @"(\+\+.+)-CL-(\d+)"); if (M.Success) { Branch = M.Groups[1].Value.Replace("+", "/"); Changelist = Convert.ToInt32(M.Groups[2].Value); } else { Branch = ""; Changelist = 0; } // allow user overrides (TODO - centralize all this!) Branch = Globals.Params.ParseValue("branch", Branch); Changelist = Convert.ToInt32(Globals.Params.ParseValue("changelist", Changelist.ToString())); }