From: Hans Wennborg Date: Fri, 27 Sep 2019 08:14:45 +0000 (+0000) Subject: Fix the 'directory' field in DumpCompilationDatabase and add test X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0f7791ecb9716fb6e5c3493db28b7dcf44a06440;p=clang Fix the 'directory' field in DumpCompilationDatabase and add test 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 --- diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp index 5484a9289c..309ce7fdc7 100644 --- a/lib/Driver/ToolChains/Clang.cpp +++ b/lib/Driver/ToolChains/Clang.cpp @@ -2027,7 +2027,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()) << "\""; diff --git a/test/Driver/compilation_database.c b/test/Driver/compilation_database.c index 017178d60c..343b76aa44 100644 --- a/test/Driver/compilation_database.c +++ b/test/Driver/compilation_database.c @@ -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: