Skip to content

ABI Checker: add an option to serialize diagnostics to a file path #31355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions tools/swift-api-digester/swift-api-digester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
// the output of api-digester will include such changes.

#include "swift/Frontend/PrintingDiagnosticConsumer.h"
#include "swift/Frontend/SerializedDiagnosticConsumer.h"
#include "swift/AST/DiagnosticsModuleDiffer.h"
#include "swift/IDE/APIDigesterData.h"
#include <functional>
Expand Down Expand Up @@ -257,6 +258,12 @@ static llvm::cl::opt<bool>
UseEmptyBaseline("empty-baseline",
llvm::cl::desc("Use empty baseline for diagnostics"),
llvm::cl::cat(Category));

static llvm::cl::opt<std::string>
SerializedDiagPath("serialize-diagnostics-path",
llvm::cl::desc("Serialize diagnostics to a path"),
llvm::cl::cat(Category));

} // namespace options

namespace {
Expand Down Expand Up @@ -2284,6 +2291,20 @@ static void findTypeMemberDiffs(NodePtr leftSDKRoot, NodePtr rightSDKRoot,
}
}

static std::unique_ptr<DiagnosticConsumer>
createDiagConsumer(llvm::raw_ostream &OS, bool &FailOnError) {
if (!options::SerializedDiagPath.empty()) {
FailOnError = true;
return serialized_diagnostics::createConsumer(options::SerializedDiagPath);
} else if (options::CompilerStyleDiags) {
FailOnError = true;
return std::make_unique<PrintingDiagnosticConsumer>();
} else {
FailOnError = false;
return std::make_unique<ModuleDifferDiagsConsumer>(true, OS);
}
}

static int diagnoseModuleChange(SDKContext &Ctx, SDKNodeRoot *LeftModule,
SDKNodeRoot *RightModule, StringRef OutputPath,
llvm::StringSet<> ProtocolReqWhitelist) {
Expand All @@ -2300,9 +2321,9 @@ static int diagnoseModuleChange(SDKContext &Ctx, SDKNodeRoot *LeftModule,
FileOS.reset(new llvm::raw_fd_ostream(OutputPath, EC, llvm::sys::fs::F_None));
OS = FileOS.get();
}
std::unique_ptr<DiagnosticConsumer> pConsumer = options::CompilerStyleDiags ?
std::make_unique<PrintingDiagnosticConsumer>():
std::make_unique<ModuleDifferDiagsConsumer>(true, *OS);
bool FailOnError;
std::unique_ptr<DiagnosticConsumer> pConsumer =
createDiagConsumer(*OS, FailOnError);

Ctx.addDiagConsumer(*pConsumer);
Ctx.setCommonVersion(std::min(LeftModule->getJsonFormatVersion(),
Expand All @@ -2316,7 +2337,7 @@ static int diagnoseModuleChange(SDKContext &Ctx, SDKNodeRoot *LeftModule,
// Find member hoist changes to help refine diagnostics.
findTypeMemberDiffs(LeftModule, RightModule, Ctx.getTypeMemberDiffs());
DiagnosisEmitter::diagnosis(LeftModule, RightModule, Ctx);
return options::CompilerStyleDiags && Ctx.getDiags().hadAnyError() ? 1 : 0;
return FailOnError && Ctx.getDiags().hadAnyError() ? 1 : 0;
}

static int diagnoseModuleChange(StringRef LeftPath, StringRef RightPath,
Expand Down