mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
swift-api-digester: add an action to dump USRs for all decls in a header.
We need this for custom migration like rdar://39992329.
This commit is contained in:
@@ -71,6 +71,7 @@ namespace {
|
||||
DeserializeDiffItems,
|
||||
DeserializeSDK,
|
||||
GenerateNameCorrectionTemplate,
|
||||
FindUsr,
|
||||
};
|
||||
} // end anonymous namespace
|
||||
|
||||
@@ -143,6 +144,9 @@ Action(llvm::cl::desc("Mode:"), llvm::cl::init(ActionType::None),
|
||||
clEnumValN(ActionType::DeserializeSDK,
|
||||
"deserialize-sdk",
|
||||
"Deserialize sdk digester in a JSON file"),
|
||||
clEnumValN(ActionType::FindUsr,
|
||||
"find-usr",
|
||||
"Find USR for decls by given condition"),
|
||||
clEnumValN(ActionType::GenerateNameCorrectionTemplate,
|
||||
"generate-name-correction",
|
||||
"Generate name correction template")));
|
||||
@@ -171,6 +175,10 @@ OutputInJson("json", llvm::cl::desc("Print output in JSON format."));
|
||||
static llvm::cl::opt<bool>
|
||||
AvoidLocation("avoid-location",
|
||||
llvm::cl::desc("Avoid serializing the file paths of SDK nodes."));
|
||||
|
||||
static llvm::cl::opt<std::string>
|
||||
LocationFilter("location",
|
||||
llvm::cl::desc("Filter nodes with the given location."));
|
||||
} // namespace options
|
||||
|
||||
namespace {
|
||||
@@ -4018,6 +4026,34 @@ static int deserializeSDKDump(StringRef dumpPath, StringRef OutputPath) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int findDeclUsr(StringRef dumpPath) {
|
||||
std::error_code EC;
|
||||
if (!fs::exists(dumpPath)) {
|
||||
llvm::errs() << dumpPath << " does not exist\n";
|
||||
return 1;
|
||||
}
|
||||
SDKContext Ctx;
|
||||
SwiftDeclCollector Collector(Ctx);
|
||||
Collector.deSerialize(dumpPath);
|
||||
struct FinderByLocation: SDKNodeVisitor {
|
||||
StringRef Location;
|
||||
FinderByLocation(StringRef Location): Location(Location) {}
|
||||
void visit(SDKNode* Node) override {
|
||||
if (auto *D = dyn_cast<SDKNodeDecl>(Node)) {
|
||||
if (D->getLocation().find(Location) != StringRef::npos &&
|
||||
!D->getUsr().empty()) {
|
||||
llvm::outs() << D->getFullyQualifiedName() << ": " << D->getUsr() << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
if (!options::LocationFilter.empty()) {
|
||||
FinderByLocation Finder(options::LocationFilter);
|
||||
Collector.visitAllRoots(Finder);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
PROGRAM_START(argc, argv);
|
||||
INITIALIZE_LLVM();
|
||||
@@ -4072,6 +4108,13 @@ int main(int argc, char *argv[]) {
|
||||
Store.addStorePath(Paths[I]);
|
||||
return deserializeNameCorrection(Store, options::OutputFile);
|
||||
}
|
||||
case ActionType::FindUsr: {
|
||||
if (options::SDKJsonPaths.size() != 1) {
|
||||
llvm::cl::PrintHelpMessage();
|
||||
return 1;
|
||||
}
|
||||
return findDeclUsr(options::SDKJsonPaths[0]);
|
||||
}
|
||||
case ActionType::None:
|
||||
llvm::errs() << "Action required\n";
|
||||
llvm::cl::PrintHelpMessage();
|
||||
|
||||
Reference in New Issue
Block a user