forked from OSchip/llvm-project
[clang-scan-deps] Fix for input file given as relative path in compilation database "command" entry.
Differential Revision: https://reviews.llvm.org/D91204
This commit is contained in:
parent
11dee2eae2
commit
79105e4644
|
@ -44,28 +44,6 @@ private:
|
|||
DependencyConsumer &C;
|
||||
};
|
||||
|
||||
/// A proxy file system that doesn't call `chdir` when changing the working
|
||||
/// directory of a clang tool.
|
||||
class ProxyFileSystemWithoutChdir : public llvm::vfs::ProxyFileSystem {
|
||||
public:
|
||||
ProxyFileSystemWithoutChdir(
|
||||
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS)
|
||||
: ProxyFileSystem(std::move(FS)) {}
|
||||
|
||||
llvm::ErrorOr<std::string> getCurrentWorkingDirectory() const override {
|
||||
assert(!CWD.empty() && "empty CWD");
|
||||
return CWD;
|
||||
}
|
||||
|
||||
std::error_code setCurrentWorkingDirectory(const Twine &Path) override {
|
||||
CWD = Path.str();
|
||||
return {};
|
||||
}
|
||||
|
||||
private:
|
||||
std::string CWD;
|
||||
};
|
||||
|
||||
/// A clang tool that runs the preprocessor in a mode that's optimized for
|
||||
/// dependency scanning for the given compiler invocation.
|
||||
class DependencyScanningAction : public tooling::ToolAction {
|
||||
|
@ -176,7 +154,7 @@ DependencyScanningWorker::DependencyScanningWorker(
|
|||
: Format(Service.getFormat()) {
|
||||
DiagOpts = new DiagnosticOptions();
|
||||
PCHContainerOps = std::make_shared<PCHContainerOperations>();
|
||||
RealFS = new ProxyFileSystemWithoutChdir(llvm::vfs::getRealFileSystem());
|
||||
RealFS = llvm::vfs::createPhysicalFileSystem().release();
|
||||
if (Service.canSkipExcludedPPRanges())
|
||||
PPSkipMappings =
|
||||
std::make_unique<ExcludedPreprocessorDirectiveSkipMapping>();
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
[
|
||||
{
|
||||
"directory": "DIR",
|
||||
"command": "clang -E Inputs/relative_directory_input1.cpp -IInputs",
|
||||
"file": "DIR/Inputs/relative_directory_input1.cpp"
|
||||
},
|
||||
{
|
||||
"directory": "DIR/Inputs",
|
||||
"command": "clang -E relative_directory_input2.cpp -I.",
|
||||
"file": "DIR/Inputs/relative_directory_input2.cpp"
|
||||
}
|
||||
]
|
|
@ -0,0 +1,25 @@
|
|||
// RUN: rm -rf %t.dir
|
||||
// RUN: rm -rf %t.cdb
|
||||
// RUN: mkdir -p %t.dir
|
||||
// RUN: mkdir %t.dir/Inputs
|
||||
// RUN: cp %s %t.dir/Inputs/relative_directory_input1.cpp
|
||||
// RUN: cp %s %t.dir/Inputs/relative_directory_input2.cpp
|
||||
// RUN: touch %t.dir/Inputs/header.h
|
||||
// RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/relative_directory.json > %t.cdb
|
||||
//
|
||||
// RUN: clang-scan-deps -compilation-database %t.cdb -j 1 | FileCheck --check-prefixes=CHECK1,CHECK2 %s
|
||||
|
||||
// The output order is non-deterministic when using more than one thread,
|
||||
// so check the output using two runs.
|
||||
// RUN: clang-scan-deps -compilation-database %t.cdb -j 2 | FileCheck --check-prefix=CHECK1 %s
|
||||
// RUN: clang-scan-deps -compilation-database %t.cdb -j 2 | FileCheck --check-prefix=CHECK2 %s
|
||||
|
||||
#include <header.h>
|
||||
|
||||
// CHECK1: relative_directory_input1.o:
|
||||
// CHECK1-NEXT: relative_directory_input1.cpp
|
||||
// CHECK1-NEXT: header.h
|
||||
|
||||
// CHECK2: relative_directory_input2.o:
|
||||
// CHECK2-NEXT: relative_directory_input2.cpp
|
||||
// CHECK2-NEXT: header.h
|
Loading…
Reference in New Issue