Files
UnrealEngineUWP/Engine/Source/Programs/DotNETCommon/BuildUtilities/UnrealBuild.cs
jonathan adamczewski d58996b916 UnrealBuildTool: move some path constants into BuildUtilities
RootDirectory, EngineDirectory, UnrealBuildToolPath are now found in BuildUtilities' UnrealBuild namesapce.

The way these are computed has changed. Previously, it was assumed that the application is UnrealBuildTool, and paths were constructed relative to that assembly.

Now, the assumption is that the process is located under a "Engine/Build/DotNET" sub-path and paths are constructed relative to that.

#jira none

#ROBOMERGE-SOURCE: CL 16607440 in //UE5/Main/...
#ROBOMERGE-BOT: STARSHIP (Main -> Release-Engine-Test) (v828-16531559)

[CL 16607455 by jonathan adamczewski in ue5-release-engine-test branch]
2021-06-09 12:55:13 -04:00

94 lines
3.7 KiB
C#

// Copyright Epic Games, Inc. All Rights Reserved.
using EpicGames.Core;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
namespace UnrealBuildBase
{
public static class UnrealBuild
{
private static DirectoryReference FindRootDirectory()
{
// This base library may be used - and so be launched - from more than one location (at time of writing, UnrealBuildTool and AutomationTool)
// Programs that use this assembly must be located under "Engine/Binaries/DotNET" and so we look for that sequence of directories in that path of the executing assembly
// Use the EntryAssembly (the application path), rather than the ExecutingAssembly (the library path)
string AssemblyLocation = Assembly.GetEntryAssembly().GetOriginalLocation();
DirectoryReference? FoundRootDirectory = DirectoryReference.FromString(AssemblyLocation);
// Search up through the directory tree for the deepest instance of the sub-path "Engine/Binaries/DotNET"
while(FoundRootDirectory != null)
{
if (String.Equals("DotNET", FoundRootDirectory.GetDirectoryName()))
{
FoundRootDirectory = FoundRootDirectory.ParentDirectory;
if (FoundRootDirectory != null && String.Equals("Binaries", FoundRootDirectory.GetDirectoryName()))
{
FoundRootDirectory = FoundRootDirectory.ParentDirectory;
if (FoundRootDirectory != null && String.Equals("Engine", FoundRootDirectory.GetDirectoryName()))
{
FoundRootDirectory = FoundRootDirectory.ParentDirectory;
break;
}
continue;
}
continue;
}
FoundRootDirectory = FoundRootDirectory.ParentDirectory;
}
if (FoundRootDirectory == null)
{
throw new Exception($"The BuildUtilities assembly requires that applications are launched from a path containing \"Engine/Binaries/DotNET\". This application was launched from {Path.GetDirectoryName(AssemblyLocation)}");
}
// Confirm that we've found a valid root directory, by testing for the existence of a well-known file
FileReference ExpectedExistingFile = FileReference.Combine(FoundRootDirectory, "Engine", "Build", "Build.version");
if (!FileReference.Exists(ExpectedExistingFile))
{
throw new Exception($"Expected file \"Engine/Build/Build.version\" was not found at {ExpectedExistingFile.FullName}");
}
return FoundRootDirectory;
}
private static FileReference FindUnrealBuildTool()
{
// todo: use UnrealBuildTool.dll (same on all platforms). Will require changes wherever UnrealBuildTool is invoked.
string UBTName = RuntimePlatform.IsWindows ? "UnrealBuildTool.exe" : "UnrealBuildTool";
// the UnrealBuildTool executable is assumed to be located under {RootDirectory}/Engine/Binaries/DotNET/UnrealBuildTool/
FileReference UnrealBuildToolPath = FileReference.Combine(EngineDirectory, "Binaries", "DotNET", "UnrealBuildTool", UBTName);
FileReference UnrealBuildToolPathCorrected = FileReference.FindCorrectCase(UnrealBuildToolPath);
if (!FileReference.Exists(UnrealBuildToolPathCorrected))
{
throw new Exception($"Unable to find {UBTName} in the expected location at {UnrealBuildToolPathCorrected.FullName}");
}
return UnrealBuildToolPathCorrected;
}
/// <summary>
/// The full name of the root UE directory
/// </summary>
public static readonly DirectoryReference RootDirectory = FindRootDirectory();
/// <summary>
/// The full name of the Engine directory
/// </summary>
public static readonly DirectoryReference EngineDirectory = DirectoryReference.Combine(RootDirectory, "Engine");
/// <summary>
/// The path to UBT
/// </summary>
public static readonly FileReference UnrealBuildToolPath = FindUnrealBuildTool();
}
}