Skip to content

Commit 1cc4ddd

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

File tree

6 files changed

+26
-1
lines changed

6 files changed

+26
-1
lines changed

Sources/Commands/SwiftPackageTool.swift

+10
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,10 @@ extension SwiftPackageTool {
589589

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

593597
func run(_ swiftTool: SwiftTool) throws {
594598
// Build the current package.
@@ -605,6 +609,7 @@ extension SwiftPackageTool {
605609
minimumAccessLevel: minimumAccessLevel,
606610
skipInheritedDocs: skipInheritedDocs,
607611
includeSPISymbols: includeSPISymbols,
612+
emitExtensionBlockSymbols: extensionBlockSymbolBehavior == .emitExtensionBlockSymbols,
608613
outputFormat: .json(pretty: prettyPrint)
609614
)
610615

@@ -625,6 +630,11 @@ extension SwiftPackageTool {
625630
print("Files written to", symbolGraphDirectory.pathString)
626631
}
627632
}
633+
634+
enum ExtensionBlockSymbolBehavior: String, EnumerableFlag {
635+
case emitExtensionBlockSymbols
636+
case omitExtensionBlockSymbols
637+
}
628638

629639
struct DumpPackage: SwiftCommand {
630640
static let configuration = CommandConfiguration(

Sources/Commands/Utilities/PluginDelegate.swift

+1
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ final class PluginDelegate: PluginInvocationDelegate {
355355
}
356356
symbolGraphExtractor.skipInheritedDocs = true
357357
symbolGraphExtractor.includeSPISymbols = options.includeSPI
358+
symbolGraphExtractor.emitExtensionBlockSymbols = options.emitExtensionBlocks
358359

359360
// Determine the output directory, and remove any old version if it already exists.
360361
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)