llvm/llvm/lib/WindowsDriver/MSVCPaths.cpp

//===-- MSVCPaths.cpp - MSVC path-parsing helpers -------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#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
// Don't support SetupApi on MinGW.
#define USE_MSVC_SETUP_API

// Make sure this comes before MSVCSetupApi.h
#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;
  // First just query for the required size.
  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();
    }
    // The destination buffer must be empty as an invariant of the conversion
    // function; but this function is sometimes called in a loop that passes in
    // the same buffer, however. Simply clear it out so we can overwrite it.
    value.clear();
    return llvm::convertWideToUTF8(WideValue, value);
  }
  return false;
}
#endif

/// Read registry string.
/// This also supports a means to look for high-versioned keys by use
/// of a $VERSION placeholder in the key path.
/// $VERSION in the key path is a placeholder for the version number,
/// causing the highest value path to be searched for and used.
/// I.e. "SOFTWARE\\Microsoft\\VisualStudio\\$VERSION".
/// There can be additional characters in the component.  Only the numeric
/// characters are compared.  This function only searches HKLM.
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) {}

} // namespace llvm