Skip to content

Commit 0f7a9db

Browse files
committed
ABIChecker: add an option to avoid diagnosing about certain given SPI groups
rdar://92032848
1 parent 3be46df commit 0f7a9db

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 {
@@ -415,6 +416,12 @@ class SDKNodeDecl: public SDKNode {
415416
if (isObjc())
416417
return;
417418
}
419+
// Don't emit SPIs if the group name is out-out.
420+
for (auto spi: getSPIGroups()) {
421+
if (Ctx.getOpts().SPIGroupNamesToIgnore.contains(spi)) {
422+
return;
423+
}
424+
}
418425
Ctx.getDiags(Loc).diagnose(Loc, ID, getScreenInfo(), std::move(Args)...);
419426
}
420427
};

include/swift/Option/Options.td

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

1405+
def ignore_spi_groups : Separate<["-", "--"], "ignore-spi-group">,
1406+
Flags<[NoDriverOption, SwiftAPIDigesterOption]>,
1407+
HelpText<"SPI group name to not diagnose about">;
1408+
14051409
def protocol_requirement_allow_list: Separate<["-", "--"], "protocol-requirement-allow-list">,
14061410
Flags<[NoDriverOption, SwiftAPIDigesterOption, ArgumentIsPath]>,
14071411
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)