@@ -63,6 +63,10 @@ static llvm::cl::opt<std::string>
63
63
ModuleList (" module-list-file" ,
64
64
llvm::cl::desc (" File containing a new-line separated list of modules" ));
65
65
66
+ static llvm::cl::opt<std::string>
67
+ ProtReqWhiteList (" protocol-requirement-white-list" ,
68
+ llvm::cl::desc (" File containing a new-line separated list of protocol names" ));
69
+
66
70
static llvm::cl::opt<std::string>
67
71
OutputFile (" o" , llvm::cl::desc(" Output file" ));
68
72
@@ -927,6 +931,7 @@ class PrunePass : public MatchedNodeListener, public SDKTreeDiffPass {
927
931
928
932
SDKContext &Ctx;
929
933
UpdatedNodesMap &UpdateMap;
934
+ llvm::StringSet<> ProtocolReqWhitelist;
930
935
931
936
static void printSpaces (llvm::raw_ostream &OS, SDKNode *N) {
932
937
assert (N);
@@ -959,6 +964,10 @@ class PrunePass : public MatchedNodeListener, public SDKTreeDiffPass {
959
964
960
965
public:
961
966
PrunePass (SDKContext &Ctx): Ctx(Ctx), UpdateMap(Ctx.getNodeUpdateMap()) {}
967
+ PrunePass (SDKContext &Ctx, llvm::StringSet<> prWhitelist):
968
+ Ctx (Ctx),
969
+ UpdateMap (Ctx.getNodeUpdateMap()),
970
+ ProtocolReqWhitelist (std::move(prWhitelist)) {}
962
971
963
972
void foundMatch (NodePtr Left, NodePtr Right, NodeMatchReason Reason) override {
964
973
if (options::Verbose)
@@ -985,6 +994,12 @@ class PrunePass : public MatchedNodeListener, public SDKTreeDiffPass {
985
994
if (ATD->getDefault ())
986
995
ShouldComplain = false ;
987
996
}
997
+ if (ShouldComplain &&
998
+ ProtocolReqWhitelist.count (D->getParent ()->getAs <SDKNodeDecl>()->getFullyQualifiedName ())) {
999
+ // Ignore protocol requirement additions if the protocol has been added
1000
+ // to the whitelist.
1001
+ ShouldComplain = false ;
1002
+ }
988
1003
if (ShouldComplain)
989
1004
Ctx.getDiags ().diagnose (SourceLoc (), diag::protocol_req_added,
990
1005
D->getScreenInfo ());
@@ -2027,7 +2042,8 @@ static void findTypeMemberDiffs(NodePtr leftSDKRoot, NodePtr rightSDKRoot,
2027
2042
2028
2043
static int diagnoseModuleChange (StringRef LeftPath, StringRef RightPath,
2029
2044
StringRef OutputPath,
2030
- CheckerOptions Opts) {
2045
+ CheckerOptions Opts,
2046
+ llvm::StringSet<> ProtocolReqWhitelist) {
2031
2047
if (!fs::exists (LeftPath)) {
2032
2048
llvm::errs () << LeftPath << " does not exist\n " ;
2033
2049
return 1 ;
@@ -2055,7 +2071,7 @@ static int diagnoseModuleChange(StringRef LeftPath, StringRef RightPath,
2055
2071
auto RightModule = RightCollector.getSDKRoot ();
2056
2072
TypeAliasDiffFinder (LeftModule, RightModule,
2057
2073
Ctx.getTypeAliasUpdateMap ()).search ();
2058
- PrunePass Prune (Ctx);
2074
+ PrunePass Prune (Ctx, std::move (ProtocolReqWhitelist) );
2059
2075
Prune.pass (LeftModule, RightModule);
2060
2076
ChangeRefinementPass RefinementPass (Ctx.getNodeUpdateMap ());
2061
2077
RefinementPass.pass (LeftModule, RightModule);
@@ -2182,7 +2198,7 @@ static int compareSDKs(StringRef LeftPath, StringRef RightPath,
2182
2198
static int readFileLineByLine (StringRef Path, llvm::StringSet<> &Lines) {
2183
2199
auto FileBufOrErr = llvm::MemoryBuffer::getFile (Path);
2184
2200
if (!FileBufOrErr) {
2185
- llvm::errs () << " error opening file: "
2201
+ llvm::errs () << " error opening file ' " << Path << " ' : "
2186
2202
<< FileBufOrErr.getError ().message () << ' \n ' ;
2187
2203
return 1 ;
2188
2204
}
@@ -2192,8 +2208,11 @@ static int readFileLineByLine(StringRef Path, llvm::StringSet<> &Lines) {
2192
2208
StringRef Line;
2193
2209
std::tie (Line, BufferText) = BufferText.split (' \n ' );
2194
2210
Line = Line.trim ();
2195
- if (!Line.empty ())
2196
- Lines.insert (Line);
2211
+ if (Line.empty ())
2212
+ continue ;
2213
+ if (Line.startswith (" // " )) // comment.
2214
+ continue ;
2215
+ Lines.insert (Line);
2197
2216
}
2198
2217
return 0 ;
2199
2218
}
@@ -2347,19 +2366,26 @@ int main(int argc, char *argv[]) {
2347
2366
return (prepareForDump (argv[0 ], InitInvok, Modules)) ? 1 :
2348
2367
dumpSDKContent (InitInvok, Modules, options::OutputFile, Opts);
2349
2368
case ActionType::CompareSDKs:
2350
- case ActionType::DiagnoseSDKs:
2369
+ case ActionType::DiagnoseSDKs: {
2351
2370
if (options::SDKJsonPaths.size () != 2 ) {
2352
2371
llvm::errs () << " Only two SDK versions can be compared\n " ;
2353
2372
llvm::cl::PrintHelpMessage ();
2354
2373
return 1 ;
2355
2374
}
2375
+ llvm::StringSet<> protocolWhitelist;
2376
+ if (!options::ProtReqWhiteList.empty ()) {
2377
+ if (readFileLineByLine (options::ProtReqWhiteList, protocolWhitelist))
2378
+ return 1 ;
2379
+ }
2356
2380
if (options::Action == ActionType::CompareSDKs)
2357
2381
return compareSDKs (options::SDKJsonPaths[0 ], options::SDKJsonPaths[1 ],
2358
2382
options::OutputFile, IgnoredUsrs, Opts);
2359
2383
else
2360
2384
return diagnoseModuleChange (options::SDKJsonPaths[0 ],
2361
2385
options::SDKJsonPaths[1 ],
2362
- options::OutputFile, Opts);
2386
+ options::OutputFile, Opts,
2387
+ std::move (protocolWhitelist));
2388
+ }
2363
2389
case ActionType::DeserializeSDK:
2364
2390
case ActionType::DeserializeDiffItems: {
2365
2391
if (options::SDKJsonPaths.size () != 1 ) {
0 commit comments