/// <summary>
        /// Resolve a list of files, tag names or file specifications as above, but preserves any directory references for further processing.
        /// </summary>
        /// <param name="DefaultDirectory">The default directory to resolve relative paths to</param>
        /// <param name="FilePatterns">List of files, tag names, or file specifications to include separated by semicolons.</param>
        /// <param name="ExcludePatterns">Set of patterns to apply to directory searches. This can greatly speed up enumeration by earlying out of recursive directory searches if large directories are excluded (eg. .../Intermediate/...).</param>
        /// <param name="TagNameToFileSet">Mapping of tag name to fileset, as passed to the Execute() method</param>
        /// <returns>Set of matching files.</returns>
        public static HashSet <FileReference> ResolveFilespecWithExcludePatterns(DirectoryReference DefaultDirectory, List <string> FilePatterns, List <string> ExcludePatterns, Dictionary <string, HashSet <FileReference> > TagNameToFileSet)
        {
            // Parse each of the patterns, and add the results into the given sets
            HashSet <FileReference> Files = new HashSet <FileReference>();

            foreach (string Pattern in FilePatterns)
            {
                // Check if it's a tag name
                if (Pattern.StartsWith("#"))
                {
                    Files.UnionWith(FindOrAddTagSet(TagNameToFileSet, Pattern));
                    continue;
                }

                // If it doesn't contain any wildcards, just add the pattern directly
                int WildcardIdx = FileFilter.FindWildcardIndex(Pattern);
                if (WildcardIdx == -1)
                {
                    Files.Add(FileReference.Combine(DefaultDirectory, Pattern));
                    continue;
                }

                // Find the base directory for the search. We construct this in a very deliberate way including the directory separator itself, so matches
                // against the OS root directory will resolve correctly both on Mac (where / is the filesystem root) and Windows (where / refers to the current drive).
                int LastDirectoryIdx       = Pattern.LastIndexOfAny(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }, WildcardIdx);
                DirectoryReference BaseDir = DirectoryReference.Combine(DefaultDirectory, Pattern.Substring(0, LastDirectoryIdx + 1));

                // Construct the absolute include pattern to match against, re-inserting the resolved base directory to construct a canonical path.
                string IncludePattern = BaseDir.FullName.TrimEnd(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }) + "/" + Pattern.Substring(LastDirectoryIdx + 1);

                // Construct a filter and apply it to the directory
                if (DirectoryReference.Exists(BaseDir))
                {
                    FileFilter Filter = new FileFilter();
                    Filter.AddRule(IncludePattern, FileFilterType.Include);
                    if (ExcludePatterns != null && ExcludePatterns.Count > 0)
                    {
                        Filter.AddRules(ExcludePatterns, FileFilterType.Exclude);
                    }
                    Files.UnionWith(Filter.ApplyToDirectory(BaseDir, BaseDir.FullName, true));
                }
            }

            // If we have exclude rules, create and run a filter against all the output files to catch things that weren't added from an include
            if (ExcludePatterns != null && ExcludePatterns.Count > 0)
            {
                FileFilter Filter = new FileFilter(FileFilterType.Include);
                Filter.AddRules(ExcludePatterns, FileFilterType.Exclude);
                Files.RemoveWhere(x => !Filter.Matches(x.FullName));
            }
            return(Files);
        }
