From: Sam Clegg Date: Thu, 19 Mar 2020 22:20:49 +0000 (-0700) Subject: [clang] Allow -DDEFAULT_SYSROOT to be a relative path X-Git-Tag: llvmorg-12-init~10997 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0731372ee25c8db93e0d976db4be4ffb7c7329c5;p=platform%2Fupstream%2Fllvm.git [clang] Allow -DDEFAULT_SYSROOT to be a relative path In this case we interpret the path as relative the clang driver binary. This allows SDKs to be built that include clang along with a custom sysroot without requiring users to specify --sysroot to point to the directory where they installed the SDK. See https://github.com/WebAssembly/wasi-sdk/issues/58 Differential Revision: https://reviews.llvm.org/D76653 --- diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt index db82d87..7809d65 100644 --- a/clang/CMakeLists.txt +++ b/clang/CMakeLists.txt @@ -226,7 +226,7 @@ set(C_INCLUDE_DIRS "" CACHE STRING "Colon separated list of directories clang will search for headers.") set(GCC_INSTALL_PREFIX "" CACHE PATH "Directory where gcc is installed." ) -set(DEFAULT_SYSROOT "" CACHE PATH +set(DEFAULT_SYSROOT "" CACHE STRING "Default to all compiler invocations for --sysroot=." ) set(ENABLE_LINKER_BUILD_ID OFF CACHE BOOL "pass --build-id to ld") diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index e3b7793..4afe3e6 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -140,6 +140,13 @@ Driver::Driver(StringRef ClangExecutable, StringRef TargetTriple, Dir = std::string(llvm::sys::path::parent_path(ClangExecutable)); InstalledDir = Dir; // Provide a sensible default installed dir. + if ((!SysRoot.empty()) && llvm::sys::path::is_relative(SysRoot)) { + // Prepend InstalledDir if SysRoot is relative + SmallString<128> P(InstalledDir); + llvm::sys::path::append(P, SysRoot); + SysRoot = std::string(P); + } + #if defined(CLANG_CONFIG_FILE_SYSTEM_DIR) SystemConfigDir = CLANG_CONFIG_FILE_SYSTEM_DIR; #endif