27
27
// the output of api-digester will include such changes.
28
28
29
29
#include " swift/Frontend/PrintingDiagnosticConsumer.h"
30
+ #include " swift/Frontend/SerializedDiagnosticConsumer.h"
30
31
#include " swift/AST/DiagnosticsModuleDiffer.h"
31
32
#include " swift/IDE/APIDigesterData.h"
32
33
#include < functional>
@@ -257,6 +258,12 @@ static llvm::cl::opt<bool>
257
258
UseEmptyBaseline (" empty-baseline" ,
258
259
llvm::cl::desc (" Use empty baseline for diagnostics" ),
259
260
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
+
260
267
} // namespace options
261
268
262
269
namespace {
@@ -2284,6 +2291,20 @@ static void findTypeMemberDiffs(NodePtr leftSDKRoot, NodePtr rightSDKRoot,
2284
2291
}
2285
2292
}
2286
2293
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
+
2287
2308
static int diagnoseModuleChange (SDKContext &Ctx, SDKNodeRoot *LeftModule,
2288
2309
SDKNodeRoot *RightModule, StringRef OutputPath,
2289
2310
llvm::StringSet<> ProtocolReqWhitelist) {
@@ -2300,9 +2321,9 @@ static int diagnoseModuleChange(SDKContext &Ctx, SDKNodeRoot *LeftModule,
2300
2321
FileOS.reset (new llvm::raw_fd_ostream (OutputPath, EC, llvm::sys::fs::F_None));
2301
2322
OS = FileOS.get ();
2302
2323
}
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 );
2306
2327
2307
2328
Ctx.addDiagConsumer (*pConsumer);
2308
2329
Ctx.setCommonVersion (std::min (LeftModule->getJsonFormatVersion (),
@@ -2316,7 +2337,7 @@ static int diagnoseModuleChange(SDKContext &Ctx, SDKNodeRoot *LeftModule,
2316
2337
// Find member hoist changes to help refine diagnostics.
2317
2338
findTypeMemberDiffs (LeftModule, RightModule, Ctx.getTypeMemberDiffs ());
2318
2339
DiagnosisEmitter::diagnosis (LeftModule, RightModule, Ctx);
2319
- return options::CompilerStyleDiags && Ctx.getDiags ().hadAnyError () ? 1 : 0 ;
2340
+ return FailOnError && Ctx.getDiags ().hadAnyError () ? 1 : 0 ;
2320
2341
}
2321
2342
2322
2343
static int diagnoseModuleChange (StringRef LeftPath, StringRef RightPath,
0 commit comments