Skip to content

Commit 318e1b9

Browse files
committed
Port swift-symbolgraph extract argument parsing from llvm::cl to llvm::opt
1 parent da37637 commit 318e1b9

File tree

5 files changed

+159
-158
lines changed

5 files changed

+159
-158
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,11 @@ REMARK(interface_file_lock_failure,none,
394394
REMARK(interface_file_lock_timed_out,none,
395395
"timed out waiting to acquire lock file for module interface '%0'", (StringRef))
396396

397+
ERROR(error_option_required,none, "option '%0' is required", (StringRef))
398+
ERROR(error_nonexistent_output_dir,none,
399+
"'-output-dir' argument '%0' does not exist or is not a directory", (StringRef))
400+
401+
397402
// Dependency Verifier Diagnostics
398403
ERROR(missing_member_dependency,none,
399404
"expected "

include/swift/Option/Options.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ namespace options {
3838
ModuleInterfaceOption = (1 << 13),
3939
SupplementaryOutput = (1 << 14),
4040
SwiftAPIExtractOption = (1 << 15),
41+
SwiftSymbolGraphExtractOption = (1 << 16),
4142
};
4243

4344
enum ID {
4445
OPT_INVALID = 0, // This is not an option ID.
4546
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
4647
HELPTEXT, METAVAR, VALUES) \
47-
OPT_##ID,
48+
OPT_##ID,
4849
#include "swift/Option/Options.inc"
4950
LastOption
5051
#undef OPTION

include/swift/Option/Options.td

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ def SupplementaryOutput : OptionFlag;
5858
// The option should be accepted by swift-api-extract.
5959
def SwiftAPIExtractOption : OptionFlag;
6060

61+
// The option should be accepted by swift-symbolgraph-extract.
62+
def SwiftSymbolGraphExtractOption : OptionFlag;
63+
6164
/////////
6265
// Options
6366

@@ -173,7 +176,8 @@ def driver_mode : Joined<["--"], "driver-mode=">, Flags<[HelpHidden]>,
173176

174177
def help : Flag<["-", "--"], "help">,
175178
Flags<[FrontendOption, AutolinkExtractOption, ModuleWrapOption,
176-
SwiftIndentOption, SwiftAPIExtractOption]>,
179+
SwiftIndentOption, SwiftAPIExtractOption,
180+
SwiftSymbolGraphExtractOption]>,
177181
HelpText<"Display available options">;
178182
def h : Flag<["-"], "h">, Alias<help>;
179183
def help_hidden : Flag<["-", "--"], "help-hidden">,
@@ -202,10 +206,12 @@ def o : JoinedOrSeparate<["-"], "o">,
202206
def j : JoinedOrSeparate<["-"], "j">, Flags<[DoesNotAffectIncrementalBuild]>,
203207
HelpText<"Number of commands to execute in parallel">, MetaVarName<"<n>">;
204208

205-
def sdk : Separate<["-"], "sdk">, Flags<[FrontendOption, ArgumentIsPath, SwiftAPIExtractOption]>,
209+
def sdk : Separate<["-"], "sdk">,
210+
Flags<[FrontendOption, ArgumentIsPath, SwiftAPIExtractOption, SwiftSymbolGraphExtractOption]>,
206211
HelpText<"Compile against <sdk>">, MetaVarName<"<sdk>">;
207212

208-
def swift_version : Separate<["-"], "swift-version">, Flags<[FrontendOption, ModuleInterfaceOption, SwiftAPIExtractOption]>,
213+
def swift_version : Separate<["-"], "swift-version">,
214+
Flags<[FrontendOption, ModuleInterfaceOption, SwiftAPIExtractOption, SwiftSymbolGraphExtractOption]>,
209215
HelpText<"Interpret input according to a specific Swift language version number">,
210216
MetaVarName<"<vers>">;
211217

@@ -222,16 +228,18 @@ def tools_directory : Separate<["-"], "tools-directory">,
222228
def D : JoinedOrSeparate<["-"], "D">, Flags<[FrontendOption]>,
223229
HelpText<"Marks a conditional compilation flag as true">;
224230

225-
def F : JoinedOrSeparate<["-"], "F">, Flags<[FrontendOption, ArgumentIsPath, SwiftAPIExtractOption]>,
231+
def F : JoinedOrSeparate<["-"], "F">,
232+
Flags<[FrontendOption, ArgumentIsPath, SwiftAPIExtractOption, SwiftSymbolGraphExtractOption]>,
226233
HelpText<"Add directory to framework search path">;
227234
def F_EQ : Joined<["-"], "F=">, Flags<[FrontendOption, ArgumentIsPath]>,
228235
Alias<F>;
229236

230237
def Fsystem : Separate<["-"], "Fsystem">,
231-
Flags<[FrontendOption, ArgumentIsPath, SwiftAPIExtractOption]>,
238+
Flags<[FrontendOption, ArgumentIsPath, SwiftAPIExtractOption, SwiftSymbolGraphExtractOption]>,
232239
HelpText<"Add directory to system framework search path">;
233240

234-
def I : JoinedOrSeparate<["-"], "I">, Flags<[FrontendOption, ArgumentIsPath, SwiftAPIExtractOption]>,
241+
def I : JoinedOrSeparate<["-"], "I">,
242+
Flags<[FrontendOption, ArgumentIsPath, SwiftAPIExtractOption, SwiftSymbolGraphExtractOption]>,
235243
HelpText<"Add directory to the import search path">;
236244
def I_EQ : Joined<["-"], "I=">, Flags<[FrontendOption, ArgumentIsPath]>,
237245
Alias<I>;
@@ -377,7 +385,8 @@ def localization_path : Separate<["-"], "localization-path">,
377385
MetaVarName<"<path>">;
378386

379387
def module_cache_path : Separate<["-"], "module-cache-path">,
380-
Flags<[FrontendOption, DoesNotAffectIncrementalBuild, ArgumentIsPath, SwiftAPIExtractOption]>,
388+
Flags<[FrontendOption, DoesNotAffectIncrementalBuild, ArgumentIsPath, SwiftAPIExtractOption,
389+
SwiftSymbolGraphExtractOption]>,
381390
HelpText<"Specifies the Clang module cache path">;
382391

383392
def enable_library_evolution : Flag<["-"], "enable-library-evolution">,
@@ -398,7 +407,8 @@ def define_availability : Separate<["-"], "define-availability">,
398407
MetaVarName<"<macro>">;
399408

400409
def module_name : Separate<["-"], "module-name">,
401-
Flags<[FrontendOption, ModuleInterfaceOption, SwiftAPIExtractOption]>,
410+
Flags<[FrontendOption, ModuleInterfaceOption, SwiftAPIExtractOption,
411+
SwiftSymbolGraphExtractOption]>,
402412
HelpText<"Name of the module to build">;
403413
def module_name_EQ : Joined<["-"], "module-name=">, Flags<[FrontendOption]>,
404414
Alias<module_name>;
@@ -667,7 +677,8 @@ def framework : Separate<["-"], "framework">, Group<linker_option_Group>,
667677
HelpText<"Specifies a framework which should be linked against">;
668678

669679
def L : JoinedOrSeparate<["-"], "L">, Group<linker_option_Group>,
670-
Flags<[FrontendOption, DoesNotAffectIncrementalBuild, ArgumentIsPath, SwiftAPIExtractOption]>,
680+
Flags<[FrontendOption, DoesNotAffectIncrementalBuild, ArgumentIsPath, SwiftAPIExtractOption,
681+
SwiftSymbolGraphExtractOption]>,
671682
HelpText<"Add directory to library link search path">;
672683
def L_EQ : Joined<["-"], "L=">, Group<linker_option_Group>,
673684
Flags<[FrontendOption, DoesNotAffectIncrementalBuild, ArgumentIsPath]>,
@@ -1014,7 +1025,7 @@ def num_threads : Separate<["-"], "num-threads">,
10141025
def Xfrontend : Separate<["-"], "Xfrontend">, Flags<[HelpHidden]>,
10151026
MetaVarName<"<arg>">, HelpText<"Pass <arg> to the Swift frontend">;
10161027

1017-
def Xcc : Separate<["-"], "Xcc">, Flags<[FrontendOption]>,
1028+
def Xcc : Separate<["-"], "Xcc">, Flags<[FrontendOption, SwiftSymbolGraphExtractOption]>,
10181029
MetaVarName<"<arg>">,
10191030
HelpText<"Pass <arg> to the C/C++/Objective-C compiler">;
10201031

@@ -1026,12 +1037,12 @@ def Xllvm : Separate<["-"], "Xllvm">,
10261037
MetaVarName<"<arg>">, HelpText<"Pass <arg> to LLVM.">;
10271038

10281039
def resource_dir : Separate<["-"], "resource-dir">,
1029-
Flags<[FrontendOption, HelpHidden, ArgumentIsPath]>,
1040+
Flags<[FrontendOption, SwiftSymbolGraphExtractOption, HelpHidden, ArgumentIsPath]>,
10301041
MetaVarName<"</usr/lib/swift>">,
10311042
HelpText<"The directory that holds the compiler resource files">;
10321043

10331044
def target : Separate<["-"], "target">,
1034-
Flags<[FrontendOption, ModuleWrapOption, ModuleInterfaceOption, SwiftAPIExtractOption]>,
1045+
Flags<[FrontendOption, ModuleWrapOption, ModuleInterfaceOption, SwiftAPIExtractOption, SwiftSymbolGraphExtractOption]>,
10351046
HelpText<"Generate code for the given target <triple>, such as x86_64-apple-macos10.9">, MetaVarName<"<triple>">;
10361047
def target_legacy_spelling : Joined<["--"], "target=">,
10371048
Flags<[FrontendOption]>, Alias<target>;
@@ -1187,8 +1198,23 @@ def emit_symbol_graph_dir : Separate<["-"], "emit-symbol-graph-dir">,
11871198
HelpText<"Emit a symbol graph to directory <dir>">,
11881199
MetaVarName<"<dir>">;
11891200

1190-
// Swift API Extraction only options
1191-
def pretty_print: Flag<["-"], "pretty-print">, Flags<[SwiftAPIExtractOption]>,
1201+
def pretty_print: Flag<["-"], "pretty-print">,
1202+
Flags<[SwiftAPIExtractOption, SwiftSymbolGraphExtractOption]>,
11921203
HelpText<"Pretty-print the output JSON">;
11931204

1205+
// swift-symbolgraph-extract-only options
1206+
def output_dir : Separate<["-"], "output-dir">,
1207+
Flags<[NoDriverOption, SwiftSymbolGraphExtractOption, ArgumentIsPath]>,
1208+
HelpText<"Symbol Graph JSON Output Directory (Required)">,
1209+
MetaVarName<"<dir>">;
1210+
1211+
def skip_synthesized_members: Flag<[ "-" ], "skip-synthesized-members">,
1212+
Flags<[NoDriverOption, SwiftSymbolGraphExtractOption]>,
1213+
HelpText<"Skip members inherited through classes or default implementations">;
1214+
1215+
def minimum_access_level : Separate<["-"], "minimum-access-level">,
1216+
Flags<[NoDriverOption, SwiftSymbolGraphExtractOption]>,
1217+
HelpText<"Include symbols with this access level or more">,
1218+
MetaVarName<"<level>">;
1219+
11941220
include "FrontendOptions.td"

test/SILOptimizer/lazy_property_getters.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// Also do an end-to-end test to check if the generated code is correct.
44
// RUN: %empty-directory(%t)
5-
// RUN: %target-build-swift -O -Xllvm -module-name=test %s -o %t/a.out
5+
// RUN: %target-build-swift -O -module-name=test %s -o %t/a.out
66
// RUN: %target-codesign %t/a.out
77
// RUN: %target-run %t/a.out | %FileCheck %s -check-prefix=CHECK-OUTPUT
88
// REQUIRES: executable_test

0 commit comments

Comments
 (0)