Skip to content

Commit 6a65a01

Browse files
committed
ABI/API checker: serialized json format should include all tool invocation arguments
1 parent a2b8826 commit 6a65a01

File tree

6 files changed

+28
-6
lines changed

6 files changed

+28
-6
lines changed

include/swift/IDE/DigesterEnums.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ KEY_STRING(IntrowatchOS, intro_watchOS)
152152
KEY_STRING(Introswift, intro_swift)
153153

154154
KEY_STRING_ARR(SuperclassNames, superclassNames)
155+
KEY_STRING_ARR(ToolArgs, tool_arguments)
155156

156157
KEY_UINT(SelfIndex, selfIndex)
157158
KEY_UINT(FixedBinaryOrder, fixedbinaryorder)

test/api-digester/clang-module-dump.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
// RUN: %empty-directory(%t.mod)
33
// RUN: %empty-directory(%t.sdk)
44
// RUN: %empty-directory(%t.module-cache)
5-
// RUN: %api-digester -dump-sdk -module Foo -o %t.result -module-cache-path %t.module-cache %clang-importer-sdk-nosource -swift-version 4 -I %S/Inputs/Foo -avoid-location
5+
// RUN: %api-digester -dump-sdk -module Foo -o %t.result -module-cache-path %t.module-cache %clang-importer-sdk-nosource -swift-version 4 -I %S/Inputs/Foo -avoid-location -avoid-tool-args
66
// RUN: diff -u %S/Outputs/clang-module-dump.txt %t.result

test/api-digester/dump-module.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// RUN: %empty-directory(%t.sdk)
33
// RUN: %empty-directory(%t.module-cache)
44
// RUN: %swift -emit-module -o %t.mod/cake.swiftmodule %S/Inputs/cake.swift -parse-as-library -I %S/Inputs/ClangCake %clang-importer-sdk-nosource
5-
// RUN: %api-digester -dump-sdk -module cake -o %t.dump.json -module-cache-path %t.module-cache -swift-only -I %t.mod -I %S/Inputs/ClangCake %clang-importer-sdk-nosource
5+
// RUN: %api-digester -dump-sdk -module cake -o %t.dump.json -module-cache-path %t.module-cache -swift-only -I %t.mod -I %S/Inputs/ClangCake %clang-importer-sdk-nosource -avoid-tool-args
66
// RUN: diff -u %S/Outputs/cake.json %t.dump.json
7-
// RUN: %api-digester -dump-sdk -module cake -o %t.dump.json -module-cache-path %t.module-cache -swift-only -I %t.mod -abi -I %S/Inputs/ClangCake %clang-importer-sdk-nosource
7+
// RUN: %api-digester -dump-sdk -module cake -o %t.dump.json -module-cache-path %t.module-cache -swift-only -I %t.mod -abi -I %S/Inputs/ClangCake %clang-importer-sdk-nosource -avoid-tool-args
88
// RUN: diff -u %S/Outputs/cake-abi.json %t.dump.json
99
// RUN: %api-digester -diagnose-sdk --input-paths %t.dump.json -input-paths %S/Outputs/cake.json
1010

tools/swift-api-digester/ModuleAnalyzerNodes.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ void SDKNodeRoot::registerDescendant(SDKNode *D) {
7979
SDKNode::SDKNode(SDKNodeInitInfo Info, SDKNodeKind Kind): Ctx(Info.Ctx),
8080
Name(Info.Name), PrintedName(Info.PrintedName), TheKind(unsigned(Kind)) {}
8181

82-
SDKNodeRoot::SDKNodeRoot(SDKNodeInitInfo Info): SDKNode(Info, SDKNodeKind::Root) {}
82+
SDKNodeRoot::SDKNodeRoot(SDKNodeInitInfo Info): SDKNode(Info, SDKNodeKind::Root),
83+
ToolArgs(Info.ToolArgs) {}
8384

8485
SDKNodeDecl::SDKNodeDecl(SDKNodeInitInfo Info, SDKNodeKind Kind)
8586
: SDKNode(Info, Kind), DKind(Info.DKind), Usr(Info.Usr),
@@ -367,6 +368,7 @@ SDKNode *SDKNodeRoot::getInstance(SDKContext &Ctx) {
367368
SDKNodeInitInfo Info(Ctx);
368369
Info.Name = Ctx.buffer("TopLevel");
369370
Info.PrintedName = Ctx.buffer("TopLevel");
371+
Info.ToolArgs = Ctx.getOpts().ToolArgs;
370372
return Info.createSDKNode(SDKNodeKind::Root);
371373
}
372374

@@ -1829,6 +1831,12 @@ void SDKNode::jsonize(json::Output &out) {
18291831
out.mapOptional(getKeyContent(Ctx, KeyKind::KK_children).data(), Children);
18301832
}
18311833

1834+
void SDKNodeRoot::jsonize(json::Output &out) {
1835+
SDKNode::jsonize(out);
1836+
if (!Ctx.getOpts().AvoidToolArgs)
1837+
out.mapOptional(getKeyContent(Ctx, KeyKind::KK_tool_arguments).data(), ToolArgs);
1838+
}
1839+
18321840
void SDKNodeConformance::jsonize(json::Output &out) {
18331841
SDKNode::jsonize(out);
18341842
output(out, KeyKind::KK_usr, Usr);

tools/swift-api-digester/ModuleAnalyzerNodes.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,15 @@ struct BreakingAttributeInfo {
140140

141141
struct CheckerOptions {
142142
bool AvoidLocation;
143+
bool AvoidToolArgs;
143144
bool ABI;
144145
bool Verbose;
145146
bool AbortOnModuleLoadFailure;
146147
bool PrintModule;
147148
bool SwiftOnly;
148149
bool SkipOSCheck;
149150
StringRef LocationFilter;
151+
std::vector<StringRef> ToolArgs;
150152
};
151153

152154
class SDKContext {
@@ -383,12 +385,15 @@ class SDKNodeDecl: public SDKNode {
383385
class SDKNodeRoot: public SDKNode {
384386
/// This keeps track of all decl descendants with USRs.
385387
llvm::StringMap<llvm::SmallSetVector<SDKNodeDecl*, 2>> DescendantDeclTable;
388+
/// The tool invocation arguments to generate this root node. We shouldn't need APIs for it.
389+
std::vector<StringRef> ToolArgs;
386390

387391
public:
388392
SDKNodeRoot(SDKNodeInitInfo Info);
389393
static SDKNode *getInstance(SDKContext &Ctx);
390394
static bool classof(const SDKNode *N);
391395
void registerDescendant(SDKNode *D);
396+
virtual void jsonize(json::Output &Out) override;
392397
ArrayRef<SDKNodeDecl*> getDescendantsByUsr(StringRef Usr) {
393398
return DescendantDeclTable[Usr].getArrayRef();
394399
}

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ AvoidLocation("avoid-location",
206206
llvm::cl::desc("Avoid serializing the file paths of SDK nodes."),
207207
llvm::cl::cat(Category));
208208

209+
static llvm::cl::opt<bool>
210+
AvoidToolArgs("avoid-tool-args",
211+
llvm::cl::desc("Avoid serializing the arguments for invoking the tool."),
212+
llvm::cl::cat(Category));
213+
209214
static llvm::cl::opt<std::string>
210215
LocationFilter("location",
211216
llvm::cl::desc("Filter nodes with the given location."),
@@ -2443,16 +2448,19 @@ static int deserializeNameCorrection(APIDiffItemStore &Store,
24432448
return EC.value();
24442449
}
24452450

2446-
static CheckerOptions getCheckOpts() {
2451+
static CheckerOptions getCheckOpts(int argc, char *argv[]) {
24472452
CheckerOptions Opts;
24482453
Opts.AvoidLocation = options::AvoidLocation;
2454+
Opts.AvoidToolArgs = options::AvoidToolArgs;
24492455
Opts.ABI = options::Abi;
24502456
Opts.Verbose = options::Verbose;
24512457
Opts.AbortOnModuleLoadFailure = options::AbortOnModuleLoadFailure;
24522458
Opts.LocationFilter = options::LocationFilter;
24532459
Opts.PrintModule = options::PrintModule;
24542460
Opts.SwiftOnly = options::SwiftOnly;
24552461
Opts.SkipOSCheck = options::DisableOSChecks;
2462+
for (int i = 1; i < argc; ++i)
2463+
Opts.ToolArgs.push_back(StringRef(argv[i]));
24562464
return Opts;
24572465
}
24582466

@@ -2482,7 +2490,7 @@ int main(int argc, char *argv[]) {
24822490
std::vector<std::string> PrintApis;
24832491
llvm::StringSet<> IgnoredUsrs;
24842492
readIgnoredUsrs(IgnoredUsrs);
2485-
CheckerOptions Opts = getCheckOpts();
2493+
CheckerOptions Opts = getCheckOpts(argc, argv);
24862494
for (auto Name : options::ApisPrintUsrs)
24872495
PrintApis.push_back(Name);
24882496
switch (options::Action) {

0 commit comments

Comments
 (0)