Пример #2
0
        public override void DoBuild(GUBP bp)
        {
            BuildProducts = new List<string>();
            FileFilter Filter = new FileFilter();

            // Include all the editor products
            AddRuleForBuildProducts(Filter, bp, GUBP.ToolsForCompileNode.StaticGetFullName(HostPlatform), FileFilterType.Include);
            AddRuleForBuildProducts(Filter, bp, GUBP.RootEditorNode.StaticGetFullName(HostPlatform), FileFilterType.Include);
            AddRuleForBuildProducts(Filter, bp, GUBP.ToolsNode.StaticGetFullName(HostPlatform), FileFilterType.Include);

            // Include win64 tools on Mac, to get the win64 build of UBT, UAT and IPP
            if (HostPlatform == UnrealTargetPlatform.Mac && bp.HostPlatforms.Contains(UnrealTargetPlatform.Win64))
            {
                AddRuleForBuildProducts(Filter, bp, GUBP.ToolsNode.StaticGetFullName(UnrealTargetPlatform.Win64), FileFilterType.Include);
                AddRuleForBuildProducts(Filter, bp, GUBP.ToolsForCompileNode.StaticGetFullName(UnrealTargetPlatform.Win64), FileFilterType.Include);
            }

            // Include the editor headers
            UnzipAndAddRuleForHeaders(GUBP.RootEditorNode.StaticGetArchivedHeadersPath(HostPlatform), Filter, FileFilterType.Include);

            // Include the build dependencies for every code platform
            foreach(UnrealTargetPlatform TargetPlatform in TargetPlatforms)
            {
                if(RocketBuild.IsCodeTargetPlatform(HostPlatform, TargetPlatform))
                {
                    UnrealTargetPlatform SourceHostPlatform = RocketBuild.GetSourceHostPlatform(bp, HostPlatform, TargetPlatform);
                    string FileListPath = GUBP.GamePlatformMonolithicsNode.StaticGetBuildDependenciesPath(SourceHostPlatform, bp.Branch.BaseEngineProject, TargetPlatform);
                    Filter.AddRuleForFiles(UnrealBuildTool.Utils.ReadClass<UnrealBuildTool.ExternalFileList>(FileListPath).FileNames, CommandUtils.CmdEnv.LocalRoot, FileFilterType.Include);
                    UnzipAndAddRuleForHeaders(GUBP.GamePlatformMonolithicsNode.StaticGetArchivedHeadersPath(SourceHostPlatform, bp.Branch.BaseEngineProject, TargetPlatform), Filter, FileFilterType.Include);
                }
            }

            // Add the monolithic binaries
            foreach(UnrealTargetPlatform TargetPlatform in TargetPlatforms)
            {
                UnrealTargetPlatform SourceHostPlatform = RocketBuild.GetSourceHostPlatform(bp, HostPlatform, TargetPlatform);
                bool bIsCodeTargetPlatform = RocketBuild.IsCodeTargetPlatform(SourceHostPlatform, TargetPlatform);
                AddRuleForBuildProducts(Filter, bp, GUBP.GamePlatformMonolithicsNode.StaticGetFullName(SourceHostPlatform, bp.Branch.BaseEngineProject, TargetPlatform, Precompiled: bIsCodeTargetPlatform), FileFilterType.Include);
            }

            // Include the feature packs
            foreach(string CurrentFeaturePack in CurrentFeaturePacks)
            {
                BranchInfo.BranchUProject Project = bp.Branch.FindGameChecked(CurrentFeaturePack);
                Filter.AddRuleForFile(GUBP.MakeFeaturePacksNode.GetOutputFile(Project), CommandUtils.CmdEnv.LocalRoot, FileFilterType.Include);
            }

            // Include all the templates
            foreach (string Template in CurrentTemplates)
            {
                BranchInfo.BranchUProject Project = bp.Branch.FindGameChecked(Template);
                Filter.Include("/" + Utils.StripBaseDirectory(Path.GetDirectoryName(Project.FilePath), CommandUtils.CmdEnv.LocalRoot).Replace('\\', '/') + "/...");
            }

            // Include all the standard rules
            string RulesFileName = CommandUtils.CombinePaths(CommandUtils.CmdEnv.LocalRoot, "Engine", "Build", "InstalledEngineFilters.ini");
            Filter.ReadRulesFromFile(RulesFileName, "CopyEditor", HostPlatform.ToString());
            Filter.ReadRulesFromFile(RulesFileName, "CopyTargetPlatforms", HostPlatform.ToString());

            // Custom rules for each target platform
            foreach(UnrealTargetPlatform TargetPlaform in TargetPlatforms)
            {
                string SectionName = String.Format("CopyTargetPlatform.{0}", TargetPlaform.ToString());
                Filter.ReadRulesFromFile(RulesFileName, SectionName, HostPlatform.ToString());
            }

            // Add the final exclusions for legal reasons.
            Filter.ExcludeConfidentialPlatforms();
            Filter.ExcludeConfidentialFolders();

            // Run the filter on the stripped symbols, and remove those files from the copy filter
            List<string> AllStrippedFiles = new List<string>();
            foreach(KeyValuePair<string, string> StrippedNodeManifestPath in StrippedNodeManifestPaths)
            {
                List<string> StrippedFiles = new List<string>();

                StripRocketNode StripNode = (StripRocketNode)bp.FindNode(StrippedNodeManifestPath.Key);
                foreach(string BuildProduct in StripNode.BuildProducts)
                {
                    if(Utils.IsFileUnderDirectory(BuildProduct, StripNode.StrippedDir))
                    {
                        string RelativePath = CommandUtils.StripBaseDirectory(Path.GetFullPath(BuildProduct), StripNode.StrippedDir);
                        if(Filter.Matches(RelativePath))
                        {
                            StrippedFiles.Add(RelativePath);
                            AllStrippedFiles.Add(RelativePath);
                            Filter.Exclude("/" + RelativePath);
                        }
                    }
                }

                WriteManifest(StrippedNodeManifestPath.Value, StrippedFiles);
                BuildProducts.Add(StrippedNodeManifestPath.Value);
            }

            // Write the filtered list of depot files to disk, removing any symlinks
            List<string> DepotFiles = Filter.ApplyToDirectory(CommandUtils.CmdEnv.LocalRoot, true).ToList();
            WriteManifest(DepotManifestPath, DepotFiles);
            BuildProducts.Add(DepotManifestPath);

            // Sort the list of output files
            SortedDictionary<string, bool> SortedFiles = new SortedDictionary<string,bool>(StringComparer.InvariantCultureIgnoreCase);
            foreach(string DepotFile in DepotFiles)
            {
                SortedFiles.Add(DepotFile, false);
            }
            foreach(string StrippedFile in AllStrippedFiles)
            {
                SortedFiles.Add(StrippedFile, true);
            }

            // Write the list to the log
            CommandUtils.Log("Files to be included in Rocket build:");
            foreach(KeyValuePair<string, bool> SortedFile in SortedFiles)
            {
                CommandUtils.Log("  {0}{1}", SortedFile.Key, SortedFile.Value? " (stripped)" : "");
            }
        }
