[clang] 79105e4 - [clang-scan-deps] Fix for input file given as relative path in compilation database "command" entry.
Sylvain Audi via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 12 05:48:38 PST 2020
Author: Sylvain Audi
Date: 2020-11-12T08:48:17-05:00
New Revision: 79105e464429d2220c81b38bf5339b9c41da1d21
URL: https://github.com/llvm/llvm-project/commit/79105e464429d2220c81b38bf5339b9c41da1d21
DIFF: https://github.com/llvm/llvm-project/commit/79105e464429d2220c81b38bf5339b9c41da1d21.diff
LOG: [clang-scan-deps] Fix for input file given as relative path in compilation database "command" entry.
Differential Revision: https://reviews.llvm.org/D91204
Added:
clang/test/ClangScanDeps/Inputs/relative_directory.json
clang/test/ClangScanDeps/relative_directory.cpp
Modified:
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
Removed:
################################################################################
diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
index 32bbc578d2db..f10b60252715 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -44,28 +44,6 @@ class DependencyConsumerForwarder : public DependencyFileGenerator {
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>();
diff --git a/clang/test/ClangScanDeps/Inputs/relative_directory.json b/clang/test/ClangScanDeps/Inputs/relative_directory.json
new file mode 100644
index 000000000000..ae3d16150bea
--- /dev/null
+++ b/clang/test/ClangScanDeps/Inputs/relative_directory.json
@@ -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"
+}
+]
diff --git a/clang/test/ClangScanDeps/relative_directory.cpp b/clang/test/ClangScanDeps/relative_directory.cpp
new file mode 100644
index 000000000000..bf5cf91a2f7b
--- /dev/null
+++ b/clang/test/ClangScanDeps/relative_directory.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
More information about the cfe-commits
mailing list