Skip to content

Commit 734d7ae

Browse files
committed
[APIDigester] Add a -disable-fail-on-error option
1 parent 038af80 commit 734d7ae

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

include/swift/Option/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,6 +1362,10 @@ def abort_on_module_fail: Flag<["-", "--"], "abort-on-module-fail">,
13621362
Flags<[NoDriverOption, SwiftAPIDigesterOption]>,
13631363
HelpText<"Abort if a module failed to load">;
13641364

1365+
def disable_fail_on_error: Flag<["-", "--"], "disable-fail-on-error">,
1366+
Flags<[NoDriverOption, SwiftAPIDigesterOption]>,
1367+
HelpText<"Don't exit with a nonzero status if errors are emitted">;
1368+
13651369
def debug_mapping: Flag<["-", "--"], "debug-mapping">,
13661370
Flags<[NoDriverOption, SwiftAPIDigesterOption]>,
13671371
HelpText<"Dumping information for debug purposes">;

test/api-digester/serialized-diagnostics.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// RUN: %target-swift-frontend -disable-objc-attr-requires-foundation-module -emit-module -o %t/color.swiftmodule %S/Inputs/cake_baseline/color.swift -parse-as-library -enable-library-evolution %clang-importer-sdk-nosource -module-name color
66
// RUN: not %api-digester -diagnose-sdk -serialize-diagnostics-path %t/result.dia -empty-baseline -I %t %clang-importer-sdk-nosource -module color -abi
77
// RUN: c-index-test -read-diagnostics %t/result.dia 2>&1 | %FileCheck %s -check-prefix CHECK-DIA
8+
// RUN: %api-digester -diagnose-sdk -serialize-diagnostics-path %t/result.dia -empty-baseline -I %t %clang-importer-sdk-nosource -module color -abi -disable-fail-on-error
9+
// RUN: c-index-test -read-diagnostics %t/result.dia 2>&1 | %FileCheck %s -check-prefix CHECK-DIA
810

911
// Ensure the 'api-digester-breaking-change' category is included in the serialized diagnostics file.
1012
// CHECK-DIA: error: ABI breakage: enum Color is a new API without @available attribute [] [api-digester-breaking-change]

tools/driver/swift_api_digester_main.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,13 +2107,13 @@ static void findTypeMemberDiffs(NodePtr leftSDKRoot, NodePtr rightSDKRoot,
21072107
}
21082108