Пример #3
0
        public override void DoBuild(GUBP bp)
        {
            BuildProducts = new List<string>();

            string InputDir = Path.GetFullPath(CommandUtils.CmdEnv.LocalRoot);
            string RulesFileName = CommandUtils.CombinePaths(CommandUtils.CmdEnv.LocalRoot, "Engine", "Build", "InstalledEngineFilters.ini");

            // Read the filter for files on this platform
            FileFilter StripFilter = new FileFilter();
            StripFilter.ReadRulesFromFile(RulesFileName, "StripSymbols." + TargetPlatform.ToString(), HostPlatform.ToString());

            // Apply the filter to the build products
            List<string> SourcePaths = new List<string>();
            List<string> TargetPaths = new List<string>();
            foreach(string NodeToStrip in NodesToStrip)
            {
                GUBP.GUBPNode Node = bp.FindNode(NodeToStrip);
                foreach(string DependencyBuildProduct in Node.BuildProducts)
                {
                    string RelativePath = CommandUtils.StripBaseDirectory(Path.GetFullPath(DependencyBuildProduct), InputDir);
                    if(StripFilter.Matches(RelativePath))
                    {
                        SourcePaths.Add(CommandUtils.CombinePaths(InputDir, RelativePath));
                        TargetPaths.Add(CommandUtils.CombinePaths(StrippedDir, RelativePath));
                    }
                }
            }

            // Strip the files and add them to the build products
            StripSymbols(TargetPlatform, SourcePaths.ToArray(), TargetPaths.ToArray());
            BuildProducts.AddRange(TargetPaths);

            SaveRecordOfSuccessAndAddToBuildProducts();
        }
		/// <summary>
		/// Runs the task, filtering the list of build products
		/// </summary>
		/// <param name="BuildProducts"></param>
		/// <returns>True if the task succeeds</returns>
		public override bool Execute(List<string> BuildProducts)
		{
			if(AddFiles != null)
			{
				BuildProducts.AddRange(AddFiles.ApplyToDirectory(BaseDirectory, true).Select(x => CommandUtils.CombinePaths(BaseDirectory, x)));
			}
			if(FilterFiles != null)
			{
				BuildProducts.RemoveAll(x => UnrealBuildTool.Utils.IsFileUnderDirectory(x, BaseDirectory) && !FilterFiles.Matches(UnrealBuildTool.Utils.StripBaseDirectory(x, BaseDirectory)));
			}
			return true;
		}
