Skip to content
This repository has been archived by the owner on Mar 28, 2020. It is now read-only.

Commit

Permalink
Fix the 'directory' field in DumpCompilationDatabase and add test
Browse files Browse the repository at this point in the history
This broke in r371027 due to a missing negation
(llvm::sys::fs::current_path returns false on success).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@373049 91177308-0d34-0410-b5e6-96231b3b80d8
(cherry picked from commit 0f7791e)
  • Loading branch information
zmodem authored and JDevlieghere committed Sep 27, 2019
1 parent 59d80e7 commit 680e510
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2016,7 +2016,7 @@ void Clang::DumpCompilationDatabase(Compilation &C, StringRef Filename,
}
auto &CDB = *CompilationDatabase;
SmallString<128> Buf;
if (!llvm::sys::fs::current_path(Buf))
if (llvm::sys::fs::current_path(Buf))
Buf = ".";
CDB << "{ \"directory\": \"" << escape(Buf) << "\"";
CDB << ", \"file\": \"" << escape(Input.getFilename()) << "\"";
Expand Down
4 changes: 2 additions & 2 deletions test/Driver/compilation_database.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// RUN: mkdir -p %t && cd %t
// RUN: mkdir -p %t.workdir && cd %t.workdir
// RUN: %clang -MD -MP --sysroot=somewhere -c -x c %s -xc++ %s -Wall -MJ - -no-canonical-prefixes 2>&1 | FileCheck %s
// RUN: not %clang -c -x c %s -MJ %s/non-existant -no-canonical-prefixes 2>&1 | FileCheck --check-prefix=ERROR %s

// CHECK: { "directory": "{{.*}}", "file": "[[SRC:[^"]+[/|\\]compilation_database.c]]", "output": "compilation_database.o", "arguments": ["{{[^"]*}}clang{{[^"]*}}", "-xc", "[[SRC]]", "--sysroot=somewhere", "-c", "-Wall",{{.*}} "--target={{[^"]+}}"]},
// CHECK: { "directory": "{{[^"]*}}workdir", "file": "[[SRC:[^"]+[/|\\]compilation_database.c]]", "output": "compilation_database.o", "arguments": ["{{[^"]*}}clang{{[^"]*}}", "-xc", "[[SRC]]", "--sysroot=somewhere", "-c", "-Wall",{{.*}} "--target={{[^"]+}}"]},
// CHECK: { "directory": "{{.*}}", "file": "[[SRC:[^"]+[/|\\]compilation_database.c]]", "output": "compilation_database.o", "arguments": ["{{[^"]*}}clang{{[^"]*}}", "-xc++", "[[SRC]]", "--sysroot=somewhere", "-c", "-Wall",{{.*}} "--target={{[^"]+}}"]},
// ERROR: error: compilation database '{{.*}}/non-existant' could not be opened:

Expand Down

0 comments on commit 680e510

Please sign in to comment.