Skip to content

Commit 754a55f

Browse files
authored
Fix "Add emit extension block symbols option to dump-symbol-graph and SymbolGraphOptions" (#5978)
* Revert "Revert "dump-symbol-graph: add support for -emit-extension-block-symbols and -omit-extension-block-symbols flags (#5892)" (#5975)" This reverts commit 9b81979. * make DriverSupport a private dependency in SymbolGraphExtract
1 parent f9f8d85 commit 754a55f

File tree

6 files changed

+33
-2
lines changed

6 files changed

+33
-2
lines changed

Sources/Commands/PackageTools/DumpCommands.swift

+10
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.
@@ -51,10 +54,12 @@ struct DumpSymbolGraph: SwiftCommand {
5154
let symbolGraphExtractor = try SymbolGraphExtract(
5255
fileSystem: swiftTool.fileSystem,
5356
tool: swiftTool.getDestinationToolchain().getSymbolGraphExtract(),
57+
observabilityScope: swiftTool.observabilityScope,
5458
skipSynthesizedMembers: skipSynthesizedMembers,
5559
minimumAccessLevel: minimumAccessLevel,
5660
skipInheritedDocs: skipInheritedDocs,
5761
includeSPISymbols: includeSPISymbols,
62+
emitExtensionBlockSymbols: extensionBlockSymbolBehavior == .emitExtensionBlockSymbols,
5863
outputFormat: .json(pretty: prettyPrint)
5964
)
6065

@@ -76,6 +81,11 @@ struct DumpSymbolGraph: SwiftCommand {
7681
}
7782
}
7883

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

Sources/Commands/Utilities/PluginDelegate.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,8 @@ final class PluginDelegate: PluginInvocationDelegate {
338338
// Configure the symbol graph extractor.
339339
var symbolGraphExtractor = try SymbolGraphExtract(
340340
fileSystem: swiftTool.fileSystem,
341-
tool: swiftTool.getDestinationToolchain().getSymbolGraphExtract()
341+
tool: swiftTool.getDestinationToolchain().getSymbolGraphExtract(),
342+
observabilityScope: swiftTool.observabilityScope
342343
)
343344
symbolGraphExtractor.skipSynthesizedMembers = !options.includeSynthesized
344345
switch options.minimumAccessLevel {
@@ -355,6 +356,7 @@ final class PluginDelegate: PluginInvocationDelegate {
355356
}
356357
symbolGraphExtractor.skipInheritedDocs = true
357358
symbolGraphExtractor.includeSPISymbols = options.includeSPI
359+
symbolGraphExtractor.emitExtensionBlockSymbols = options.emitExtensionBlocks
358360

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

Sources/Commands/Utilities/SymbolGraphExtract.swift

+11
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,19 @@ import PackageGraph
1616
import PackageModel
1717
import SPMBuildCore
1818
import TSCBasic
19+
@_implementationOnly import DriverSupport
1920

2021
/// A wrapper for swift-symbolgraph-extract tool.
2122
public struct SymbolGraphExtract {
2223
let fileSystem: FileSystem
2324
let tool: AbsolutePath
25+
let observabilityScope: ObservabilityScope
2426

2527
var skipSynthesizedMembers = false
2628
var minimumAccessLevel = AccessLevel.public
2729
var skipInheritedDocs = false
2830
var includeSPISymbols = false
31+
var emitExtensionBlockSymbols = false
2932
var outputFormat = OutputFormat.json(pretty: false)
3033

3134
/// Access control levels.
@@ -70,6 +73,14 @@ public struct SymbolGraphExtract {
7073
if includeSPISymbols {
7174
commandLine += ["-include-spi-symbols"]
7275
}
76+
77+
let extensionBlockSymbolsFlag = emitExtensionBlockSymbols ? "-emit-extension-block-symbols" : "-omit-extension-block-symbols"
78+
if DriverSupport.checkSupportedFrontendFlags(flags: [extensionBlockSymbolsFlag.trimmingCharacters(in: ["-"])], fileSystem: fileSystem) {
79+
commandLine += [extensionBlockSymbolsFlag]
80+
} else {
81+
observabilityScope.emit(warning: "dropped \(extensionBlockSymbolsFlag) flag because it is not supported by this compiler version")
82+
}
83+
7384
switch outputFormat {
7485
case .json(let pretty):
7586
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
@@ -321,5 +321,6 @@ enum PluginToHostMessage: Codable {
321321
}
322322
var includeSynthesized: Bool
323323
var includeSPI: Bool
324+
var emitExtensionBlocks: Bool
324325
}
325326
}

Sources/SPMBuildCore/PluginInvocation.swift

+2
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,7 @@ public struct PluginInvocationSymbolGraphOptions {
700700
}
701701
public var includeSynthesized: Bool
702702
public var includeSPI: Bool
703+
public var emitExtensionBlocks: Bool
703704
}
704705

705706
public struct PluginInvocationSymbolGraphResult {
@@ -960,6 +961,7 @@ fileprivate extension PluginInvocationSymbolGraphOptions {
960961
self.minimumAccessLevel = .init(options.minimumAccessLevel)
961962
self.includeSynthesized = options.includeSynthesized
962963
self.includeSPI = options.includeSPI
964+
self.emitExtensionBlocks = options.emitExtensionBlocks
963965
}
964966
}
965967

0 commit comments

Comments
 (0)