]> granicus.if.org Git - clang/commitdiff
[clang-scan-deps] strip the --serialize-diagnostics argument
authorAlex Lorenz <arphaman@gmail.com>
Sat, 21 Sep 2019 00:17:26 +0000 (00:17 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Sat, 21 Sep 2019 00:17:26 +0000 (00:17 +0000)
This ensures that clang-scan-deps won't write out diagnostics when
scanning dependencies.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@372444 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Tooling/ArgumentsAdjusters.h
lib/Tooling/ArgumentsAdjusters.cpp
test/ClangScanDeps/Inputs/strip_diag_serialize.json [new file with mode: 0644]
test/ClangScanDeps/strip_diag_serialize.cpp [new file with mode: 0644]
tools/clang-scan-deps/ClangScanDeps.cpp

index bf0886034324ab71bf17045f3356d298ae07cf75..c48a8725aae90d19107f56bdd512e80d08a2099b 100644 (file)
@@ -43,6 +43,10 @@ ArgumentsAdjuster getClangSyntaxOnlyAdjuster();
 /// arguments.
 ArgumentsAdjuster getClangStripOutputAdjuster();
 
+/// Gets an argument adjuster which removes command line arguments related to
+/// diagnostic serialization.
+ArgumentsAdjuster getClangStripSerializeDiagnosticAdjuster();
+
 /// Gets an argument adjuster which removes dependency-file
 /// related command line arguments.
 ArgumentsAdjuster getClangStripDependencyFileAdjuster();
index 942b35df453e9b05274accc0a5bb33809a318d34..f56d08c47b9a4336a92f15e5a36d9fd9d3c17eb5 100644 (file)
@@ -57,6 +57,22 @@ ArgumentsAdjuster getClangStripOutputAdjuster() {
   };
 }
 
+ArgumentsAdjuster getClangStripSerializeDiagnosticAdjuster() {
+  return [](const CommandLineArguments &Args, StringRef /*unused*/) {
+    CommandLineArguments AdjustedArgs;
+    for (size_t i = 0, e = Args.size(); i < e; ++i) {
+      StringRef Arg = Args[i];
+      if (Arg == "--serialize-diagnostics") {
+        // Skip the diagnostic output argument.
+        ++i;
+        continue;
+      }
+      AdjustedArgs.push_back(Args[i]);
+    }
+    return AdjustedArgs;
+  };
+}
+
 ArgumentsAdjuster getClangStripDependencyFileAdjuster() {
   return [](const CommandLineArguments &Args, StringRef /*unused*/) {
     CommandLineArguments AdjustedArgs;
diff --git a/test/ClangScanDeps/Inputs/strip_diag_serialize.json b/test/ClangScanDeps/Inputs/strip_diag_serialize.json
new file mode 100644 (file)
index 0000000..a774d95
--- /dev/null
@@ -0,0 +1,7 @@
+[
+{
+  "directory": "DIR",
+  "command": "clang -E -fsyntax-only DIR/strip_diag_serialize_input.cpp --serialize-diagnostics /does/not/exist",
+  "file": "DIR/strip_diag_serialize_input.cpp"
+}
+]
diff --git a/test/ClangScanDeps/strip_diag_serialize.cpp b/test/ClangScanDeps/strip_diag_serialize.cpp
new file mode 100644 (file)
index 0000000..ec62e75
--- /dev/null
@@ -0,0 +1,11 @@
+// RUN: rm -rf %t.dir
+// RUN: rm -rf %t.cdb
+// RUN: mkdir -p %t.dir
+// RUN: cp %s %t.dir/strip_diag_serialize_input.cpp
+// RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/strip_diag_serialize.json > %t.cdb
+//
+// RUN: clang-scan-deps -compilation-database %t.cdb 2>&1 | FileCheck %s
+// CHECK-NOT: unable to open file
+// CHECK: strip_diag_serialize_input.cpp
+
+#warning "diagnostic"
index ebb42c034633ece124c8136ac05486df8e96bb56..d44e3b9ff3558f1dfb6511064e3468521de57133 100644 (file)
@@ -266,6 +266,8 @@ int main(int argc, const char **argv) {
         AdjustedArgs.push_back("-Wno-error");
         return AdjustedArgs;
       });
+  AdjustingCompilations->appendArgumentsAdjuster(
+      tooling::getClangStripSerializeDiagnosticAdjuster());
 
   SharedStream Errs(llvm::errs());
   // Print out the dependency results to STDOUT by default.