aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/CommandLine.cpp
diff options
context:
space:
mode:
authorSerge Pavlov <sepavloff@gmail.com>2022-08-29 12:50:36 +0700
committerSerge Pavlov <sepavloff@gmail.com>2022-09-09 16:28:51 +0700
commit9424497e43aff088e014d65fd952ec557e28e6cf (patch)
tree9ad728dfd34df836e6678050656acc5e3441bc47 /llvm/lib/Support/CommandLine.cpp
parent1f639d1bd2f202f9bdf7c5023c93b4e3c8563413 (diff)
downloadllvm-9424497e43aff088e014d65fd952ec557e28e6cf.zip
llvm-9424497e43aff088e014d65fd952ec557e28e6cf.tar.gz
llvm-9424497e43aff088e014d65fd952ec557e28e6cf.tar.bz2
[Clang] Use virtual FS in processing config files
Clang has support of virtual file system for the purpose of testing, but treatment of config files did not use it. This change enables VFS in it as well. Differential Revision: https://reviews.llvm.org/D132867
Diffstat (limited to 'llvm/lib/Support/CommandLine.cpp')
-rw-r--r--llvm/lib/Support/CommandLine.cpp31
1 files changed, 20 insertions, 11 deletions
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp
index b8375f6..d81e115 100644
--- a/llvm/lib/Support/CommandLine.cpp
+++ b/llvm/lib/Support/CommandLine.cpp
@@ -1264,10 +1264,17 @@ bool cl::ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer,
// always have an absolute path deduced from the containing file.
SmallString<128> CurrDir;
if (llvm::sys::path::is_relative(FName)) {
- if (!CurrentDir)
- llvm::sys::fs::current_path(CurrDir);
- else
+ if (!CurrentDir) {
+ if (auto CWD = FS.getCurrentWorkingDirectory()) {
+ CurrDir = *CWD;
+ } else {
+ // TODO: The error should be propagated up the stack.
+ llvm::consumeError(llvm::errorCodeToError(CWD.getError()));
+ return false;
+ }
+ } else {
CurrDir = *CurrentDir;
+ }
llvm::sys::path::append(CurrDir, FName);
FName = CurrDir.c_str();
}
@@ -1357,24 +1364,26 @@ bool cl::expandResponseFiles(int Argc, const char *const *Argv,
}
bool cl::readConfigFile(StringRef CfgFile, StringSaver &Saver,
- SmallVectorImpl<const char *> &Argv) {
+ SmallVectorImpl<const char *> &Argv,
+ llvm::vfs::FileSystem &FS) {
SmallString<128> AbsPath;
if (sys::path::is_relative(CfgFile)) {
- llvm::sys::fs::current_path(AbsPath);
- llvm::sys::path::append(AbsPath, CfgFile);
+ AbsPath.assign(CfgFile);
+ if (std::error_code EC = FS.makeAbsolute(AbsPath))
+ return false;
CfgFile = AbsPath.str();
}
- if (llvm::Error Err = ExpandResponseFile(
- CfgFile, Saver, cl::tokenizeConfigFile, Argv,
- /*MarkEOLs=*/false, /*RelativeNames=*/true, /*ExpandBasePath=*/true,
- *llvm::vfs::getRealFileSystem())) {
+ if (llvm::Error Err =
+ ExpandResponseFile(CfgFile, Saver, cl::tokenizeConfigFile, Argv,
+ /*MarkEOLs=*/false, /*RelativeNames=*/true,
+ /*ExpandBasePath=*/true, FS)) {
// TODO: The error should be propagated up the stack.
llvm::consumeError(std::move(Err));
return false;
}
return ExpandResponseFiles(Saver, cl::tokenizeConfigFile, Argv,
/*MarkEOLs=*/false, /*RelativeNames=*/true,
- /*ExpandBasePath=*/true, llvm::None);
+ /*ExpandBasePath=*/true, llvm::None, FS);
}
static void initCommonOptions();