#include "llvm/WindowsDriver/MSVCPaths.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/VersionTuple.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/TargetParser/Host.h"
#include "llvm/TargetParser/Triple.h"
#include <optional>
#include <string>
#ifdef _WIN32
#include "llvm/Support/ConvertUTF.h"
#endif
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#define NOGDI
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
#endif
#ifdef _MSC_VER
#define USE_MSVC_SETUP_API
#include <comdef.h>
#include "llvm/Support/COM.h"
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnon-virtual-dtor"
#endif
#include "llvm/WindowsDriver/MSVCSetupApi.h"
#ifdef __clang__
#pragma clang diagnostic pop
#endif
_COM_SMARTPTR_TYPEDEF(ISetupConfiguration, __uuidof(ISetupConfiguration));
_COM_SMARTPTR_TYPEDEF(ISetupConfiguration2, __uuidof(ISetupConfiguration2));
_COM_SMARTPTR_TYPEDEF(ISetupHelper, __uuidof(ISetupHelper));
_COM_SMARTPTR_TYPEDEF(IEnumSetupInstances, __uuidof(IEnumSetupInstances));
_COM_SMARTPTR_TYPEDEF(ISetupInstance, __uuidof(ISetupInstance));
_COM_SMARTPTR_TYPEDEF(ISetupInstance2, __uuidof(ISetupInstance2));
#endif
static std::string
getHighestNumericTupleInDirectory(llvm::vfs::FileSystem &VFS,
llvm::StringRef Directory) { … }
static bool getWindows10SDKVersionFromPath(llvm::vfs::FileSystem &VFS,
const std::string &SDKPath,
std::string &SDKVersion) { … }
static bool getWindowsSDKDirViaCommandLine(
llvm::vfs::FileSystem &VFS, std::optional<llvm::StringRef> WinSdkDir,
std::optional<llvm::StringRef> WinSdkVersion,
std::optional<llvm::StringRef> WinSysRoot, std::string &Path, int &Major,
std::string &Version) { … }
#ifdef _WIN32
static bool readFullStringValue(HKEY hkey, const char *valueName,
std::string &value) {
std::wstring WideValueName;
if (!llvm::ConvertUTF8toWide(valueName, WideValueName))
return false;
DWORD result = 0;
DWORD valueSize = 0;
DWORD type = 0;
result = RegQueryValueExW(hkey, WideValueName.c_str(), NULL, &type, NULL,
&valueSize);
if (result != ERROR_SUCCESS || type != REG_SZ || !valueSize)
return false;
std::vector<BYTE> buffer(valueSize);
result = RegQueryValueExW(hkey, WideValueName.c_str(), NULL, NULL, &buffer[0],
&valueSize);
if (result == ERROR_SUCCESS) {
std::wstring WideValue(reinterpret_cast<const wchar_t *>(buffer.data()),
valueSize / sizeof(wchar_t));
if (valueSize && WideValue.back() == L'\0') {
WideValue.pop_back();
}
value.clear();
return llvm::convertWideToUTF8(WideValue, value);
}
return false;
}
#endif
static bool getSystemRegistryString(const char *keyPath, const char *valueName,
std::string &value, std::string *phValue) { … }
namespace llvm {
const char *archToWindowsSDKArch(Triple::ArchType Arch) { … }
const char *archToLegacyVCArch(Triple::ArchType Arch) { … }
const char *archToDevDivInternalArch(Triple::ArchType Arch) { … }
bool appendArchToWindowsSDKLibPath(int SDKMajor, SmallString<128> LibPath,
Triple::ArchType Arch, std::string &path) { … }
std::string getSubDirectoryPath(SubDirectoryType Type, ToolsetLayout VSLayout,
const std::string &VCToolChainPath,
Triple::ArchType TargetArch,
StringRef SubdirParent) { … }
bool useUniversalCRT(ToolsetLayout VSLayout, const std::string &VCToolChainPath,
Triple::ArchType TargetArch, vfs::FileSystem &VFS) { … }
bool getWindowsSDKDir(vfs::FileSystem &VFS, std::optional<StringRef> WinSdkDir,
std::optional<StringRef> WinSdkVersion,
std::optional<StringRef> WinSysRoot, std::string &Path,
int &Major, std::string &WindowsSDKIncludeVersion,
std::string &WindowsSDKLibVersion) { … }
bool getUniversalCRTSdkDir(vfs::FileSystem &VFS,
std::optional<StringRef> WinSdkDir,
std::optional<StringRef> WinSdkVersion,
std::optional<StringRef> WinSysRoot,
std::string &Path, std::string &UCRTVersion) { … }
bool findVCToolChainViaCommandLine(vfs::FileSystem &VFS,
std::optional<StringRef> VCToolsDir,
std::optional<StringRef> VCToolsVersion,
std::optional<StringRef> WinSysRoot,
std::string &Path, ToolsetLayout &VSLayout) { … }
bool findVCToolChainViaEnvironment(vfs::FileSystem &VFS, std::string &Path,
ToolsetLayout &VSLayout) { … }
bool findVCToolChainViaSetupConfig(vfs::FileSystem &VFS,
std::optional<StringRef> VCToolsVersion,
std::string &Path, ToolsetLayout &VSLayout) { … }
bool findVCToolChainViaRegistry(std::string &Path, ToolsetLayout &VSLayout) { … }
}