Skip to content

Commit 137b508

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

File tree

6 files changed

+25
-1
lines changed

6 files changed

+25
-1
lines changed

Sources/Commands/PackageTools/DumpCommands.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ struct DumpSymbolGraph: SwiftCommand {
3939

4040
@Flag(help: "Add symbols with SPI information to the symbol graph.")
4141
var includeSPISymbols = false
42+
43+
@Flag(help: "Emit extension block symbols for extensions to external types or directly associate members and conformances with the extended nominal.")
44+
var extensionBlockSymbolBehavior: ExtensionBlockSymbolBehavior = .omitExtensionBlockSymbols
4245

4346
func run(_ swiftTool: SwiftTool) throws {
4447
// Build the current package.
@@ -55,6 +58,7 @@ struct DumpSymbolGraph: SwiftCommand {
5558
minimumAccessLevel: minimumAccessLevel,
5659
skipInheritedDocs: skipInheritedDocs,
5760
includeSPISymbols: includeSPISymbols,
61+
emitExtensionBlockSymbols: extensionBlockSymbolBehavior == .emitExtensionBlockSymbols,
5862
outputFormat: .json(pretty: prettyPrint)
5963
)
6064

@@ -76,6 +80,11 @@ struct DumpSymbolGraph: SwiftCommand {
7680
}
7781
}
7882

83+
enum ExtensionBlockSymbolBehavior: String, EnumerableFlag {
84+
case emitExtensionBlockSymbols
85+
case omitExtensionBlockSymbols
86+
}
87+
7988
struct DumpPackage: SwiftCommand {
8089
static let configuration = CommandConfiguration(
8190
abstract: "Print parsed Package.swift as JSON")

Sources/Commands/Utilities/PluginDelegate.swift

Lines changed: 1 addition & 0 deletions
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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 6 additions & 1 deletion
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,5 +316,6 @@ enum PluginToHostMessage: Codable {
316316
}
317317
var includeSynthesized: Bool
318318
var includeSPI: Bool
319+
var emitExtensionBlocks: Bool
319320
}
320321
}

Sources/SPMBuildCore/PluginInvocation.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ public struct PluginInvocationSymbolGraphOptions {
674674
}
675675
public var includeSynthesized: Bool
676676
public var includeSPI: Bool
677+
public var emitExtensionBlocks: Bool
677678
}
678679

679680
public struct PluginInvocationSymbolGraphResult {
@@ -933,6 +934,7 @@ fileprivate extension PluginInvocationSymbolGraphOptions {
933934
self.minimumAccessLevel = .init(options.minimumAccessLevel)
934935
self.includeSynthesized = options.includeSynthesized
935936
self.includeSPI = options.includeSPI
937+
self.emitExtensionBlocks = options.emitExtensionBlocks
936938
}
937939
}
938940

0 commit comments

Comments
 (0)