21092109
static std::unique_ptr<DiagnosticConsumer>
2110-
createDiagConsumer(llvm::raw_ostream &OS, bool &FailOnError,
2110+
createDiagConsumer(llvm::raw_ostream &OS, bool &FailOnError, bool DisableFailOnError,
21112111
bool CompilerStyleDiags, StringRef SerializedDiagPath) {
21122112
if (!SerializedDiagPath.empty()) {
2113-
FailOnError = true;
2113+
FailOnError = !DisableFailOnError;
21142114
return serialized_diagnostics::createConsumer(SerializedDiagPath);
21152115
} else if (CompilerStyleDiags) {
2116-
FailOnError = true;
2116+
FailOnError = !DisableFailOnError;
21172117
return std::make_unique<PrintingDiagnosticConsumer>();
21182118
} else {
21192119
FailOnError = false;
@@ -2168,6 +2168,7 @@ static bool readBreakageAllowlist(SDKContext &Ctx, llvm::StringSet<> &lines,
21682168
static int diagnoseModuleChange(SDKContext &Ctx, SDKNodeRoot *LeftModule,
21692169
SDKNodeRoot *RightModule, StringRef OutputPath,
21702170
llvm::StringSet<> ProtocolReqAllowlist,
2171+
bool DisableFailOnError,
21712172
bool CompilerStyleDiags,
21722173
StringRef SerializedDiagPath,
21732174
StringRef BreakageAllowlistPath,
@@ -2192,7 +2193,7 @@ static int diagnoseModuleChange(SDKContext &Ctx, SDKNodeRoot *LeftModule,
21922193
BreakageAllowlistPath);
21932194
}
21942195
auto pConsumer = std::make_unique<FilteringDiagnosticConsumer>(
2195-
createDiagConsumer(*OS, FailOnError, CompilerStyleDiags,
2196+
createDiagConsumer(*OS, FailOnError, DisableFailOnError, CompilerStyleDiags,
21962197
SerializedDiagPath),
21972198
std::move(allowedBreakages));
21982199
SWIFT_DEFER { pConsumer->finishProcessing(); };
@@ -2214,6 +2215,7 @@ static int diagnoseModuleChange(SDKContext &Ctx, SDKNodeRoot *LeftModule,
22142215
static int diagnoseModuleChange(StringRef LeftPath, StringRef RightPath,
22152216
StringRef OutputPath, CheckerOptions Opts,
22162217
llvm::StringSet<> ProtocolReqAllowlist,
2218+
bool DisableFailOnError,
22172219
bool CompilerStyleDiags,
22182220
StringRef SerializedDiagPath,
22192221
StringRef BreakageAllowlistPath,
@@ -2233,7 +2235,7 @@ static int diagnoseModuleChange(StringRef LeftPath, StringRef RightPath,
22332235
RightCollector.deSerialize(RightPath);
22342236
return diagnoseModuleChange(
22352237
Ctx, LeftCollector.getSDKRoot(), RightCollector.getSDKRoot(), OutputPath,
2236-
std::move(ProtocolReqAllowlist), CompilerStyleDiags, SerializedDiagPath,
2238+
std::move(ProtocolReqAllowlist), DisableFailOnError, CompilerStyleDiags, SerializedDiagPath,
22372239
BreakageAllowlistPath, DebugMapping);
22382240
}
22392241

@@ -2517,6 +2519,7 @@ class SwiftAPIDigesterInvocation {
25172519
std::vector<std::string> PreferInterfaceForModules;
25182520
std::string ResourceDir;
25192521
std::string ModuleCachePath;
2522+
bool DisableFailOnError;
25202523

25212524
public:
25222525
SwiftAPIDigesterInvocation(const std::string &ExecPath)
@@ -2618,6 +2621,7 @@ class SwiftAPIDigesterInvocation {
26182621
ResourceDir = ParsedArgs.getLastArgValue(OPT_resource_dir).str();
26192622
ModuleCachePath = ParsedArgs.getLastArgValue(OPT_module_cache_path).str();
26202623
DebugMapping = ParsedArgs.hasArg(OPT_debug_mapping);
2624+
DisableFailOnError = ParsedArgs.hasArg(OPT_disable_fail_on_error);
26212625

26222626
CheckerOpts.AvoidLocation = ParsedArgs.hasArg(OPT_avoid_location);
26232627
CheckerOpts.AvoidToolArgs = ParsedArgs.hasArg(OPT_avoid_tool_args);
@@ -2820,21 +2824,21 @@ class SwiftAPIDigesterInvocation {
28202824
case ComparisonInputMode::BothJson: {
28212825
return diagnoseModuleChange(
28222826
SDKJsonPaths[0], SDKJsonPaths[1], OutputFile, CheckerOpts,
2823-
std::move(protocolAllowlist), CompilerStyleDiags,
2827+
std::move(protocolAllowlist), DisableFailOnError, CompilerStyleDiags,
28242828
SerializedDiagPath, BreakageAllowlistPath, DebugMapping);
28252829
}
28262830
case ComparisonInputMode::BaselineJson: {
28272831
SDKContext Ctx(CheckerOpts);
28282832
return diagnoseModuleChange(
28292833
Ctx, getBaselineFromJson(Ctx), getSDKRoot(Ctx, false), OutputFile,
2830-
std::move(protocolAllowlist), CompilerStyleDiags,
2834+
std::move(protocolAllowlist), DisableFailOnError, CompilerStyleDiags,
28312835
SerializedDiagPath, BreakageAllowlistPath, DebugMapping);
28322836
}
28332837
case ComparisonInputMode::BothLoad: {
28342838
SDKContext Ctx(CheckerOpts);
28352839
return diagnoseModuleChange(
28362840
Ctx, getSDKRoot(Ctx, true), getSDKRoot(Ctx, false), OutputFile,
2837-
std::move(protocolAllowlist), CompilerStyleDiags,
2841+
std::move(protocolAllowlist), DisableFailOnError, CompilerStyleDiags,
28382842
SerializedDiagPath, BreakageAllowlistPath, DebugMapping);
28392843
}
28402844
}

0 commit comments

Comments
 (0)