public int ArchiveFiles(string InPath, string Wildcard = "*", bool bRecursive = true, string[] ExcludeWildcard = null, string NewPath = null) { int FilesAdded = 0; if (CommandUtils.DirectoryExists(InPath)) { var All = CommandUtils.FindFiles(Wildcard, bRecursive, InPath); var Exclude = new HashSet <string>(); if (ExcludeWildcard != null) { foreach (var Excl in ExcludeWildcard) { var Remove = CommandUtils.FindFiles(Excl, bRecursive, InPath); foreach (var File in Remove) { Exclude.Add(CommandUtils.CombinePaths(File)); } } } foreach (var AllFile in All) { var FileToCopy = CommandUtils.CombinePaths(AllFile); if (Exclude.Contains(FileToCopy)) { continue; } if (!bIsCombiningMultiplePlatforms) { FileReference InputFile = new FileReference(FileToCopy); bool OtherPlatform = false; foreach (UnrealTargetPlatform Plat in Enum.GetValues(typeof(UnrealTargetPlatform))) { if (Plat != StageTargetPlatform.PlatformType && Plat != UnrealTargetPlatform.Unknown) { var Search = FileToCopy; if (InputFile.IsUnderDirectory(LocalRoot)) { Search = InputFile.MakeRelativeTo(LocalRoot); } else if (InputFile.IsUnderDirectory(ProjectRoot)) { Search = InputFile.MakeRelativeTo(ProjectRoot); } if (Search.IndexOf(CommandUtils.CombinePaths("/" + Plat.ToString() + "/"), 0, StringComparison.InvariantCultureIgnoreCase) >= 0) { OtherPlatform = true; break; } } } if (OtherPlatform) { continue; } } string Dest; if (!FileToCopy.StartsWith(InPath)) { throw new AutomationException("Can't archive {0}; it was supposed to start with {1}", FileToCopy, InPath); } // If the specified a new directory, first we deal with that, then apply the other things // this is used to collapse the sandbox, among other things if (NewPath != null) { Dest = FileToCopy.Substring(InPath.Length); if (Dest.StartsWith("/") || Dest.StartsWith("\\")) { Dest = Dest.Substring(1); } Dest = CommandUtils.CombinePaths(NewPath, Dest); } else { Dest = FileToCopy.Substring(InPath.Length); } if (Dest.StartsWith("/") || Dest.StartsWith("\\")) { Dest = Dest.Substring(1); } if (ArchivedFiles.ContainsKey(FileToCopy)) { if (ArchivedFiles[FileToCopy] != Dest) { throw new AutomationException("Can't archive {0}: it was already in the files to archive with a different destination '{1}'", FileToCopy, Dest); } } else { ArchivedFiles.Add(FileToCopy, Dest); } FilesAdded++; } } return(FilesAdded); }
/// <summary> /// Retrieves and saves all artifacts from the provided session role. Artifacts are saved to the destination path /// </summary> /// <param name="InContext"></param> /// <param name="InRunningRole"></param> /// <param name="InDestArtifactPath"></param> /// <returns></returns> public UnrealRoleArtifacts SaveRoleArtifacts(UnrealTestContext InContext, UnrealSessionInstance.RoleInstance InRunningRole, string InDestArtifactPath) { bool IsServer = InRunningRole.Role.RoleType.IsServer(); string RoleName = (InRunningRole.Role.IsDummy() ? "Dummy" : "") + InRunningRole.Role.RoleType.ToString(); UnrealTargetPlatform?Platform = InRunningRole.Role.Platform; string RoleConfig = InRunningRole.Role.Configuration.ToString(); Directory.CreateDirectory(InDestArtifactPath); // Don't archive editor data, there can be a *lot* of stuff in that saved folder! bool IsEditor = InRunningRole.Role.RoleType.UsesEditor(); bool IsDevBuild = InContext.TestParams.ParseParam("dev"); string DestSavedDir = Path.Combine(InDestArtifactPath, "Saved"); string SourceSavedDir = ""; // save the contents of the saved directory SourceSavedDir = InRunningRole.AppInstance.ArtifactPath; // save the output from TTY string ArtifactLogPath = Path.Combine(InDestArtifactPath, RoleName + "Output.log"); // Write a brief Gauntlet header to aid debugging StringBuilder LogOut = new StringBuilder(); LogOut.AppendLine("------ Gauntlet Test ------"); LogOut.AppendFormat("Role: {0}\r\n", InRunningRole.Role); LogOut.AppendFormat("Automation Command: {0}\r\n", Environment.CommandLine); LogOut.AppendLine("---------------------------"); // Write instance stdout stream LogOut.Append(InRunningRole.AppInstance.StdOut); File.WriteAllText(ArtifactLogPath, LogOut.ToString()); Log.Info("Wrote Log to {0}", ArtifactLogPath); if (IsServer == false) { // gif-ify and jpeg-ify any screenshots try { string ScreenshotPath = Path.Combine(SourceSavedDir, "Screenshots", Platform.ToString()).ToLower(); if (Directory.Exists(ScreenshotPath) && Directory.GetFiles(ScreenshotPath).Length > 0) { Log.Info("Downsizing and gifying session images at {0}", ScreenshotPath); // downsize first so gif-step is quicker and takes less resoruces. Utils.Image.ConvertImages(ScreenshotPath, ScreenshotPath, "jpg", true); string GifPath = Path.Combine(InDestArtifactPath, RoleName + "Test.gif"); if (Utils.Image.SaveImagesAsGif(ScreenshotPath, GifPath)) { Log.Info("Saved gif to {0}", GifPath); } } } catch (Exception Ex) { Log.Info("Failed to downsize and gif-ify images! {0}", Ex); } } // don't archive data in dev mode, because peoples saved data could be huuuuuuuge! if (IsEditor == false) { LogLevel OldLevel = Log.Level; Log.Level = LogLevel.Normal; if (Directory.Exists(SourceSavedDir)) { Utils.SystemHelpers.CopyDirectory(SourceSavedDir, DestSavedDir); Log.Info("Archived artifacts to to {0}", DestSavedDir); } else { Log.Info("Archive path '{0}' was not found!", SourceSavedDir); } Log.Level = OldLevel; } else { if (IsEditor) { Log.Info("Skipping archival of assets for editor {0}", RoleName); } else if (IsDevBuild) { Log.Info("Skipping archival of assets for dev build"); } } foreach (EIntendedBaseCopyDirectory ArtifactDir in InRunningRole.Role.AdditionalArtifactDirectories) { if (InRunningRole.AppInstance.Device.GetPlatformDirectoryMappings().ContainsKey(ArtifactDir)) { string SourcePath = InRunningRole.AppInstance.Device.GetPlatformDirectoryMappings()[ArtifactDir]; var DirToCopy = new DirectoryInfo(SourcePath); if (DirToCopy.Exists) { // Grab the final dir name to copy everything into so everything's not just going into root artifact dir. string IntendedCopyLocation = Path.Combine(InDestArtifactPath, DirToCopy.Name); Utils.SystemHelpers.CopyDirectory(SourcePath, IntendedCopyLocation); } } } // TODO REMOVEME- this should go elsewhere, likely a util that can be called or inserted by relevant test nodes. if (IsServer == false) { // Copy over PSOs try { if (InContext.Options.LogPSO) { foreach (var ThisFile in CommandUtils.FindFiles_NoExceptions(true, "*.rec.upipelinecache", true, DestSavedDir)) { bool Copied = false; var JustFile = Path.GetFileName(ThisFile); if (JustFile.StartsWith("++")) { var Parts = JustFile.Split(new Char[] { '+', '-' }).Where(A => A != "").ToArray(); if (Parts.Count() >= 2) { string ProjectName = Parts[0].ToString(); string BuildRoot = CommandUtils.CombinePaths(CommandUtils.RootBuildStorageDirectory()); string SrcBuildPath = CommandUtils.CombinePaths(BuildRoot, ProjectName); string SrcBuildPath2 = CommandUtils.CombinePaths(BuildRoot, ProjectName.Replace("Game", "").Replace("game", "")); if (!CommandUtils.DirectoryExists(SrcBuildPath)) { SrcBuildPath = SrcBuildPath2; } if (CommandUtils.DirectoryExists(SrcBuildPath)) { var JustBuildFolder = JustFile.Replace("-" + Parts.Last(), ""); string PlatformStr = Platform.ToString(); string SrcCLMetaPath = CommandUtils.CombinePaths(SrcBuildPath, JustBuildFolder, PlatformStr, "MetaData"); if (CommandUtils.DirectoryExists(SrcCLMetaPath)) { string SrcCLMetaPathCollected = CommandUtils.CombinePaths(SrcCLMetaPath, "CollectedPSOs"); if (!CommandUtils.DirectoryExists(SrcCLMetaPathCollected)) { Log.Info("Creating Directory {0}", SrcCLMetaPathCollected); CommandUtils.CreateDirectory(SrcCLMetaPathCollected); } if (CommandUtils.DirectoryExists(SrcCLMetaPathCollected)) { string DestFile = CommandUtils.CombinePaths(SrcCLMetaPathCollected, JustFile); CommandUtils.CopyFile_NoExceptions(ThisFile, DestFile, true); if (CommandUtils.FileExists(true, DestFile)) { Log.Info("Deleting local file, copied to {0}", DestFile); CommandUtils.DeleteFile_NoExceptions(ThisFile, true); Copied = true; } } } } } } if (!Copied) { Log.Warning("Could not find anywhere to put this file {0}", JustFile); } } } } catch (Exception Ex) { Log.Info("Failed to copy upipelinecaches to the network {0}", Ex); } } // END REMOVEME UnrealLogParser LogParser = new UnrealLogParser(InRunningRole.AppInstance.StdOut); int ExitCode = InRunningRole.AppInstance.ExitCode; LogParser.GetTestExitCode(out ExitCode); UnrealRoleArtifacts Artifacts = new UnrealRoleArtifacts(InRunningRole.Role, InRunningRole.AppInstance, InDestArtifactPath, ArtifactLogPath, LogParser); return(Artifacts); }
public DeploymentContext( FileReference RawProjectPathOrName, string InLocalRoot, string BaseStageDirectory, string BaseArchiveDirectory, Platform InSourcePlatform, Platform InTargetPlatform, List <UnrealTargetConfiguration> InTargetConfigurations, IEnumerable <StageTarget> InStageTargets, List <String> InStageExecutables, bool InServer, bool InCooked, bool InStageCrashReporter, bool InStage, bool InCookOnTheFly, bool InArchive, bool InProgram, bool IsClientInsteadOfNoEditor, bool InForceChunkManifests, bool bInUseWebsocketNetDriver = false ) { bStageCrashReporter = InStageCrashReporter; RawProjectPath = RawProjectPathOrName; DedicatedServer = InServer; LocalRoot = CommandUtils.CombinePaths(InLocalRoot); CookSourcePlatform = InSourcePlatform; StageTargetPlatform = InTargetPlatform; StageTargetConfigurations = new List <UnrealTargetConfiguration>(InTargetConfigurations); StageTargets = new List <StageTarget>(InStageTargets); StageExecutables = InStageExecutables; IsCodeBasedProject = ProjectUtils.IsCodeBasedUProjectFile(RawProjectPath); ShortProjectName = ProjectUtils.GetShortProjectName(RawProjectPath); Stage = InStage; Archive = InArchive; bUseWebsocketNetDriver = bInUseWebsocketNetDriver; if (CookSourcePlatform != null && InCooked) { CookPlatform = CookSourcePlatform.GetCookPlatform(DedicatedServer, IsClientInsteadOfNoEditor); } else if (CookSourcePlatform != null && InProgram) { CookPlatform = CookSourcePlatform.GetCookPlatform(false, false); } else { CookPlatform = ""; } if (StageTargetPlatform != null && InCooked) { FinalCookPlatform = StageTargetPlatform.GetCookPlatform(DedicatedServer, IsClientInsteadOfNoEditor); } else if (StageTargetPlatform != null && InProgram) { FinalCookPlatform = StageTargetPlatform.GetCookPlatform(false, false); } else { FinalCookPlatform = ""; } PlatformDir = StageTargetPlatform.PlatformType.ToString(); StageDirectory = CommandUtils.CombinePaths(BaseStageDirectory, FinalCookPlatform); ArchiveDirectory = CommandUtils.CombinePaths(BaseArchiveDirectory, FinalCookPlatform); if (!CommandUtils.FileExists(RawProjectPath.FullName)) { throw new AutomationException("Can't find uproject file {0}.", RawProjectPathOrName); } ProjectRoot = CommandUtils.CombinePaths(CommandUtils.GetDirectoryName(RawProjectPath.FullName)); if (!CommandUtils.DirectoryExists(ProjectRoot)) { throw new AutomationException("Project Directory {0} doesn't exist.", ProjectRoot); } RelativeProjectRootForStage = ShortProjectName; ProjectArgForCommandLines = CommandUtils.MakePathSafeToUseWithCommandLine(RawProjectPath.FullName); CookSourceRuntimeRootDir = RuntimeRootDir = LocalRoot; RuntimeProjectRootDir = ProjectRoot; RelativeProjectRootForUnrealPak = CommandUtils.CombinePaths(RelativeProjectRootForStage).Replace("\\", "/"); if (RelativeProjectRootForUnrealPak.StartsWith("/")) { RelativeProjectRootForUnrealPak = RelativeProjectRootForUnrealPak.Substring(1); RelativeProjectRootForStage = RelativeProjectRootForStage.Substring(1); } SourceRelativeProjectRoot = RelativeProjectRootForStage; // for foreign projects this doesn't make much sense, but it turns into a noop on staging files if (ProjectRoot.StartsWith(LocalRoot, StringComparison.InvariantCultureIgnoreCase)) { SourceRelativeProjectRoot = ProjectRoot.Substring(LocalRoot.Length); } if (SourceRelativeProjectRoot.StartsWith("/") || SourceRelativeProjectRoot.StartsWith("\\")) { SourceRelativeProjectRoot = SourceRelativeProjectRoot.Substring(1); } if (Stage) { CommandUtils.CreateDirectory(StageDirectory); StageProjectRoot = CommandUtils.CombinePaths(StageDirectory, RelativeProjectRootForStage); RuntimeRootDir = StageDirectory; CookSourceRuntimeRootDir = CommandUtils.CombinePaths(BaseStageDirectory, CookPlatform); RuntimeProjectRootDir = StageProjectRoot; ProjectArgForCommandLines = CommandUtils.MakePathSafeToUseWithCommandLine(UProjectCommandLineArgInternalRoot + RelativeProjectRootForStage + "/" + ShortProjectName + ".uproject"); } if (Archive) { CommandUtils.CreateDirectory(ArchiveDirectory); } ProjectArgForCommandLines = ProjectArgForCommandLines.Replace("\\", "/"); ProjectBinariesFolder = CommandUtils.CombinePaths(ProjectUtils.GetClientProjectBinariesRootPath(RawProjectPath, TargetRules.TargetType.Game, IsCodeBasedProject), PlatformDir); // If we were configured to use manifests across the whole project, then this platform should use manifests. // Otherwise, read whether we are generating chunks from the ProjectPackagingSettings ini. if (InForceChunkManifests) { PlatformUsesChunkManifests = true; } else { ConfigCacheIni GameIni = ConfigCacheIni.CreateConfigCacheIni(InTargetPlatform.PlatformType, "Game", RawProjectPath.Directory); String IniPath = "/Script/UnrealEd.ProjectPackagingSettings"; bool bSetting = false; if (GameIni.GetBool(IniPath, "bGenerateChunks", out bSetting)) { PlatformUsesChunkManifests = bSetting; } } }
public void StageFiles(StagedFileType FileType, string InPath, string Wildcard = "*", bool bRecursive = true, string[] ExcludeWildcard = null, string NewPath = null, bool bAllowNone = false, bool bRemap = true, string NewName = null, bool bAllowNotForLicenseesFiles = true, bool bStripFilesForOtherPlatforms = true, bool bConvertToLower = false) { int FilesAdded = 0; // make sure any ..'s are removed Utils.CollapseRelativeDirectories(ref InPath); if (CommandUtils.DirectoryExists(InPath)) { var All = CommandUtils.FindFiles(Wildcard, bRecursive, InPath); var Exclude = new HashSet <string>(); if (ExcludeWildcard != null) { foreach (var Excl in ExcludeWildcard) { var Remove = CommandUtils.FindFiles(Excl, bRecursive, InPath); foreach (var File in Remove) { Exclude.Add(CommandUtils.CombinePaths(File)); } } } foreach (var AllFile in All) { var FileToCopy = CommandUtils.CombinePaths(AllFile); if (Exclude.Contains(FileToCopy)) { continue; } if (!bAllowNotForLicenseesFiles && (FileToCopy.Contains("NotForLicensees") || FileToCopy.Contains("NoRedist"))) { continue; } if (bStripFilesForOtherPlatforms && !bIsCombiningMultiplePlatforms) { bool OtherPlatform = false; foreach (UnrealTargetPlatform Plat in Enum.GetValues(typeof(UnrealTargetPlatform))) { bool bMatchesIniPlatform = (AllFile.EndsWith(".ini") && Plat == StageTargetPlatform.IniPlatformType); // filter ini files for the ini file platform bool bMatchesTargetPlatform = (Plat == StageTargetPlatform.PlatformType || Plat == UnrealTargetPlatform.Unknown); // filter platform files for the target platform if (!bMatchesIniPlatform && !bMatchesTargetPlatform) { var Search = FileToCopy; if (Search.StartsWith(LocalRoot, StringComparison.InvariantCultureIgnoreCase)) { if (LocalRoot.EndsWith("\\") || LocalRoot.EndsWith("/")) { Search = Search.Substring(LocalRoot.Length - 1); } else { Search = Search.Substring(LocalRoot.Length); } } if (Search.StartsWith(ProjectRoot, StringComparison.InvariantCultureIgnoreCase)) { if (ProjectRoot.EndsWith("\\") || ProjectRoot.EndsWith("/")) { Search = Search.Substring(ProjectRoot.Length - 1); } else { Search = Search.Substring(ProjectRoot.Length); } } if (Search.IndexOf(CommandUtils.CombinePaths("/" + Plat.ToString() + "/"), 0, StringComparison.InvariantCultureIgnoreCase) >= 0) { OtherPlatform = true; break; } } } if (OtherPlatform) { continue; } } string Dest; if (!FileToCopy.StartsWith(InPath)) { throw new AutomationException("Can't deploy {0}; it was supposed to start with {1}", FileToCopy, InPath); } string FileToRemap = FileToCopy; // If the specified a new directory, first we deal with that, then apply the other things // this is used to collapse the sandbox, among other things if (NewPath != null) { Dest = FileToRemap.Substring(InPath.Length); if (Dest.StartsWith("/") || Dest.StartsWith("\\")) { Dest = Dest.Substring(1); } Dest = CommandUtils.CombinePaths(NewPath, Dest); #if false // if the cooker rebases, I don't think we need to ever rebase while staging to a new path if (Dest.StartsWith("/") || Dest.StartsWith("\\")) { Dest = Dest.Substring(1); } // project relative stuff in a collapsed sandbox if (Dest.StartsWith(SourceRelativeProjectRoot, StringComparison.InvariantCultureIgnoreCase)) { Dest = Dest.Substring(SourceRelativeProjectRoot.Length); if (Dest.StartsWith("/") || Dest.StartsWith("\\")) { Dest = Dest.Substring(1); } Dest = CommandUtils.CombinePaths(RelativeProjectRootForStage, Dest); } #endif } // project relative file else if (FileToRemap.StartsWith(ProjectRoot, StringComparison.InvariantCultureIgnoreCase)) { Dest = FileToRemap.Substring(ProjectRoot.Length); if (Dest.StartsWith("/") || Dest.StartsWith("\\")) { Dest = Dest.Substring(1); } Dest = CommandUtils.CombinePaths(RelativeProjectRootForStage, Dest); } // engine relative file else if (FileToRemap.StartsWith(LocalRoot, StringComparison.InvariantCultureIgnoreCase)) { Dest = CommandUtils.CombinePaths(FileToRemap.Substring(LocalRoot.Length)); } else { throw new AutomationException("Can't deploy {0} because it doesn't start with {1} or {2}", FileToRemap, ProjectRoot, LocalRoot); } if (Dest.StartsWith("/") || Dest.StartsWith("\\")) { Dest = Dest.Substring(1); } if (NewName != null) { Dest = CommandUtils.CombinePaths(Path.GetDirectoryName(Dest), NewName); } if (bRemap) { Dest = StageTargetPlatform.Remap(Dest); } if (bConvertToLower) { Dest = Dest.ToLowerInvariant(); } if (FileType == StagedFileType.UFS) { AddUniqueStagingFile(UFSStagingFiles, FileToCopy, Dest); } else if (FileType == StagedFileType.NonUFS) { AddStagingFile(NonUFSStagingFiles, FileToCopy, Dest); } else if (FileType == StagedFileType.DebugNonUFS) { AddStagingFile(NonUFSStagingFilesDebug, FileToCopy, Dest); } FilesAdded++; } } if (FilesAdded == 0 && !bAllowNone && !bIsCombiningMultiplePlatforms) { throw new AutomationException(ExitCode.Error_StageMissingFile, "No files found to deploy for {0} with wildcard {1} and exclusions {2}", InPath, Wildcard, ExcludeWildcard); } }
public int ArchiveFiles(string InPath, string Wildcard = "*", bool bRecursive = true, string[] ExcludeWildcard = null) { int FilesAdded = 0; if (CommandUtils.DirectoryExists(InPath)) { var All = CommandUtils.FindFiles(Wildcard, bRecursive, InPath); var Exclude = new HashSet <string>(); if (ExcludeWildcard != null) { foreach (var Excl in ExcludeWildcard) { var Remove = CommandUtils.FindFiles(Excl, bRecursive, InPath); foreach (var File in Remove) { Exclude.Add(CommandUtils.CombinePaths(File)); } } } foreach (var AllFile in All) { var FileToCopy = CommandUtils.CombinePaths(AllFile); if (Exclude.Contains(FileToCopy)) { continue; } bool OtherPlatform = false; foreach (UnrealTargetPlatform Plat in Enum.GetValues(typeof(UnrealTargetPlatform))) { if (Plat != StageTargetPlatform.PlatformType && Plat != UnrealTargetPlatform.Unknown && FileToCopy.IndexOf(CommandUtils.CombinePaths("/" + Plat.ToString() + "/"), 0, StringComparison.InvariantCultureIgnoreCase) >= 0) { OtherPlatform = true; break; } } if (OtherPlatform) { continue; } string Dest; if (!FileToCopy.StartsWith(InPath)) { throw new AutomationException("Can't archive {0}; it was supposed to start with {1}", FileToCopy, InPath); } Dest = FileToCopy.Substring(InPath.Length); if (Dest.StartsWith("/") || Dest.StartsWith("\\")) { Dest = Dest.Substring(1); } ArchivedFiles.Add(FileToCopy, Dest); FilesAdded++; } } return(FilesAdded); }
public DeploymentContext( string RawProjectPathOrName, string InLocalRoot, string BaseStageDirectory, string BaseArchiveDirectory, string CookFlavor, Platform InSourcePlatform, Platform InTargetPlatform, List <UnrealTargetConfiguration> InTargetConfigurations, List <String> InStageExecutables, bool InServer, bool InCooked, bool InStageCrashReporter, bool InStage, bool InCookOnTheFly, bool InArchive, bool InProgram, bool bHasDedicatedServerAndClient ) { bStageCrashReporter = InStageCrashReporter; RawProjectPath = RawProjectPathOrName; DedicatedServer = InServer; LocalRoot = CommandUtils.CombinePaths(InLocalRoot); CookSourcePlatform = InSourcePlatform; StageTargetPlatform = InTargetPlatform; StageTargetConfigurations = new List <UnrealTargetConfiguration>(InTargetConfigurations); StageExecutables = InStageExecutables; IsCodeBasedProject = ProjectUtils.IsCodeBasedUProjectFile(RawProjectPath); ShortProjectName = ProjectUtils.GetShortProjectName(RawProjectPath); Stage = InStage; Archive = InArchive; if (CookSourcePlatform != null && InCooked) { CookPlatform = CookSourcePlatform.GetCookPlatform(DedicatedServer, bHasDedicatedServerAndClient, CookFlavor); } else if (CookSourcePlatform != null && InProgram) { CookPlatform = CookSourcePlatform.GetCookPlatform(false, false, ""); } else { CookPlatform = ""; } if (StageTargetPlatform != null && InCooked) { FinalCookPlatform = StageTargetPlatform.GetCookPlatform(DedicatedServer, bHasDedicatedServerAndClient, CookFlavor); } else if (StageTargetPlatform != null && InProgram) { FinalCookPlatform = StageTargetPlatform.GetCookPlatform(false, false, ""); } else { FinalCookPlatform = ""; } PlatformDir = StageTargetPlatform.PlatformType.ToString(); StageDirectory = CommandUtils.CombinePaths(BaseStageDirectory, FinalCookPlatform); ArchiveDirectory = CommandUtils.CombinePaths(BaseArchiveDirectory, FinalCookPlatform); if (!CommandUtils.FileExists(RawProjectPath)) { throw new AutomationException("Can't find uproject file {0}.", RawProjectPathOrName); } ProjectRoot = CommandUtils.CombinePaths(CommandUtils.GetDirectoryName(Path.GetFullPath(RawProjectPath))); if (!CommandUtils.DirectoryExists(ProjectRoot)) { throw new AutomationException("Project Directory {0} doesn't exist.", ProjectRoot); } RelativeProjectRootForStage = ShortProjectName; ProjectArgForCommandLines = CommandUtils.MakePathSafeToUseWithCommandLine(RawProjectPath); CookSourceRuntimeRootDir = RuntimeRootDir = LocalRoot; RuntimeProjectRootDir = ProjectRoot; RelativeProjectRootForUnrealPak = CommandUtils.CombinePaths(RelativeProjectRootForStage).Replace("\\", "/"); if (RelativeProjectRootForUnrealPak.StartsWith("/")) { RelativeProjectRootForUnrealPak = RelativeProjectRootForUnrealPak.Substring(1); RelativeProjectRootForStage = RelativeProjectRootForStage.Substring(1); } SourceRelativeProjectRoot = RelativeProjectRootForStage; // for foreign projects this doesn't make much sense, but it turns into a noop on staging files if (ProjectRoot.StartsWith(LocalRoot, StringComparison.InvariantCultureIgnoreCase)) { SourceRelativeProjectRoot = ProjectRoot.Substring(LocalRoot.Length); } if (SourceRelativeProjectRoot.StartsWith("/") || SourceRelativeProjectRoot.StartsWith("\\")) { SourceRelativeProjectRoot = SourceRelativeProjectRoot.Substring(1); } if (Stage) { CommandUtils.CreateDirectory(StageDirectory); StageProjectRoot = CommandUtils.CombinePaths(StageDirectory, RelativeProjectRootForStage); RuntimeRootDir = StageDirectory; CookSourceRuntimeRootDir = CommandUtils.CombinePaths(BaseStageDirectory, CookPlatform); RuntimeProjectRootDir = StageProjectRoot; ProjectArgForCommandLines = CommandUtils.MakePathSafeToUseWithCommandLine(UProjectCommandLineArgInternalRoot + RelativeProjectRootForStage + "/" + ShortProjectName + ".uproject"); } if (Archive) { CommandUtils.CreateDirectory(ArchiveDirectory); } ProjectArgForCommandLines = ProjectArgForCommandLines.Replace("\\", "/"); }
public override void ExecuteBuild() { // Get the plugin filename string PluginFileName = ParseParamValue("Plugin"); if (PluginFileName == null) { throw new AutomationException("Plugin file name was not specified via the -plugin argument"); } // Read the plugin PluginDescriptor Plugin = PluginDescriptor.FromFile(PluginFileName); // Clean the intermediate build directory string IntermediateBuildDirectory = Path.Combine(Path.GetDirectoryName(PluginFileName), "Intermediate", "Build"); if (CommandUtils.DirectoryExists(IntermediateBuildDirectory)) { CommandUtils.DeleteDirectory(IntermediateBuildDirectory); } // Get any additional arguments from the commandline string AdditionalArgs = ""; if (ParseParam("Rocket")) { AdditionalArgs += " -Rocket"; } // Build the host platforms List <string> ReceiptFileNames = new List <string>(); UE4Build.BuildAgenda Agenda = new UE4Build.BuildAgenda(); UnrealTargetPlatform HostPlatform = BuildHostPlatform.Current.Platform; if (!ParseParam("NoHostPlatform")) { AddPluginToAgenda(Agenda, PluginFileName, Plugin, "UE4Editor", TargetRules.TargetType.Editor, HostPlatform, UnrealTargetConfiguration.Development, ReceiptFileNames, AdditionalArgs); } // Add the game targets List <UnrealTargetPlatform> TargetPlatforms = Rocket.RocketBuild.GetTargetPlatforms(this, HostPlatform); foreach (UnrealTargetPlatform TargetPlatform in TargetPlatforms) { if (Rocket.RocketBuild.IsCodeTargetPlatform(HostPlatform, TargetPlatform)) { AddPluginToAgenda(Agenda, PluginFileName, Plugin, "UE4Game", TargetRules.TargetType.Game, TargetPlatform, UnrealTargetConfiguration.Development, ReceiptFileNames, AdditionalArgs); AddPluginToAgenda(Agenda, PluginFileName, Plugin, "UE4Game", TargetRules.TargetType.Game, TargetPlatform, UnrealTargetConfiguration.Shipping, ReceiptFileNames, AdditionalArgs); } } // Build it UE4Build Build = new UE4Build(this); Build.Build(Agenda, InDeleteBuildProducts: true, InUpdateVersionFiles: false); // Package the plugin to the output folder string PackageDirectory = ParseParamValue("Package"); if (PackageDirectory != null) { List <BuildProduct> BuildProducts = GetBuildProductsFromReceipts(ReceiptFileNames); PackagePlugin(PluginFileName, BuildProducts, PackageDirectory); } }
public int ArchiveFiles(string InPath, string Wildcard = "*", bool bRecursive = true, string[] ExcludeWildcard = null) { int FilesAdded = 0; if (CommandUtils.DirectoryExists(InPath)) { var All = CommandUtils.FindFiles(Wildcard, bRecursive, InPath); var Exclude = new HashSet <string>(); if (ExcludeWildcard != null) { foreach (var Excl in ExcludeWildcard) { var Remove = CommandUtils.FindFiles(Excl, bRecursive, InPath); foreach (var File in Remove) { Exclude.Add(CommandUtils.CombinePaths(File)); } } } foreach (var AllFile in All) { var FileToCopy = CommandUtils.CombinePaths(AllFile); if (Exclude.Contains(FileToCopy)) { continue; } if (!bIsCombiningMultiplePlatforms) { bool OtherPlatform = false; foreach (UnrealTargetPlatform Plat in Enum.GetValues(typeof(UnrealTargetPlatform))) { if (Plat != StageTargetPlatform.PlatformType && Plat != UnrealTargetPlatform.Unknown) { var Search = FileToCopy; if (Search.StartsWith(LocalRoot, StringComparison.InvariantCultureIgnoreCase)) { if (LocalRoot.EndsWith("\\") || LocalRoot.EndsWith("/")) { Search = Search.Substring(LocalRoot.Length - 1); } else { Search = Search.Substring(LocalRoot.Length); } } if (Search.StartsWith(ProjectRoot, StringComparison.InvariantCultureIgnoreCase)) { if (ProjectRoot.EndsWith("\\") || ProjectRoot.EndsWith("/")) { Search = Search.Substring(ProjectRoot.Length - 1); } else { Search = Search.Substring(ProjectRoot.Length); } } if (Search.IndexOf(CommandUtils.CombinePaths("/" + Plat.ToString() + "/"), 0, StringComparison.InvariantCultureIgnoreCase) >= 0) { OtherPlatform = true; break; } } } if (OtherPlatform) { continue; } } string Dest; if (!FileToCopy.StartsWith(InPath)) { throw new AutomationException("Can't archive {0}; it was supposed to start with {1}", FileToCopy, InPath); } Dest = FileToCopy.Substring(InPath.Length); if (Dest.StartsWith("/") || Dest.StartsWith("\\")) { Dest = Dest.Substring(1); } if (ArchivedFiles.ContainsKey(FileToCopy)) { if (ArchivedFiles[FileToCopy] != Dest) { throw new AutomationException("Can't archive {0}: it was already in the files to archive with a different destination '{1}'", FileToCopy, Dest); } } else { ArchivedFiles.Add(FileToCopy, Dest); } FilesAdded++; } } return(FilesAdded); }
public override void ExecuteBuild() { // Get the plugin filename string PluginParam = ParseParamValue("Plugin"); if (PluginParam == null) { throw new AutomationException("Plugin file name was not specified via the -plugin argument"); } // Read the plugin FileReference PluginFile = new FileReference(PluginParam); DirectoryReference PluginDirectory = PluginFile.Directory; PluginDescriptor Plugin = PluginDescriptor.FromFile(PluginFile); // Clean the intermediate build directory DirectoryReference IntermediateBuildDirectory = DirectoryReference.Combine(PluginDirectory, "Intermediate", "Build"); if (CommandUtils.DirectoryExists(IntermediateBuildDirectory.FullName)) { CommandUtils.DeleteDirectory(IntermediateBuildDirectory.FullName); } // Create a host project for the plugin. For script generator plugins, we need to have UHT be able to load it - and that can only happen if it's enabled in a project. DirectoryReference HostProjectDirectory = DirectoryReference.Combine(new DirectoryReference(CommandUtils.CmdEnv.LocalRoot), "HostProject"); if (CommandUtils.DirectoryExists(HostProjectDirectory.FullName)) { CommandUtils.DeleteDirectory(HostProjectDirectory.FullName); } DirectoryReference HostProjectPluginDirectory = DirectoryReference.Combine(HostProjectDirectory, "Plugins", PluginFile.GetFileNameWithoutExtension()); string[] CopyPluginFiles = Directory.EnumerateFiles(PluginDirectory.FullName, "*", SearchOption.AllDirectories).ToArray(); foreach (string CopyPluginFile in CopyPluginFiles) { CommandUtils.CopyFile(CopyPluginFile, CommandUtils.MakeRerootedFilePath(CopyPluginFile, PluginDirectory.FullName, HostProjectPluginDirectory.FullName)); } FileReference HostProjectPluginFile = FileReference.Combine(HostProjectPluginDirectory, PluginFile.GetFileName()); FileReference HostProjectFile = FileReference.Combine(HostProjectDirectory, "HostProject.uproject"); File.WriteAllText(HostProjectFile.FullName, "{ \"FileVersion\": 3, \"Plugins\": [ { \"Name\": \"" + PluginFile.GetFileNameWithoutExtension() + "\", \"Enabled\": true } ] }"); // Get any additional arguments from the commandline string AdditionalArgs = ""; // Build the host platforms List <string> ReceiptFileNames = new List <string>(); UnrealTargetPlatform HostPlatform = BuildHostPlatform.Current.Platform; if (!ParseParam("NoHostPlatform")) { if (Plugin.bCanBeUsedWithUnrealHeaderTool) { BuildPluginWithUBT(PluginFile, Plugin, null, "UnrealHeaderTool", TargetRules.TargetType.Program, HostPlatform, UnrealTargetConfiguration.Development, ReceiptFileNames, String.Format("{0} -plugin {1}", AdditionalArgs, CommandUtils.MakePathSafeToUseWithCommandLine(HostProjectPluginFile.FullName))); } BuildPluginWithUBT(PluginFile, Plugin, HostProjectFile, "UE4Editor", TargetRules.TargetType.Editor, HostPlatform, UnrealTargetConfiguration.Development, ReceiptFileNames, AdditionalArgs); } // Add the game targets List <UnrealTargetPlatform> TargetPlatforms = Rocket.RocketBuild.GetTargetPlatforms(this, HostPlatform); foreach (UnrealTargetPlatform TargetPlatform in TargetPlatforms) { if (Rocket.RocketBuild.IsCodeTargetPlatform(HostPlatform, TargetPlatform)) { BuildPluginWithUBT(PluginFile, Plugin, HostProjectFile, "UE4Game", TargetRules.TargetType.Game, TargetPlatform, UnrealTargetConfiguration.Development, ReceiptFileNames, AdditionalArgs); BuildPluginWithUBT(PluginFile, Plugin, HostProjectFile, "UE4Game", TargetRules.TargetType.Game, TargetPlatform, UnrealTargetConfiguration.Shipping, ReceiptFileNames, AdditionalArgs); } } // Package the plugin to the output folder string PackageDirectory = ParseParamValue("Package"); if (PackageDirectory != null) { List <BuildProduct> BuildProducts = GetBuildProductsFromReceipts(UnrealBuildTool.UnrealBuildTool.EngineDirectory, HostProjectDirectory, ReceiptFileNames); PackagePlugin(HostProjectPluginFile, BuildProducts, PackageDirectory); } }