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
/// 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();
};
}
-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");
// 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())
"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"
}
]
// 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"
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.