// Copyright Epic Games, Inc. All Rights Reserved. using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Runtime.Versioning; using System.Xml.Linq; using EpicGames.Core; using Microsoft.Extensions.Logging; namespace UnrealBuildTool { /// /// Public Linux functions exposed to UAT /// public static class WindowsExports { /// /// Tries to get the directory for an installed Visual Studio version /// /// The compiler version /// True if successful public static IEnumerable? TryGetVSInstallDirs(WindowsCompiler Compiler) { return WindowsPlatform.TryGetVSInstallDirs(Compiler, Log.Logger); } /// /// Gets the path to MSBuild.exe /// /// Path to MSBuild.exe [SupportedOSPlatform("windows")] public static string GetMSBuildToolPath() { return MicrosoftPlatformSDK.GetMsBuildToolPath(Log.Logger).FullName; } /// /// Returns the architecture name of the current architecture. /// /// The architecture enum /// String with the name public static string GetArchitectureName(UnrealArch arch) { return WindowsPlatform.GetArchitectureName(arch); } /// /// Tries to get the directory for an installed Windows SDK /// /// Receives the desired version on success /// Version of SDK /// Path to SDK root folder /// String with the name [SupportedOSPlatform("windows")] public static bool TryGetWindowsSdkDir(string DesiredVersion, [NotNullWhen(true)] out Version? OutSdkVersion, [NotNullWhen(true)] out DirectoryReference? OutSdkDir) { VersionNumber? vn; if (WindowsPlatform.TryGetWindowsSdkDir(DesiredVersion, Log.Logger, out vn, out OutSdkDir)) { OutSdkVersion = new Version(vn.ToString()); return true; } OutSdkVersion = new Version(); return false; } /// /// Gets a list of Windows Sdk installation directories, ordered by preference /// /// String with the name [SupportedOSPlatform("windows")] public static List> GetWindowsSdkDirs() { List> WindowsSdkDirs = new List>(); // Add the default directory first VersionNumber? Version; DirectoryReference? DefaultWindowsSdkDir; if (WindowsPlatform.TryGetWindowsSdkDir(null, Log.Logger, out Version, out DefaultWindowsSdkDir)) { WindowsSdkDirs.Add(new KeyValuePair(Version.ToString(), DefaultWindowsSdkDir)); } // Add all the other directories sorted in reverse order IReadOnlyDictionary WindowsSdkDirPairs = MicrosoftPlatformSDK.FindWindowsSdkDirs(Log.Logger); foreach (KeyValuePair Pair in WindowsSdkDirPairs.OrderByDescending(x => x.Key)) { if (!WindowsSdkDirs.Any(x => x.Value == Pair.Value)) { WindowsSdkDirs.Add(new KeyValuePair(Pair.Key.ToString(), Pair.Value)); } } return WindowsSdkDirs; } /// /// Enumerates all the Windows 10 SDK root directories /// /// Receives all the Windows 10 sdk root directories /// Logger for output [SupportedOSPlatform("windows")] public static void EnumerateSdkRootDirs(List RootDirs, ILogger Logger) { MicrosoftPlatformSDK.EnumerateSdkRootDirs(RootDirs, Logger); } /// /// Determines the directory containing the MSVC toolchain /// /// Major version of the compiler to use /// The minimum compiler version to use /// Architecture that is required /// Logger for output /// Receives the chosen toolchain version /// Receives the directory containing the toolchain /// Receives the optional directory containing redistributable components /// True if the toolchain directory was found correctly [SupportedOSPlatform("windows")] public static bool TryGetToolChainDir(WindowsCompiler Compiler, string? CompilerVersion, UnrealArch Architecture, ILogger Logger, [NotNullWhen(true)] out VersionNumber? OutToolChainVersion, [NotNullWhen(true)] out DirectoryReference? OutToolChainDir, out DirectoryReference? OutRedistDir) { OutToolChainVersion = null; OutToolChainDir = null; OutRedistDir = null; return MicrosoftPlatformSDK.TryGetToolChainDir(Compiler, CompilerVersion, Architecture, Logger, out OutToolChainVersion, out OutToolChainDir, out OutRedistDir); } } }