Skip to content

Commit 307a2f0

Browse files
authored
Merge pull request #29566 from bitjammer/acgarland/rdar-58770554-ssg-arg-polish
swift-symbolgraph-extract: Mark required args
2 parents a7f2878 + 81b4d84 commit 307a2f0

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

tools/driver/swift_symbolgraph_extract_main.cpp

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ namespace options {
3232
static llvm::cl::OptionCategory Category("swift-symbolgraph-extract Options");
3333

3434
static llvm::cl::opt<std::string>
35-
ModuleName("module-name", llvm::cl::desc("Name of the module to extract"), llvm::cl::cat(Category));
35+
ModuleName("module-name", llvm::cl::desc("Name of the module to extract (Required)"), llvm::cl::cat(Category));
3636

3737
static llvm::cl::list<std::string>
38-
FrameworkSearchPaths("F", llvm::cl::desc("add a directory to the framework search paths"), llvm::cl::ZeroOrMore,
38+
FrameworkSearchPaths("F", llvm::cl::desc("Add a directory to the framework search paths"), llvm::cl::ZeroOrMore,
3939
llvm::cl::cat(Category));
4040

4141
static llvm::cl::list<std::string>
@@ -54,7 +54,7 @@ SDK("sdk", llvm::cl::desc("Path to the SDK"),
5454
llvm::cl::cat(Category));
5555

5656
static llvm::cl::opt<std::string>
57-
Target("target", llvm::cl::desc("Target triple"),
57+
Target("target", llvm::cl::desc("Target triple (Required)"),
5858
llvm::cl::cat(Category));
5959

6060
static llvm::cl::opt<std::string>
@@ -67,9 +67,29 @@ static llvm::cl::opt<std::string>
6767
MinimumAccessLevel("minimum-access-level", llvm::cl::desc("Include symbols with this access level or more"), llvm::cl::cat(Category));
6868

6969
static llvm::cl::opt<std::string>
70-
OutputPath("o", llvm::cl::desc("Symbol Graph JSON Output Path"), llvm::cl::cat(Category));
70+
OutputPath("o", llvm::cl::desc("Symbol Graph JSON Output Path (Required)"), llvm::cl::cat(Category));
7171
} // end namespace options
7272

73+
static bool argumentsAreValid() {
74+
bool Valid = true;
75+
if (options::Target.empty()) {
76+
llvm::errs() << "Required -target option is missing\n";
77+
Valid = false;
78+
}
79+
80+
if (options::ModuleName.empty()) {
81+
llvm::errs() << "Required -module-name argument is missing\n";
82+
Valid = false;
83+
}
84+
85+
if (options::OutputPath.empty()) {
86+
llvm::errs() << "Required -o argument is missing\n";
87+
Valid = false;
88+
}
89+
90+
return Valid;
91+
}
92+
7393
int swift_symbolgraph_extract_main(ArrayRef<const char *> Args, const char *Argv0, void *MainAddr) {
7494
INITIALIZE_LLVM();
7595

@@ -79,8 +99,18 @@ int swift_symbolgraph_extract_main(ArrayRef<const char *> Args, const char *Argv
7999
SmallVector<const char *, 8> ArgsWithArgv0 { Argv0 };
80100
ArgsWithArgv0.append(Args.begin(), Args.end());
81101

102+
if (Args.empty()) {
103+
ArgsWithArgv0.push_back("-help");
104+
}
105+
82106
llvm::cl::ParseCommandLineOptions(ArgsWithArgv0.size(),
83-
llvm::makeArrayRef(ArgsWithArgv0).data(), "Swift Symbol Graph Extractor\n");
107+
llvm::makeArrayRef(ArgsWithArgv0).data(),
108+
"Swift Symbol Graph Extractor\n");
109+
110+
if (!argumentsAreValid()) {
111+
llvm::cl::PrintHelpMessage();
112+
return EXIT_FAILURE;
113+
}
84114

85115
CompilerInvocation Invocation;
86116

0 commit comments

Comments
 (0)