Skip to content

Commit 288d3df

Browse files
committed
Begin refactoring API digester tool to use a SwiftAPIDigesterInvocation object for option parsing and config
1 parent 09c7f7c commit 288d3df

File tree

1 file changed

+57
-37
lines changed

1 file changed

+57
-37
lines changed

tools/driver/swift_api_digester_main.cpp

Lines changed: 57 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2852,44 +2852,44 @@ static std::string getJsonOutputFilePath(llvm::Triple Triple, bool ABI) {
28522852
exit(1);
28532853
}
28542854

2855-
int swift_api_digester_main(ArrayRef<const char *> Args, const char *Argv0,
2856-
void *MainAddr) {
2857-
INITIALIZE_LLVM();
2858-
2859-
// LLVM Command Line parsing expects to trim off argv[0].
2860-
SmallVector<const char *, 8> ArgsWithArgv0{Argv0};
2861-
ArgsWithArgv0.append(Args.begin(), Args.end());
2862-
2863-
std::string MainExecutablePath = fs::getMainExecutable(Argv0, MainAddr);
2864-
2865-
llvm::cl::HideUnrelatedOptions(options::Category);
2866-
llvm::cl::ParseCommandLineOptions(ArgsWithArgv0.size(),
2867-
llvm::makeArrayRef(ArgsWithArgv0).data(),
2868-
"Swift SDK Digester\n");
2869-
CompilerInvocation InitInvok;
2855+
class SwiftAPIDigesterInvocation {
2856+
private:
2857+
std::string MainExecutablePath;
28702858

2871-
llvm::StringSet<> Modules;
2872-
std::vector<std::string> PrintApis;
2873-
llvm::StringSet<> IgnoredUsrs;
2874-
readIgnoredUsrs(IgnoredUsrs);
2875-
CheckerOptions Opts = getCheckOpts(Args);
2876-
for (auto Name : options::ApisPrintUsrs)
2877-
PrintApis.push_back(Name);
2878-
switch (options::Action) {
2879-
case ActionType::DumpSDK:
2880-
return (prepareForDump(MainExecutablePath, InitInvok, Modules))
2881-
? 1
2882-
: dumpSDKContent(
2883-
InitInvok, Modules,
2884-
getJsonOutputFilePath(InitInvok.getLangOptions().Target,
2885-
Opts.ABI),
2886-
Opts);
2887-
case ActionType::MigratorGen:
2888-
case ActionType::DiagnoseSDKs: {
2889-
ComparisonInputMode Mode = checkComparisonInputMode();
2890-
llvm::StringSet<> protocolAllowlist;
2891-
if (!options::ProtReqAllowList.empty()) {
2892-
if (readFileLineByLine(options::ProtReqAllowList, protocolAllowlist))
2859+
public:
2860+
SwiftAPIDigesterInvocation(const std::string &ExecPath)
2861+
: MainExecutablePath(ExecPath) {}
2862+
2863+
int parseArgs(ArrayRef<const char *> Args) { return 0; }
2864+
2865+
int run(ArrayRef<const char *> Args) {
2866+
llvm::cl::HideUnrelatedOptions(options::Category);
2867+
llvm::cl::ParseCommandLineOptions(
2868+
Args.size(), llvm::makeArrayRef(Args).data(), "Swift SDK Digester\n");
2869+
CompilerInvocation InitInvok;
2870+
2871+
llvm::StringSet<> Modules;
2872+
std::vector<std::string> PrintApis;
2873+
llvm::StringSet<> IgnoredUsrs;
2874+
readIgnoredUsrs(IgnoredUsrs);
2875+
CheckerOptions Opts = getCheckOpts(Args);
2876+
for (auto Name : options::ApisPrintUsrs)
2877+
PrintApis.push_back(Name);
2878+
switch (options::Action) {
2879+
case ActionType::DumpSDK:
2880+
return (prepareForDump(MainExecutablePath, InitInvok, Modules))
2881+
? 1
2882+
: dumpSDKContent(
2883+
InitInvok, Modules,
2884+
getJsonOutputFilePath(InitInvok.getLangOptions().Target,
2885+
Opts.ABI),
2886+
Opts);
2887+
case ActionType::MigratorGen:
2888+
case ActionType::DiagnoseSDKs: {
2889+
ComparisonInputMode Mode = checkComparisonInputMode();
2890+
llvm::StringSet<> protocolAllowlist;
2891+
if (!options::ProtReqAllowList.empty()) {
2892+
if (readFileLineByLine(options::ProtReqAllowList, protocolAllowlist))
28932893
return 1;
28942894
}
28952895
if (options::Action == ActionType::MigratorGen) {
@@ -2962,4 +2962,24 @@ int swift_api_digester_main(ArrayRef<const char *> Args, const char *Argv0,
29622962
llvm::cl::PrintHelpMessage();
29632963
return 1;
29642964
}
2965+
}
2966+
};
2967+
2968+
int swift_api_digester_main(ArrayRef<const char *> Args, const char *Argv0,
2969+
void *MainAddr) {
2970+
INITIALIZE_LLVM();
2971+
2972+
// LLVM Command Line parsing expects to trim off argv[0].
2973+
SmallVector<const char *, 8> ArgsWithArgv0{Argv0};
2974+
ArgsWithArgv0.append(Args.begin(), Args.end());
2975+
2976+
std::string MainExecutablePath = fs::getMainExecutable(Argv0, MainAddr);
2977+
SwiftAPIDigesterInvocation Invocation(MainExecutablePath);
2978+
if (Invocation.parseArgs(ArgsWithArgv0) != 0)
2979+
return EXIT_FAILURE;
2980+
2981+
if (Invocation.run(ArgsWithArgv0) != 0)
2982+
return EXIT_FAILURE;
2983+
2984+
return EXIT_SUCCESS;
29652985
}

0 commit comments

Comments
 (0)