Skip to content

Commit 9a84d01

Browse files
authored
Merge pull request #25725 from nkcsgexi/compiler-style-diags
swift-api-digester: add a flag to print compiler-style diagnostics to stderr
2 parents b72b3cb + 47d205a commit 9a84d01

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
// can be reflected as source-breaking changes for API users. If they are,
2727
// the output of api-digester will include such changes.
2828

29+
#include "swift/Frontend/PrintingDiagnosticConsumer.h"
2930
#include "swift/AST/DiagnosticsModuleDiffer.h"
3031
#include "swift/IDE/APIDigesterData.h"
3132
#include <functional>
@@ -209,6 +210,11 @@ static llvm::cl::opt<std::string>
209210
LocationFilter("location",
210211
llvm::cl::desc("Filter nodes with the given location."),
211212
llvm::cl::cat(Category));
213+
214+
static llvm::cl::opt<bool>
215+
CompilerStyleDiags("compiler-style-diags",
216+
llvm::cl::desc("Print compiler style diagnostics to stderr."),
217+
llvm::cl::cat(Category));
212218
} // namespace options
213219

214220
namespace {
@@ -2114,9 +2120,11 @@ static int diagnoseModuleChange(SDKContext &Ctx, SDKNodeRoot *LeftModule,
21142120
FileOS.reset(new llvm::raw_fd_ostream(OutputPath, EC, llvm::sys::fs::F_None));
21152121
OS = FileOS.get();
21162122
}
2117-
ModuleDifferDiagsConsumer PDC(true, *OS);
2123+
std::unique_ptr<DiagnosticConsumer> pConsumer = options::CompilerStyleDiags ?
2124+
llvm::make_unique<PrintingDiagnosticConsumer>():
2125+
llvm::make_unique<ModuleDifferDiagsConsumer>(true, *OS);
21182126

2119-
Ctx.getDiags().addConsumer(PDC);
2127+
Ctx.getDiags().addConsumer(*pConsumer);
21202128
TypeAliasDiffFinder(LeftModule, RightModule,
21212129
Ctx.getTypeAliasUpdateMap()).search();
21222130
PrunePass Prune(Ctx, std::move(ProtocolReqWhitelist));
@@ -2185,10 +2193,11 @@ static int generateMigrationScript(StringRef LeftPath, StringRef RightPath,
21852193
return 1;
21862194
}
21872195
llvm::errs() << "Diffing: " << LeftPath << " and " << RightPath << "\n";
2188-
2189-
ModuleDifferDiagsConsumer PDC(false);
2196+
std::unique_ptr<DiagnosticConsumer> pConsumer = options::CompilerStyleDiags ?
2197+
llvm::make_unique<PrintingDiagnosticConsumer>():
2198+
llvm::make_unique<ModuleDifferDiagsConsumer>(false);
21902199
SDKContext Ctx(Opts);
2191-
Ctx.getDiags().addConsumer(PDC);
2200+
Ctx.getDiags().addConsumer(*pConsumer);
21922201

21932202
SwiftDeclCollector LeftCollector(Ctx);
21942203
LeftCollector.deSerialize(LeftPath);

0 commit comments

Comments
 (0)