Skip to content

Commit e1838a3

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-rebranch
2 parents 3a51ce6 + 77ba60f commit e1838a3

File tree

9 files changed

+47
-10
lines changed

9 files changed

+47
-10
lines changed

include/swift/IDE/DigesterEnums.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,11 @@ 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)
159+
KEY_UINT(JsonFormatVer, json_format_version)
158160

159161
KEY(children)
160162
KEY(conformances)

test/api-digester/Outputs/cake-abi.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1753,5 +1753,6 @@
17531753
}
17541754
]
17551755
}
1756-
]
1756+
],
1757+
"json_format_version": 1
17571758
}

test/api-digester/Outputs/cake.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1621,5 +1621,6 @@
16211621
}
16221622
]
16231623
}
1624-
]
1624+
],
1625+
"json_format_version": 1
16251626
}

test/api-digester/Outputs/clang-module-dump.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,5 +168,6 @@
168168
"ObjC"
169169
]
170170
}
171-
]
171+
],
172+
"json_format_version": 1
172173
}

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: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ 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),
84+
JsonFormatVer(Info.JsonFormatVer.hasValue() ? *Info.JsonFormatVer : DIGESTER_JSON_DEFAULT_VERSION) {}
8385

8486
SDKNodeDecl::SDKNodeDecl(SDKNodeInitInfo Info, SDKNodeKind Kind)
8587
: SDKNode(Info, Kind), DKind(Info.DKind), Usr(Info.Usr),
@@ -367,6 +369,8 @@ SDKNode *SDKNodeRoot::getInstance(SDKContext &Ctx) {
367369
SDKNodeInitInfo Info(Ctx);
368370
Info.Name = Ctx.buffer("TopLevel");
369371
Info.PrintedName = Ctx.buffer("TopLevel");
372+
Info.ToolArgs = Ctx.getOpts().ToolArgs;
373+
Info.JsonFormatVer = DIGESTER_JSON_VERSION;
370374
return Info.createSDKNode(SDKNodeKind::Root);
371375
}
372376

@@ -1834,6 +1838,13 @@ void SDKNode::jsonize(json::Output &out) {
18341838
out.mapOptional(getKeyContent(Ctx, KeyKind::KK_children).data(), Children);
18351839
}
18361840

1841+
void SDKNodeRoot::jsonize(json::Output &out) {
1842+
SDKNode::jsonize(out);
1843+
out.mapRequired(getKeyContent(Ctx, KeyKind::KK_json_format_version).data(), JsonFormatVer);
1844+
if (!Ctx.getOpts().AvoidToolArgs)
1845+
out.mapOptional(getKeyContent(Ctx, KeyKind::KK_tool_arguments).data(), ToolArgs);
1846+
}
1847+
18371848
void SDKNodeConformance::jsonize(json::Output &out) {
18381849
SDKNode::jsonize(out);
18391850
output(out, KeyKind::KK_usr, Usr);

tools/swift-api-digester/ModuleAnalyzerNodes.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ class Output;
5858
namespace ide {
5959
namespace api {
6060

61+
/// Serialized json format version number.
62+
///
63+
/// When the json format changes in a way that requires version-specific handling, this number should be incremented.
64+
/// This ensures we could have backward compatibility so that version changes in the format won't stop the checker from working.
65+
const uint8_t DIGESTER_JSON_VERSION = 1; // Adding digester_version to the format
66+
const uint8_t DIGESTER_JSON_DEFAULT_VERSION = 0; // Use this version number for files before we have a version number in json.
67+
6168
class SDKNode;
6269
typedef SDKNode* NodePtr;
6370
typedef std::map<NodePtr, NodePtr> ParentMap;
@@ -140,13 +147,15 @@ struct BreakingAttributeInfo {
140147

141148
struct CheckerOptions {
142149
bool AvoidLocation;
150+
bool AvoidToolArgs;
143151
bool ABI;
144152
bool Verbose;
145153
bool AbortOnModuleLoadFailure;
146154
bool PrintModule;
147155
bool SwiftOnly;
148156
bool SkipOSCheck;
149157
StringRef LocationFilter;
158+
std::vector<StringRef> ToolArgs;
150159
};
151160

152161
class SDKContext {
@@ -383,12 +392,16 @@ class SDKNodeDecl: public SDKNode {
383392
class SDKNodeRoot: public SDKNode {
384393
/// This keeps track of all decl descendants with USRs.
385394
llvm::StringMap<llvm::SmallSetVector<SDKNodeDecl*, 2>> DescendantDeclTable;
386-
395+
/// The tool invocation arguments to generate this root node. We shouldn't need APIs for it.
396+
std::vector<StringRef> ToolArgs;
397+
uint8_t JsonFormatVer;
387398
public:
388399
SDKNodeRoot(SDKNodeInitInfo Info);
389400
static SDKNode *getInstance(SDKContext &Ctx);
390401
static bool classof(const SDKNode *N);
391402
void registerDescendant(SDKNode *D);
403+
virtual void jsonize(json::Output &Out) override;
404+
Optional<uint8_t> getJsonFormatVersion() const { return JsonFormatVer; }
392405
ArrayRef<SDKNodeDecl*> getDescendantsByUsr(StringRef Usr) {
393406
return DescendantDeclTable[Usr].getArrayRef();
394407
}

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)