Пример #5
0
		/// <summary>
		/// Resolve a list of files, tag names or file specifications as above, but preserves any directory references for further processing.
		/// </summary>
		/// <param name="DefaultDirectory">The default directory to resolve relative paths to</param>
		/// <param name="FilePatterns">List of files, tag names, or file specifications to include separated by semicolons.</param>
		/// <param name="ExcludePatterns">Set of patterns to apply to directory searches. This can greatly speed up enumeration by earlying out of recursive directory searches if large directories are excluded (eg. .../Intermediate/...).</param>
		/// <param name="TagNameToFileSet">Mapping of tag name to fileset, as passed to the Execute() method</param>
		/// <returns>Set of matching files.</returns>
		public static HashSet<FileReference> ResolveFilespecWithExcludePatterns(DirectoryReference DefaultDirectory, List<string> FilePatterns, List<string> ExcludePatterns, Dictionary<string, HashSet<FileReference>> TagNameToFileSet)
		{
			// Parse each of the patterns, and add the results into the given sets
			HashSet<FileReference> Files = new HashSet<FileReference>();
			foreach(string Pattern in FilePatterns)
			{
				// Check if it's a tag name
				if(Pattern.StartsWith("#"))
				{
					Files.UnionWith(FindOrAddTagSet(TagNameToFileSet, Pattern));
					continue;
				}

				// If it doesn't contain any wildcards, just add the pattern directly
				int WildcardIdx = FileFilter.FindWildcardIndex(Pattern);
				if(WildcardIdx == -1)
				{
					Files.Add(FileReference.Combine(DefaultDirectory, Pattern));
					continue;
				}

				// Find the base directory for the search. We construct this in a very deliberate way including the directory separator itself, so matches
				// against the OS root directory will resolve correctly both on Mac (where / is the filesystem root) and Windows (where / refers to the current drive).
				int LastDirectoryIdx = Pattern.LastIndexOfAny(new char[]{ Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }, WildcardIdx);
				DirectoryReference BaseDir = DirectoryReference.Combine(DefaultDirectory, Pattern.Substring(0, LastDirectoryIdx + 1));

				// Construct the absolute include pattern to match against, re-inserting the resolved base directory to construct a canonical path.
				string IncludePattern = BaseDir.FullName.TrimEnd(new char[]{ Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }) + "/" + Pattern.Substring(LastDirectoryIdx + 1);

				// Construct a filter and apply it to the directory
				if(BaseDir.Exists())
				{
					FileFilter Filter = new FileFilter();
					Filter.AddRule(IncludePattern, FileFilterType.Include);
					Filter.AddRules(ExcludePatterns, FileFilterType.Exclude);
					Files.UnionWith(Filter.ApplyToDirectory(BaseDir, BaseDir.FullName, true));
				}
			}

			// If we have exclude rules, create and run a filter against all the output files to catch things that weren't added from an include
			if(ExcludePatterns.Count > 0)
			{
				FileFilter Filter = new FileFilter(FileFilterType.Include);
				Filter.AddRules(ExcludePatterns, FileFilterType.Exclude);
				Files.RemoveWhere(x => !Filter.Matches(x.FullName));
			}
			return Files;
		}
		public override void DoBuild(GUBP bp)
		{
			BuildProducts = new List<string>();

			string InputDir = Path.GetFullPath(CommandUtils.CmdEnv.LocalRoot);

			// Read the filter for files on this platform
			FileFilter SignFilter = new FileFilter();
			if (HostPlatform == UnrealTargetPlatform.Mac)
			{
				SignFilter.AddRule("*.dylib");
				SignFilter.AddRule("*.app");
			}
			else
			{
				SignFilter.AddRule("*.exe");
				SignFilter.AddRule("*.dll");
			}

			// Apply the filter to the build products
			List<string> SourcePaths = new List<string>();
			List<string> TargetPaths = new List<string>();
			foreach (string NodeToSign in NodesToSign)
			{
				GUBP.GUBPNode Node = BranchConfig.FindNode(NodeToSign);
				foreach (string DependencyBuildProduct in Node.BuildProducts)
				{
					string RelativePath = CommandUtils.StripBaseDirectory(Path.GetFullPath(DependencyBuildProduct), InputDir);
					if (SignFilter.Matches(RelativePath))
					{
						SourcePaths.Add(CommandUtils.CombinePaths(InputDir, RelativePath));
						TargetPaths.Add(CommandUtils.CombinePaths(SignedDir, RelativePath));
					}
				}
			}

			// Strip the files and add them to the build products
			SignFiles(bp, SourcePaths.ToArray(), TargetPaths.ToArray());
			BuildProducts.AddRange(TargetPaths);

			SaveRecordOfSuccessAndAddToBuildProducts();
		}