[clang][deps] Move stripping of diagnostic serialization from `clang-scan-deps` to...
authorJan Svoboda <jan_svoboda@apple.com>
Mon, 14 Jun 2021 10:02:19 +0000 (12:02 +0200)
committerJan Svoboda <jan_svoboda@apple.com>
Mon, 14 Jun 2021 10:23:32 +0000 (12:23 +0200)
To prevent the creation of diagnostics file, `clang-scan-deps` strips the corresponding command-line argument. This behavior is useful even when using the C++ `DependencyScanner` library.

This patch transforms stripping of command-line in `clang-scan-deps` into stripping of `CompilerInvocation` in `DependencyScanning`.

AFAIK, the `clang-cl` driver doesn't even accept `--serialize-diagnostics`, so I've removed the test. (It would fail with an unknown command-line argument otherwise.)

Note: Since we're generating command-lines for modular dependencies from `CompilerInvocation`, the `--serialize-diagnostics` will be dropped. This was already happening in `clang-scan-deps` before this patch, but it will now happen also when using `DependencyScanning` library directly. This is resolved in D104036.

Reviewed By: dexonsmith, arphaman

Differential Revision: https://reviews.llvm.org/D104012

clang/include/clang/Tooling/ArgumentsAdjusters.h
clang/lib/Tooling/ArgumentsAdjusters.cpp
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
clang/test/ClangScanDeps/Inputs/strip_diag_serialize.json
clang/test/ClangScanDeps/strip_diag_serialize.cpp
clang/tools/clang-scan-deps/ClangScanDeps.cpp

index c48a872..bf08860 100644 (file)
@@ -43,10 +43,6 @@ 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 d94673b..7f5dc4d 100644 (file)
@@ -86,22 +86,6 @@ 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*/) {
     auto UsingClDriver = (getDriverMode(Args) == "cl");
index ebcd16e..40466b0 100644 (file)
@@ -85,6 +85,8 @@ public:
 
     // Don't print 'X warnings and Y errors generated'.
     Compiler.getDiagnosticOpts().ShowCarets = false;
+    // Don't write out diagnostic file.
+    Compiler.getDiagnosticOpts().DiagnosticSerializationFile.clear();
     // Create the compiler's actual diagnostics engine.
     Compiler.createDiagnostics(DiagConsumer, /*ShouldOwnClient=*/false);
     if (!Compiler.hasDiagnostics())
index 7af1acd..a774d95 100644 (file)
@@ -3,10 +3,5 @@
   "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"
-},
-{
-  "directory": "DIR",
-  "command": "clang-cl /E --serialize-diagnostics A:/does/not/exist -- DIR/strip_diag_serialize_input_clangcl.cpp",
-  "file": "DIR/strip_diag_serialize_input_clangcl.cpp"
 }
 ]
index d9f7588..c8713be 100644 (file)
@@ -8,6 +8,5 @@
 // RUN: clang-scan-deps -compilation-database %t.cdb -j 1 2>&1 | FileCheck %s
 // CHECK-NOT: unable to open file
 // CHECK: strip_diag_serialize_input.cpp
-// CHECK: strip_diag_serialize_input_clangcl.cpp
 
 #warning "diagnostic"
index ce8be72..625a4c1 100644 (file)
@@ -571,8 +571,6 @@ int main(int argc, const char **argv) {
         AdjustedArgs.insert(AdjustedArgs.end(), FlagsEnd, Args.end());
         return AdjustedArgs;
       });
-  AdjustingCompilations->appendArgumentsAdjuster(
-      tooling::getClangStripSerializeDiagnosticAdjuster());
 
   SharedStream Errs(llvm::errs());
   // Print out the dependency results to STDOUT by default.