Files
UnrealEngineUWP/Engine/Source/Programs/UnrealBuildTool/System/SourceFileSearch.cs
joe kirchoff 56c81f683c UnrealBuildTool: Slightly optimize generated visual studio project to reduce memory usage
* Filter out numerous source files that match */Source/ThirdParty/* that should have already been filtered, this does not include Module.Build.cs or .tps files, or if bGatherThirdPartySource is enabled
* Filter out source files that match */third_party/* by default
* Add option bIncludeDotNetPrograms to remove all ..NET projects, doing so saved me around 400MB. Note if you disable the .NET projects UnrealBuildTool won't build before compiling (but GenerateProjectFiles.bat will still build it)

Attempted changes that did not reduce memory usage by a significant amount:
* Filtering out project configurations
* Filtering out Engine/Shaders or Engine/Content/Editor/Templates
* Increasing the shared include size, even making it large enough to contain every include path didn't really make a difference. Also it can't really be increased anyway because that entire property is added to the process environment when starting a build and there's a max environment size of around 32k

Other Fixes:
* Fix vs2019 ToolVersionString 15.0 -> 16.0
* Add VCProjectVersion to Project globals
* Update UniqueIdentifier GUIDs in projects to be stable by hashing the directory path and using that hash as the GUID
* Don't write ProjectConfiguration if filtered out (Didn't affect memory usage)
* Add optional configuration filter for Debug, DebugGame, & Development

#jira UE-111822
#rb none

#ROBOMERGE-SOURCE: CL 16319735 in //UE5/Main/...
#ROBOMERGE-BOT: STARSHIP (Main -> Release-Engine-Test) (v804-16311228)

[CL 16319758 by joe kirchoff in ue5-release-engine-test branch]
2021-05-13 17:39:22 -04:00

131 lines
5.2 KiB
C#

// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.Linq;
using EpicGames.Core;
namespace UnrealBuildTool
{
static class SourceFileSearch
{
// Certain file types should never be added to project files. These extensions must all be lowercase.
static readonly string[] DefaultExcludedFileSuffixes = new string[]
{
".vcxproj", // Visual Studio project files
".vcxproj.filters", // Visual Studio filter file
".vcxproj.user", // Visual Studio project user file
".vcxproj.vspscc", // Visual Studio source control state
".sln", // Visual Studio solution file
".sdf", // Visual Studio embedded symbol database file
".suo", // Visual Studio solution option files
".sln.docstates.suo", // Visual Studio temp file
".tmp", // Temp files used by P4 diffing (e.g. t6884t87698.tmp)
".csproj", // Visual Studio C# project files
".userprefs", // MonoDevelop project settings
".ds_store", // Mac Desktop Services Store hidden files
".bin", // Binary files
Path.DirectorySeparatorChar + "do_not_delete.txt", // Perforce placeholder file
};
// Default directory names to exclude. Must be lowercase.
static readonly string[] DefaultExcludedDirectorySuffixes = new string[]
{
Path.DirectorySeparatorChar + "intermediate",
Path.DirectorySeparatorChar + "source" + Path.DirectorySeparatorChar + "thirdparty",
Path.DirectorySeparatorChar + "third_party",
};
/// Finds mouse source files
public static List<FileReference> FindModuleSourceFiles(FileReference ModuleRulesFile, bool SearchSubdirectories = true, HashSet<DirectoryReference>? SearchedDirectories = null)
{
// The module's "base directory" is simply the directory where its xxx.Build.cs file is stored. We'll always
// harvest source files for this module in this base directory directory and all of its sub-directories.
return SourceFileSearch.FindFiles(ModuleRulesFile.Directory, SubdirectoryNamesToExclude: null, SearchSubdirectories: SearchSubdirectories, SearchedDirectories: SearchedDirectories);
}
/// <summary>
/// Fills in a project file with source files discovered in the specified list of paths
/// </summary>
/// <param name="DirectoryToSearch">Directory to search</param>
/// <param name="SubdirectoryNamesToExclude">Directory base names to ignore when searching subdirectories. Can be null.</param>
/// <param name="SearchSubdirectories">True to include subdirectories, otherwise we only search the list of base directories</param>
/// <param name="SearchedDirectories">If non-null, is updated with a list of the directories searched</param>
public static List<FileReference> FindFiles(DirectoryReference DirectoryToSearch, List<string>? SubdirectoryNamesToExclude = null, bool SearchSubdirectories = true, HashSet<DirectoryReference>? SearchedDirectories = null)
{
// Build a list of directory names that we don't want to search under. We always ignore intermediate directories.
string[] ExcludedDirectorySuffixes;
if (SubdirectoryNamesToExclude == null)
{
ExcludedDirectorySuffixes = DefaultExcludedDirectorySuffixes;
}
else
{
ExcludedDirectorySuffixes = SubdirectoryNamesToExclude.Select(x => Path.DirectorySeparatorChar + x.ToLowerInvariant()).Union(DefaultExcludedDirectorySuffixes).ToArray();
}
// Find all the files
List<FileReference> FoundFiles = new List<FileReference>();
if (SearchSubdirectories)
{
FindFilesInternalRecursive(DirectoryToSearch, ExcludedDirectorySuffixes, FoundFiles, SearchedDirectories);
}
else
{
FindFilesInternal(DirectoryToSearch, ExcludedDirectorySuffixes, FoundFiles, SearchedDirectories);
}
return FoundFiles;
}
static void FindFilesInternal(DirectoryReference Directory, string[] ExcludedDirectorySuffixes, List<FileReference> FoundFiles, HashSet<DirectoryReference>? SearchedDirectories)
{
if(SearchedDirectories != null)
{
SearchedDirectories.Add(Directory);
}
foreach (FileReference File in DirectoryReference.EnumerateFiles(Directory))
{
if (ShouldInclude(File, DefaultExcludedFileSuffixes))
{
FoundFiles.Add(File);
}
}
}
static void FindFilesInternalRecursive(DirectoryReference Directory, string[] ExcludedDirectorySuffixes, List<FileReference> FoundFiles, HashSet<DirectoryReference>? SearchedDirectories)
{
FindFilesInternal(Directory, ExcludedDirectorySuffixes, FoundFiles, SearchedDirectories);
foreach (DirectoryReference SubDirectory in DirectoryReference.EnumerateDirectories(Directory))
{
if (ShouldInclude(SubDirectory, ExcludedDirectorySuffixes))
{
FindFilesInternalRecursive(SubDirectory, ExcludedDirectorySuffixes, FoundFiles, SearchedDirectories);
}
}
}
static bool ShouldInclude(FileSystemReference Reference, string[] ExcludedSuffixes)
{
// Ignore Mac resource fork files on non-HFS partitions
if (Path.GetFileName(Reference.FullName).StartsWith("._"))
{
return false;
}
foreach (string ExcludedSuffix in ExcludedSuffixes)
{
if (Reference.FullName.EndsWith(ExcludedSuffix, FileSystemReference.Comparison))
{
return false;
}
}
return true;
}
}
}