Skip to content

Commit

Permalink
[clang-scan-deps] strip the --serialize-diagnostics argument
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hyp committed Sep 21, 2019
1 parent c091e0e commit 69a791e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/clang/Tooling/ArgumentsAdjusters.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 16 additions & 0 deletions lib/Tooling/ArgumentsAdjusters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions test/ClangScanDeps/Inputs/strip_diag_serialize.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
11 changes: 11 additions & 0 deletions test/ClangScanDeps/strip_diag_serialize.cpp
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 2 additions & 0 deletions tools/clang-scan-deps/ClangScanDeps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 69a791e

Please sign in to comment.