Skip to content

Commit dfb5321

Browse files
committed
ABIChecker: add an option to avoid diagnosing about certain given SPI groups
rdar://92032848
1 parent 0567a9b commit dfb5321

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

include/swift/APIDigester/ModuleAnalyzerNodes.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ struct CheckerOptions {
161161
bool Migrator;
162162
StringRef LocationFilter;
163163
std::vector<std::string> ToolArgs;
164+
llvm::StringSet<> SPIGroupNamesToIgnore;
164165
};
165166

166167
class SDKContext {
@@ -417,6 +418,12 @@ class SDKNodeDecl: public SDKNode {
417418
if (isObjc())
418419
return;
419420
}
421+
// Don't emit SPIs if the group name is out-out.
422+
for (auto spi: getSPIGroups()) {
423+
if (Ctx.getOpts().SPIGroupNamesToIgnore.contains(spi)) {
424+
return;
425+
}
426+
}
420427
Ctx.getDiags(Loc).diagnose(Loc, ID, getScreenInfo(), std::move(Args)...);
421428
}
422429
};

include/swift/Option/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,10 @@ def ignored_usrs: Separate<["-", "--"], "ignored-usrs">,
13991399
HelpText<"the file containing USRs of removed decls that the digester should ignore">,
14001400
MetaVarName<"<path>">;
14011401

1402+
def ignore_spi_groups : Separate<["-", "--"], "ignore-spi-group">,
1403+
Flags<[NoDriverOption, SwiftAPIDigesterOption]>,
1404+
HelpText<"SPI group name to not diagnose about">;
1405+
14021406
def protocol_requirement_allow_list: Separate<["-", "--"], "protocol-requirement-allow-list">,
14031407
Flags<[NoDriverOption, SwiftAPIDigesterOption, ArgumentIsPath]>,
14041408
HelpText<"File containing a new-line separated list of protocol names">,

lib/DriverTool/swift_api_digester_main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2338,7 +2338,8 @@ class SwiftAPIDigesterInvocation {
23382338
CompilerStyleDiags || !SerializedDiagPath.empty();
23392339
for (auto Arg : Args)
23402340
CheckerOpts.ToolArgs.push_back(Arg);
2341-
2341+
for(auto spi: ParsedArgs.getAllArgValues(OPT_ignore_spi_groups))
2342+
CheckerOpts.SPIGroupNamesToIgnore.insert(spi);
23422343
if (!SDK.empty()) {
23432344
auto Ver = getSDKBuildVersion(SDK);
23442345
if (!Ver.empty()) {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-swift-frontend -emit-module -o %t/Foo.swiftmodule -emit-abi-descriptor-path %t/abi-before.json %s -enable-library-evolution -DBASELINE -emit-tbd-path %t/abi-before.tbd
4+
// RUN: %target-swift-frontend -emit-module -o %t/Foo.swiftmodule -emit-abi-descriptor-path %t/abi-after.json %s -enable-library-evolution -emit-tbd-path %t/abi-after.tbd
5+
// RUN: %api-digester -diagnose-sdk --input-paths %t/abi-before.json -input-paths %t/abi-after.json -abi -o %t/result.txt
6+
// RUN: %FileCheck %s -check-prefix CHECK_INCLUDE_SPI < %t/result.txt
7+
8+
// RUN: %api-digester -diagnose-sdk --input-paths %t/abi-before.json -input-paths %t/abi-after.json -abi -o %t/result.txt -ignore-spi-group secret
9+
// RUN: %FileCheck -check-prefix CHECK_EXCLUDE_SPI %s < %t/result.txt
10+
11+
#if BASELINE
12+
13+
@_spi(secret)
14+
public func foo() {}
15+
16+
#else
17+
18+
19+
#endif
20+
21+
// CHECK_INCLUDE_SPI: Func foo() has been removed
22+
// CHECK_EXCLUDE_SPI-NOT: foo()

0 commit comments

Comments
 (0)