[clang] 0731372 - [clang] Allow -DDEFAULT_SYSROOT to be a relative path
Sam Clegg via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 26 13:49:09 PDT 2020
Author: Sam Clegg
Date: 2020-03-26T13:48:57-07:00
New Revision: 0731372ee25c8db93e0d976db4be4ffb7c7329c5
URL: https://github.com/llvm/llvm-project/commit/0731372ee25c8db93e0d976db4be4ffb7c7329c5
DIFF: https://github.com/llvm/llvm-project/commit/0731372ee25c8db93e0d976db4be4ffb7c7329c5.diff
LOG: [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
Added:
Modified:
clang/CMakeLists.txt
clang/lib/Driver/Driver.cpp
Removed:
################################################################################
diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index db82d87b181f..7809d6529195 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 <path> to all compiler invocations for --sysroot=<path>." )
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 e3b7793ca266..4afe3e635fc8 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
More information about the cfe-commits
mailing list