Skip to content

Commit 1eca454

Browse files
committed
dump-symbol-graph: add support for -emit-extension-block-symbols and -omit-extension-block-symbols flags
1 parent f28c338 commit 1eca454

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

Sources/Commands/SwiftPackageTool.swift

+11
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,10 @@ extension SwiftPackageTool {
588588

589589
@Flag(help: "Add symbols with SPI information to the symbol graph.")
590590
var includeSPISymbols = false
591+
592+
@Flag(help: "Emit extension block symbols for extensions to external types or directly associate members and conformances with the extended nominal.")
593+
var extensionBlockSymbolBehavior: ExtensionBlockSymbolBehavior = .omitExtensionBlockSymbols
594+
591595

592596
func run(_ swiftTool: SwiftTool) throws {
593597
// Build the current package.
@@ -604,6 +608,7 @@ extension SwiftPackageTool {
604608
minimumAccessLevel: minimumAccessLevel,
605609
skipInheritedDocs: skipInheritedDocs,
606610
includeSPISymbols: includeSPISymbols,
611+
emitExtensionBlockSymbols: extensionBlockSymbolBehavior == .emitExtensionBlockSymbols,
607612
outputFormat: .json(pretty: prettyPrint)
608613
)
609614

@@ -624,6 +629,11 @@ extension SwiftPackageTool {
624629
print("Files written to", symbolGraphDirectory.pathString)
625630
}
626631
}
632+
633+
enum ExtensionBlockSymbolBehavior: String, EnumerableFlag {
634+
case emitExtensionBlockSymbols
635+
case omitExtensionBlockSymbols
636+
}
627637

628638
struct DumpPackage: SwiftCommand {
629639
static let configuration = CommandConfiguration(
@@ -1428,6 +1438,7 @@ final class PluginDelegate: PluginInvocationDelegate {
14281438
}
14291439
symbolGraphExtractor.skipInheritedDocs = true
14301440
symbolGraphExtractor.includeSPISymbols = options.includeSPI
1441+
symbolGraphExtractor.emitExtensionBlockSymbols = options.emitExtensionBlocks
14311442

14321443
// Determine the output directory, and remove any old version if it already exists.
14331444
guard let package = packageGraph.package(for: target) else {

Sources/Commands/Utilities/SymbolGraphExtract.swift

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public struct SymbolGraphExtract {
2626
var minimumAccessLevel = AccessLevel.public
2727
var skipInheritedDocs = false
2828
var includeSPISymbols = false
29+
var emitExtensionBlockSymbols = false
2930
var outputFormat = OutputFormat.json(pretty: false)
3031

3132
/// Access control levels.
@@ -70,6 +71,11 @@ public struct SymbolGraphExtract {
7071
if includeSPISymbols {
7172
commandLine += ["-include-spi-symbols"]
7273
}
74+
if emitExtensionBlockSymbols {
75+
commandLine += ["-emit-extension-block-symbols"]
76+
} else {
77+
commandLine += ["-omit-extension-block-symbols"]
78+
}
7379
switch outputFormat {
7480
case .json(let pretty):
7581
if pretty {

Sources/PackagePlugin/PackageManagerProxy.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,15 @@ public struct PackageManager {
229229

230230
/// Whether to include symbols marked as SPI.
231231
public var includeSPI: Bool
232+
233+
/// Whether to emit symbols for extensions to external types.
234+
public var emitExtensionBlocks: Bool
232235

233-
public init(minimumAccessLevel: AccessLevel = .public, includeSynthesized: Bool = false, includeSPI: Bool = false) {
236+
public init(minimumAccessLevel: AccessLevel = .public, includeSynthesized: Bool = false, includeSPI: Bool = false, emitExtensionBlocks: Bool = false) {
234237
self.minimumAccessLevel = minimumAccessLevel
235238
self.includeSynthesized = includeSynthesized
236239
self.includeSPI = includeSPI
240+
self.emitExtensionBlocks = emitExtensionBlocks
237241
}
238242
}
239243

@@ -410,6 +414,7 @@ fileprivate extension PluginToHostMessage.SymbolGraphOptions {
410414
self.minimumAccessLevel = .init(options.minimumAccessLevel)
411415
self.includeSynthesized = options.includeSynthesized
412416
self.includeSPI = options.includeSPI
417+
self.emitExtensionBlocks = options.emitExtensionBlocks
413418
}
414419
}
415420

Sources/PackagePlugin/PluginMessages.swift

+1
Original file line numberDiff line numberDiff line change
@@ -315,5 +315,6 @@ enum PluginToHostMessage: Codable {
315315
}
316316
var includeSynthesized: Bool
317317
var includeSPI: Bool
318+
var emitExtensionBlocks: Bool
318319
}
319320
}

Sources/SPMBuildCore/PluginInvocation.swift

+2
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ public struct PluginInvocationSymbolGraphOptions {
663663
}
664664
public var includeSynthesized: Bool
665665
public var includeSPI: Bool
666+
public var emitExtensionBlocks: Bool
666667
}
667668

668669
public struct PluginInvocationSymbolGraphResult {
@@ -922,6 +923,7 @@ fileprivate extension PluginInvocationSymbolGraphOptions {
922923
self.minimumAccessLevel = .init(options.minimumAccessLevel)
923924
self.includeSynthesized = options.includeSynthesized
924925
self.includeSPI = options.includeSPI
926+
self.emitExtensionBlocks = options.emitExtensionBlocks
925927
}
926928
}
927929

0 commit comments

Comments
 (0)