Skip to content

Commit 1682c99

Browse files
authored
[Clang][Driver] Support relative paths for CLANG_CONFIG_FILE_SYSTEM_DIR (#110962)
Shipping a system configuration file for Clang is useful, but it limits the relocatability of the toolchain because it bakes in a reference to an absolute path on the file system. Let's fix that by allowing for `CLANG_CONFIG_FILE_SYSTEM_DIR` to be set to a relative path, and then interpreting that relative to the location of the driver if applicable. This would be useful for the LLVM package we ship at Homebrew. We currently have to bake in a `DEFAULT_SYSROOT` in order to ship a toolchain that works out of the box on macOS. If `CLANG_CONFIG_FILE_SYSTEM_DIR` supported relative paths, we could replace that with a configuration file which would be easier to update when the compiled-in `DEFAULT_SYSROOT` becomes stale (e.g. on macOS version upgrades). We could, of course, set `CLANG_CONFIG_FILE_SYSTEM_DIR` to an absolute path to begin with. However, we do have users who install Homebrew into a prefix that is different from the one used on our buildbots, so doing this would result in a broken toolchain for those users.
1 parent c4c34f0 commit 1682c99

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,14 @@ Driver::Driver(StringRef ClangExecutable, StringRef TargetTriple,
229229
}
230230

231231
#if defined(CLANG_CONFIG_FILE_SYSTEM_DIR)
232-
SystemConfigDir = CLANG_CONFIG_FILE_SYSTEM_DIR;
232+
if (llvm::sys::path::is_absolute(CLANG_CONFIG_FILE_SYSTEM_DIR)) {
233+
SystemConfigDir = CLANG_CONFIG_FILE_SYSTEM_DIR;
234+
} else {
235+
SmallString<128> configFileDir(Dir);
236+
llvm::sys::path::append(configFileDir, CLANG_CONFIG_FILE_SYSTEM_DIR);
237+
llvm::sys::path::remove_dots(configFileDir, true);
238+
SystemConfigDir = static_cast<std::string>(configFileDir);
239+
}
233240
#endif
234241
#if defined(CLANG_CONFIG_FILE_USER_DIR)
235242
{

0 commit comments

Comments
 (0)