Skip to content

Commit 1882c40

Browse files
authored
Merge pull request swiftlang#31355 from nkcsgexi/serialize-abi-checker-diag
ABI Checker: add an option to serialize diagnostics to a file path
2 parents e5aa9d7 + 6b6a65f commit 1882c40

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

tools/swift-api-digester/swift-api-digester.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
// the output of api-digester will include such changes.
2828

2929
#include "swift/Frontend/PrintingDiagnosticConsumer.h"
30+
#include "swift/Frontend/SerializedDiagnosticConsumer.h"
3031
#include "swift/AST/DiagnosticsModuleDiffer.h"
3132
#include "swift/IDE/APIDigesterData.h"
3233
#include <functional>
@@ -257,6 +258,12 @@ static llvm::cl::opt<bool>
257258
UseEmptyBaseline("empty-baseline",
258259
llvm::cl::desc("Use empty baseline for diagnostics"),
259260
llvm::cl::cat(Category));
261+
262+
static llvm::cl::opt<std::string>
263+
SerializedDiagPath("serialize-diagnostics-path",
264+
llvm::cl::desc("Serialize diagnostics to a path"),
265+
llvm::cl::cat(Category));
266+
260267
} // namespace options
261268

262269
namespace {
@@ -2284,6 +2291,20 @@ static void findTypeMemberDiffs(NodePtr leftSDKRoot, NodePtr rightSDKRoot,
22842291
}
22852292
}
22862293

2294+
static std::unique_ptr<DiagnosticConsumer>
2295+
createDiagConsumer(llvm::raw_ostream &OS, bool &FailOnError) {
2296+
if (!options::SerializedDiagPath.empty()) {
2297+
FailOnError = true;
2298+
return serialized_diagnostics::createConsumer(options::SerializedDiagPath);
2299+
} else if (options::CompilerStyleDiags) {
2300+
FailOnError = true;
2301+
return std::make_unique<PrintingDiagnosticConsumer>();
2302+
} else {
2303+
FailOnError = false;
2304+
return std::make_unique<ModuleDifferDiagsConsumer>(true, OS);
2305+
}
2306+
}
2307+
22872308
static int diagnoseModuleChange(SDKContext &Ctx, SDKNodeRoot *LeftModule,
22882309
SDKNodeRoot *RightModule, StringRef OutputPath,
22892310
llvm::StringSet<> ProtocolReqWhitelist) {
@@ -2300,9 +2321,9 @@ static int diagnoseModuleChange(SDKContext &Ctx, SDKNodeRoot *LeftModule,
23002321
FileOS.reset(new llvm::raw_fd_ostream(OutputPath, EC, llvm::sys::fs::F_None));
23012322
OS = FileOS.get();
23022323
}
2303-
std::unique_ptr<DiagnosticConsumer> pConsumer = options::CompilerStyleDiags ?
2304-
std::make_unique<PrintingDiagnosticConsumer>():
2305-
std::make_unique<ModuleDifferDiagsConsumer>(true, *OS);
2324+
bool FailOnError;
2325+
std::unique_ptr<DiagnosticConsumer> pConsumer =
2326+
createDiagConsumer(*OS, FailOnError);
23062327

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

23222343
static int diagnoseModuleChange(StringRef LeftPath, StringRef RightPath,

0 commit comments

Comments
 (0)