Skip to content

Commit e01f234

Browse files
authored
Merge pull request #68994 from tshortli/api-extract-supplementary-output
TBDGen: Introduce option to emit API descriptor as supplementary output
2 parents 37f5b43 + 778532d commit e01f234

24 files changed

+428
-142
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ ERROR(error_mode_cannot_emit_module_summary,none,
152152
ERROR(error_mode_cannot_emit_symbol_graph,none,
153153
"this mode does not support emitting symbol graph files", ())
154154
ERROR(error_mode_cannot_emit_abi_descriptor,none,
155-
"this mode does not support emitting ABI descriptor", ())
155+
"this mode does not support emitting ABI descriptor files", ())
156+
ERROR(error_mode_cannot_emit_api_descriptor,none,
157+
"this mode does not support emitting API descriptor files", ())
156158
ERROR(error_mode_cannot_emit_const_values,none,
157159
"this mode does not support emitting extracted const values", ())
158160
ERROR(error_mode_cannot_emit_module_semantic_info,none,
@@ -313,6 +315,10 @@ ERROR(tbd_not_supported_with_cmo,none,
313315
"Test-Based InstallAPI (TBD) is not support with cross-module-optimization",
314316
())
315317

318+
WARNING(api_descriptor_only_supported_in_whole_module,none,
319+
"API descriptor generation is only supported when the whole module can be seen",
320+
())
321+
316322
ERROR(previous_installname_map_missing,none,
317323
"cannot open previous install name map from %0",
318324
(StringRef))

include/swift/Basic/FileTypes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ TYPE("pch", PCH, "pch", "")
9898
TYPE("none", Nothing, "", "")
9999

100100
TYPE("abi-baseline-json", SwiftABIDescriptor, "abi.json", "")
101+
TYPE("api-json", SwiftAPIDescriptor, "", "")
101102
TYPE("fixit", SwiftFixIt, "", "")
102103
TYPE("module-semantic-info", ModuleSemanticInfo, "", "")
103104
TYPE("cached-diagnostics", CachedDiagnostics, "", "")

include/swift/Basic/SupplementaryOutputPaths.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ OUTPUT(ModuleSummaryOutputPath, TY_SwiftModuleSummaryFile)
143143
/// The output path to generate ABI baseline.
144144
OUTPUT(ABIDescriptorOutputPath, TY_SwiftABIDescriptor)
145145

146+
/// The output path to the module's API description.
147+
OUTPUT(APIDescriptorOutputPath, TY_SwiftAPIDescriptor)
148+
146149
/// The output path for extracted compile-time-known value information
147150
OUTPUT(ConstValuesOutputPath, TY_ConstValues)
148151

include/swift/Frontend/Frontend.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,11 @@ class CompilerInvocation {
428428
std::string getModuleInterfaceOutputPathForWholeModule() const;
429429
std::string getPrivateModuleInterfaceOutputPathForWholeModule() const;
430430

431+
/// APIDescriptorPath only makes sense in whole module compilation mode,
432+
/// so return the APIDescriptorPath when in that mode and fail an assert
433+
/// if not in that mode.
434+
std::string getAPIDescriptorPathForWholeModule() const;
435+
431436
public:
432437
/// Given the current configuration of this frontend invocation, a set of
433438
/// supplementary output paths, and a module, compute the appropriate set of

include/swift/Frontend/FrontendInputsAndOutputs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ class FrontendInputsAndOutputs {
265265
bool hasModuleInterfaceOutputPath() const;
266266
bool hasPrivateModuleInterfaceOutputPath() const;
267267
bool hasABIDescriptorOutputPath() const;
268+
bool hasAPIDescriptorOutputPath() const;
268269
bool hasConstValuesOutputPath() const;
269270
bool hasModuleSemanticInfoOutputPath() const;
270271
bool hasModuleSummaryOutputPath() const;

include/swift/Frontend/FrontendOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ class FrontendOptions {
569569
static bool canActionEmitModuleSummary(ActionType);
570570
static bool canActionEmitInterface(ActionType);
571571
static bool canActionEmitABIDescriptor(ActionType);
572+
static bool canActionEmitAPIDescriptor(ActionType);
572573
static bool canActionEmitConstValues(ActionType);
573574
static bool canActionEmitModuleSemanticInfo(ActionType);
574575

include/swift/Option/Options.td

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,19 @@ def emit_const_values :
626626
def emit_const_values_path : Separate<["-"], "emit-const-values-path">,
627627
Flags<[FrontendOption, NoInteractiveOption, ArgumentIsPath,
628628
SupplementaryOutput, CacheInvariant]>,
629-
MetaVarName<"<path>">, HelpText<"Emit the extracted compile-time known values to <path>">;
629+
MetaVarName<"<path>">,
630+
HelpText<"Emit the extracted compile-time known values to <path>">;
631+
632+
def emit_api_descriptor :
633+
Flag<["-"], "emit-api-descriptor">,
634+
Flags<[NoInteractiveOption, SupplementaryOutput, CacheInvariant]>,
635+
HelpText<"Output a JSON file describing the module's API">;
636+
def emit_api_descriptor_path :
637+
Separate<["-"], "emit-api-descriptor-path">,
638+
Flags<[FrontendOption, NoInteractiveOption, ArgumentIsPath,
639+
SupplementaryOutput, CacheInvariant]>,
640+
MetaVarName<"<path>">,
641+
HelpText<"Output a JSON file describing the module's API to <path>">;
630642

631643
def emit_objc_header : Flag<["-"], "emit-objc-header">,
632644
Flags<[FrontendOption, NoInteractiveOption, SupplementaryOutput, CacheInvariant]>,

lib/Basic/FileTypes.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ bool file_types::isTextual(ID Id) {
8686
case file_types::TY_JSONDependencies:
8787
case file_types::TY_JSONFeatures:
8888
case file_types::TY_SwiftABIDescriptor:
89+
case file_types::TY_SwiftAPIDescriptor:
8990
case file_types::TY_ConstValues:
9091
return true;
9192
case file_types::TY_Image:
@@ -164,6 +165,7 @@ bool file_types::isAfterLLVM(ID Id) {
164165
case file_types::TY_JSONFeatures:
165166
case file_types::TY_IndexUnitOutputPath:
166167
case file_types::TY_SwiftABIDescriptor:
168+
case file_types::TY_SwiftAPIDescriptor:
167169
case file_types::TY_ConstValues:
168170
case file_types::TY_SwiftFixIt:
169171
case file_types::TY_ModuleSemanticInfo:
@@ -220,6 +222,7 @@ bool file_types::isPartOfSwiftCompilation(ID Id) {
220222
case file_types::TY_JSONFeatures:
221223
case file_types::TY_IndexUnitOutputPath:
222224
case file_types::TY_SwiftABIDescriptor:
225+
case file_types::TY_SwiftAPIDescriptor:
223226
case file_types::TY_ConstValues:
224227
case file_types::TY_SwiftFixIt:
225228
case file_types::TY_ModuleSemanticInfo:

lib/Driver/Driver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,6 +2090,7 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
20902090
case file_types::TY_JSONDependencies:
20912091
case file_types::TY_JSONFeatures:
20922092
case file_types::TY_SwiftABIDescriptor:
2093+
case file_types::TY_SwiftAPIDescriptor:
20932094
case file_types::TY_ConstValues:
20942095
case file_types::TY_SwiftFixIt:
20952096
case file_types::TY_ModuleSemanticInfo:

lib/Driver/ToolChains.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ const char *ToolChain::JobContext::computeFrontendModeForCompile() const {
733733
case file_types::TY_SwiftOverlayFile:
734734
case file_types::TY_IndexUnitOutputPath:
735735
case file_types::TY_SwiftABIDescriptor:
736+
case file_types::TY_SwiftAPIDescriptor:
736737
case file_types::TY_ConstValues:
737738
case file_types::TY_SwiftFixIt:
738739
case file_types::TY_ModuleSemanticInfo:
@@ -997,6 +998,7 @@ ToolChain::constructInvocation(const BackendJobAction &job,
997998
case file_types::TY_SwiftOverlayFile:
998999
case file_types::TY_IndexUnitOutputPath:
9991000
case file_types::TY_SwiftABIDescriptor:
1001+
case file_types::TY_SwiftAPIDescriptor:
10001002
case file_types::TY_ConstValues:
10011003
case file_types::TY_SwiftFixIt:
10021004
case file_types::TY_ModuleSemanticInfo:

0 commit comments

Comments
 (0)