Files
UnrealEngineUWP/Engine/Source/Programs/UnrealBuildTool/System/NativeProjects.cs
jonathan adamczewski f270855eef AutomationTool: Compile script modules within the application
Add a layer of caching to avoid running msbuild as much as possible.

#jira UE-109181
#rb ben.marsh

#ROBOMERGE-SOURCE: CL 17102399 in //UE5/Main/...
#ROBOMERGE-BOT: STARSHIP (Main -> Release-Engine-Test) (v853-17066230)

[CL 17102408 by jonathan adamczewski in ue5-release-engine-test branch]
2021-08-09 10:39:35 -04:00

74 lines
2.4 KiB
C#

// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EpicGames.Core;
using UnrealBuildBase;
namespace UnrealBuildTool
{
/// <summary>
/// Utility functions for querying native projects (ie. those found via a .uprojectdirs query)
/// </summary>
public class NativeProjects : NativeProjectsBase
{
/// <summary>
/// Cached map of target names to the project file they belong to
/// </summary>
static Dictionary<string, FileReference>? CachedTargetNameToProjectFile;
/// <summary>
/// Clear our cached properties. Generally only needed if your script has modified local files...
/// </summary>
public static void ClearCache()
{
ClearCacheBase();
CachedTargetNameToProjectFile = null;
}
/// <summary>
/// Get the project folder for the given target name
/// </summary>
/// <param name="InTargetName">Name of the target of interest</param>
/// <param name="OutProjectFileName">The project filename</param>
/// <returns>True if the target was found</returns>
public static bool TryGetProjectForTarget(string InTargetName, [NotNullWhen(true)] out FileReference? OutProjectFileName)
{
if(CachedTargetNameToProjectFile == null)
{
lock(LockObject)
{
if(CachedTargetNameToProjectFile == null)
{
Dictionary<string, FileReference> TargetNameToProjectFile = new Dictionary<string, FileReference>();
foreach(FileReference ProjectFile in EnumerateProjectFiles())
{
foreach (DirectoryReference ExtensionDir in Unreal.GetExtensionDirs(ProjectFile.Directory))
{
DirectoryReference SourceDirectory = DirectoryReference.Combine(ExtensionDir, "Source");
if (DirectoryLookupCache.DirectoryExists(SourceDirectory))
{
FindTargetFiles(SourceDirectory, TargetNameToProjectFile, ProjectFile);
}
DirectoryReference IntermediateSourceDirectory = DirectoryReference.Combine(ExtensionDir, "Intermediate", "Source");
if (DirectoryLookupCache.DirectoryExists(IntermediateSourceDirectory))
{
FindTargetFiles(IntermediateSourceDirectory, TargetNameToProjectFile, ProjectFile);
}
}
}
CachedTargetNameToProjectFile = TargetNameToProjectFile;
}
}
}
return CachedTargetNameToProjectFile.TryGetValue(InTargetName, out OutProjectFileName);
}
}
}