@@ -1915,42 +1915,20 @@ static bool readBreakageAllowlist(SDKContext &Ctx, llvm::StringSet<> &lines,
1915
1915
}
1916
1916
1917
1917
static int diagnoseModuleChange (SDKContext &Ctx, SDKNodeRoot *LeftModule,
1918
- SDKNodeRoot *RightModule, StringRef OutputPath,
1918
+ SDKNodeRoot *RightModule,
1919
1919
llvm::StringSet<> ProtocolReqAllowlist,
1920
- bool DisableFailOnError,
1921
- bool CompilerStyleDiags,
1922
- StringRef SerializedDiagPath,
1923
- StringRef BreakageAllowlistPath,
1924
- bool DebugMapping) {
1920
+ bool DebugMapping,
1921
+ bool FailOnError,
1922
+ FilteringDiagnosticConsumer *pConsumer) {
1925
1923
PrettyStackTraceSDKNodes trace (
1926
1924
" diagnosing changes between modules" , LeftModule, RightModule);
1927
1925
1928
1926
assert (LeftModule);
1929
1927
assert (RightModule);
1930
- llvm::raw_ostream *OS = &llvm::errs ();
1931
1928
if (!LeftModule || !RightModule) {
1932
- *OS << " Cannot diagnose null SDKNodeRoot" ;
1929
+ llvm::errs () << " Cannot diagnose null SDKNodeRoot" ;
1933
1930
exit (1 );
1934
1931
}
1935
- std::unique_ptr<llvm::raw_ostream> FileOS;
1936
- if (!OutputPath.empty ()) {
1937
- std::error_code EC;
1938
- FileOS.reset (new llvm::raw_fd_ostream (OutputPath, EC, llvm::sys::fs::OF_None));
1939
- OS = FileOS.get ();
1940
- }
1941
- bool FailOnError;
1942
- auto allowedBreakages = std::make_unique<llvm::StringSet<>>();
1943
- if (readBreakageAllowlist (Ctx, *allowedBreakages, BreakageAllowlistPath)) {
1944
- Ctx.getDiags ().diagnose (SourceLoc (), diag::cannot_read_allowlist,
1945
- BreakageAllowlistPath);
1946
- }
1947
- auto pConsumer = std::make_unique<FilteringDiagnosticConsumer>(
1948
- createDiagConsumer (*OS, FailOnError, DisableFailOnError, CompilerStyleDiags,
1949
- SerializedDiagPath),
1950
- std::move (allowedBreakages),
1951
- /* DowngradeToWarning*/ false );
1952
- SWIFT_DEFER { pConsumer->finishProcessing (); };
1953
- Ctx.addDiagConsumer (*pConsumer);
1954
1932
Ctx.setCommonVersion (std::min (LeftModule->getJsonFormatVersion (),
1955
1933
RightModule->getJsonFormatVersion ()));
1956
1934
TypeAliasDiffFinder (LeftModule, RightModule,
@@ -1965,14 +1943,12 @@ static int diagnoseModuleChange(SDKContext &Ctx, SDKNodeRoot *LeftModule,
1965
1943
return FailOnError && pConsumer->hasError () ? 1 : 0 ;
1966
1944
}
1967
1945
1968
- static int diagnoseModuleChange (StringRef LeftPath , StringRef RightPath ,
1969
- StringRef OutputPath, CheckerOptions Opts ,
1946
+ static int diagnoseModuleChange (SDKContext &Ctx , StringRef LeftPath ,
1947
+ StringRef RightPath ,
1970
1948
llvm::StringSet<> ProtocolReqAllowlist,
1971
- bool DisableFailOnError,
1972
- bool CompilerStyleDiags,
1973
- StringRef SerializedDiagPath,
1974
- StringRef BreakageAllowlistPath,
1975
- bool DebugMapping) {
1949
+ bool DebugMapping,
1950
+ bool FailOnError,
1951
+ FilteringDiagnosticConsumer *pConsumer) {
1976
1952
if (!fs::exists (LeftPath)) {
1977
1953
llvm::errs () << LeftPath << " does not exist\n " ;
1978
1954
return 1 ;
@@ -1981,15 +1957,13 @@ static int diagnoseModuleChange(StringRef LeftPath, StringRef RightPath,
1981
1957
llvm::errs () << RightPath << " does not exist\n " ;
1982
1958
return 1 ;
1983
1959
}
1984
- SDKContext Ctx (Opts);
1985
1960
SwiftDeclCollector LeftCollector (Ctx);
1986
1961
LeftCollector.deSerialize (LeftPath);
1987
1962
SwiftDeclCollector RightCollector (Ctx);
1988
1963
RightCollector.deSerialize (RightPath);
1989
1964
return diagnoseModuleChange (
1990
- Ctx, LeftCollector.getSDKRoot (), RightCollector.getSDKRoot (), OutputPath,
1991
- std::move (ProtocolReqAllowlist), DisableFailOnError, CompilerStyleDiags, SerializedDiagPath,
1992
- BreakageAllowlistPath, DebugMapping);
1965
+ Ctx, LeftCollector.getSDKRoot (), RightCollector.getSDKRoot (),
1966
+ std::move (ProtocolReqAllowlist), DebugMapping, FailOnError, pConsumer);
1993
1967
}
1994
1968
1995
1969
static void populateAliasChanges (NodeMap &AliasMap, DiffVector &AllItems,
@@ -2579,26 +2553,46 @@ class SwiftAPIDigesterInvocation {
2579
2553
OutputFile, IgnoredUsrs, CheckerOpts,
2580
2554
OutputInJson, DebugMapping);
2581
2555
}
2556
+ SDKContext Ctx (CheckerOpts);
2557
+
2558
+ llvm::raw_ostream *OS = &llvm::errs ();
2559
+ std::unique_ptr<llvm::raw_ostream> FileOS;
2560
+ if (!OutputFile.empty ()) {
2561
+ std::error_code EC;
2562
+ FileOS.reset (new llvm::raw_fd_ostream (OutputFile, EC, llvm::sys::fs::OF_None));
2563
+ OS = FileOS.get ();
2564
+ }
2565
+ bool FailOnError;
2566
+ auto allowedBreakages = std::make_unique<llvm::StringSet<>>();
2567
+ if (readBreakageAllowlist (Ctx, *allowedBreakages, BreakageAllowlistPath)) {
2568
+ Ctx.getDiags ().diagnose (SourceLoc (), diag::cannot_read_allowlist,
2569
+ BreakageAllowlistPath);
2570
+ }
2571
+ auto pConsumer = std::make_unique<FilteringDiagnosticConsumer>(
2572
+ createDiagConsumer (*OS, FailOnError, DisableFailOnError, CompilerStyleDiags,
2573
+ SerializedDiagPath),
2574
+ std::move (allowedBreakages),
2575
+ /* DowngradeToWarning*/ false );
2576
+ SWIFT_DEFER { pConsumer->finishProcessing (); };
2577
+ Ctx.addDiagConsumer (*pConsumer);
2578
+
2582
2579
switch (Mode) {
2583
2580
case ComparisonInputMode::BothJson: {
2584
2581
return diagnoseModuleChange (
2585
- SDKJsonPaths[0 ], SDKJsonPaths[1 ], OutputFile, CheckerOpts,
2586
- std::move (protocolAllowlist), DisableFailOnError, CompilerStyleDiags,
2587
- SerializedDiagPath, BreakageAllowlistPath, DebugMapping);
2582
+ Ctx, SDKJsonPaths[0 ], SDKJsonPaths[1 ], std::move (protocolAllowlist),
2583
+ DebugMapping, FailOnError, pConsumer.get ());
2588
2584
}
2589
2585
case ComparisonInputMode::BaselineJson: {
2590
- SDKContext Ctx (CheckerOpts);
2591
2586
return diagnoseModuleChange (
2592
- Ctx, getBaselineFromJson (Ctx), getSDKRoot (Ctx, false ), OutputFile,
2593
- std::move (protocolAllowlist), DisableFailOnError, CompilerStyleDiags ,
2594
- SerializedDiagPath, BreakageAllowlistPath, DebugMapping );
2587
+ Ctx, getBaselineFromJson (Ctx), getSDKRoot (Ctx, false ),
2588
+ std::move (protocolAllowlist), DebugMapping, FailOnError ,
2589
+ pConsumer. get () );
2595
2590
}
2596
2591
case ComparisonInputMode::BothLoad: {
2597
- SDKContext Ctx (CheckerOpts);
2598
2592
return diagnoseModuleChange (
2599
- Ctx, getSDKRoot (Ctx, true ), getSDKRoot (Ctx, false ), OutputFile,
2600
- std::move (protocolAllowlist), DisableFailOnError, CompilerStyleDiags ,
2601
- SerializedDiagPath, BreakageAllowlistPath, DebugMapping );
2593
+ Ctx, getSDKRoot (Ctx, true ), getSDKRoot (Ctx, false ),
2594
+ std::move (protocolAllowlist), DebugMapping, FailOnError ,
2595
+ pConsumer. get () );
2602
2596
}
2603
2597
}
2604
2598
}
0 commit comments