Skip to content

Commit

Permalink
Fix "Add emit extension block symbols option to dump-symbol-graph and…
Browse files Browse the repository at this point in the history
… SymbolGraphOptions" (#5985)

bring back dump-symbol-graph: add support for -emit-extension-block-symbols and -omit-extension-block-symbols flags (#5892)
  • Loading branch information
theMomax committed Dec 21, 2022
1 parent 800f742 commit 26f5077
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Sources/Commands/PackageTools/DumpCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ struct DumpSymbolGraph: SwiftCommand {

@Flag(help: "Add symbols with SPI information to the symbol graph.")
var includeSPISymbols = false

@Flag(help: "Emit extension block symbols for extensions to external types or directly associate members and conformances with the extended nominal.")
var extensionBlockSymbolBehavior: ExtensionBlockSymbolBehavior = .omitExtensionBlockSymbols

func run(_ swiftTool: SwiftTool) throws {
// Build the current package.
Expand All @@ -51,10 +54,12 @@ struct DumpSymbolGraph: SwiftCommand {
let symbolGraphExtractor = try SymbolGraphExtract(
fileSystem: swiftTool.fileSystem,
tool: swiftTool.getDestinationToolchain().getSymbolGraphExtract(),
observabilityScope: swiftTool.observabilityScope,
skipSynthesizedMembers: skipSynthesizedMembers,
minimumAccessLevel: minimumAccessLevel,
skipInheritedDocs: skipInheritedDocs,
includeSPISymbols: includeSPISymbols,
emitExtensionBlockSymbols: extensionBlockSymbolBehavior == .emitExtensionBlockSymbols,
outputFormat: .json(pretty: prettyPrint)
)

Expand All @@ -76,6 +81,11 @@ struct DumpSymbolGraph: SwiftCommand {
}
}

enum ExtensionBlockSymbolBehavior: String, EnumerableFlag {
case emitExtensionBlockSymbols
case omitExtensionBlockSymbols
}

struct DumpPackage: SwiftCommand {
static let configuration = CommandConfiguration(
abstract: "Print parsed Package.swift as JSON")
Expand Down
4 changes: 3 additions & 1 deletion Sources/Commands/Utilities/PluginDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ final class PluginDelegate: PluginInvocationDelegate {
// Configure the symbol graph extractor.
var symbolGraphExtractor = try SymbolGraphExtract(
fileSystem: swiftTool.fileSystem,
tool: swiftTool.getDestinationToolchain().getSymbolGraphExtract()
tool: swiftTool.getDestinationToolchain().getSymbolGraphExtract(),
observabilityScope: swiftTool.observabilityScope
)
symbolGraphExtractor.skipSynthesizedMembers = !options.includeSynthesized
switch options.minimumAccessLevel {
Expand All @@ -355,6 +356,7 @@ final class PluginDelegate: PluginInvocationDelegate {
}
symbolGraphExtractor.skipInheritedDocs = true
symbolGraphExtractor.includeSPISymbols = options.includeSPI
symbolGraphExtractor.emitExtensionBlockSymbols = options.emitExtensionBlocks

// Determine the output directory, and remove any old version if it already exists.
guard let package = packageGraph.package(for: target) else {
Expand Down
11 changes: 11 additions & 0 deletions Sources/Commands/Utilities/SymbolGraphExtract.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@ import PackageGraph
import PackageModel
import SPMBuildCore
import TSCBasic
@_implementationOnly import DriverSupport

/// A wrapper for swift-symbolgraph-extract tool.
public struct SymbolGraphExtract {
let fileSystem: FileSystem
let tool: AbsolutePath
let observabilityScope: ObservabilityScope

var skipSynthesizedMembers = false
var minimumAccessLevel = AccessLevel.public
var skipInheritedDocs = false
var includeSPISymbols = false
var emitExtensionBlockSymbols = false
var outputFormat = OutputFormat.json(pretty: false)

/// Access control levels.
Expand Down Expand Up @@ -70,6 +73,14 @@ public struct SymbolGraphExtract {
if includeSPISymbols {
commandLine += ["-include-spi-symbols"]
}

let extensionBlockSymbolsFlag = emitExtensionBlockSymbols ? "-emit-extension-block-symbols" : "-omit-extension-block-symbols"
if DriverSupport.checkSupportedFrontendFlags(flags: [extensionBlockSymbolsFlag.trimmingCharacters(in: ["-"])], fileSystem: fileSystem) {
commandLine += [extensionBlockSymbolsFlag]
} else {
observabilityScope.emit(warning: "dropped \(extensionBlockSymbolsFlag) flag because it is not supported by this compiler version")
}

switch outputFormat {
case .json(let pretty):
if pretty {
Expand Down
7 changes: 6 additions & 1 deletion Sources/PackagePlugin/PackageManagerProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,15 @@ public struct PackageManager {

/// Whether to include symbols marked as SPI.
public var includeSPI: Bool

/// Whether to emit symbols for extensions to external types.
public var emitExtensionBlocks: Bool

public init(minimumAccessLevel: AccessLevel = .public, includeSynthesized: Bool = false, includeSPI: Bool = false) {
public init(minimumAccessLevel: AccessLevel = .public, includeSynthesized: Bool = false, includeSPI: Bool = false, emitExtensionBlocks: Bool = false) {
self.minimumAccessLevel = minimumAccessLevel
self.includeSynthesized = includeSynthesized
self.includeSPI = includeSPI
self.emitExtensionBlocks = emitExtensionBlocks
}
}

Expand Down Expand Up @@ -410,6 +414,7 @@ fileprivate extension PluginToHostMessage.SymbolGraphOptions {
self.minimumAccessLevel = .init(options.minimumAccessLevel)
self.includeSynthesized = options.includeSynthesized
self.includeSPI = options.includeSPI
self.emitExtensionBlocks = options.emitExtensionBlocks
}
}

Expand Down
1 change: 1 addition & 0 deletions Sources/PackagePlugin/PluginMessages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -321,5 +321,6 @@ enum PluginToHostMessage: Codable {
}
var includeSynthesized: Bool
var includeSPI: Bool
var emitExtensionBlocks: Bool
}
}
2 changes: 2 additions & 0 deletions Sources/SPMBuildCore/PluginInvocation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ public struct PluginInvocationSymbolGraphOptions {
}
public var includeSynthesized: Bool
public var includeSPI: Bool
public var emitExtensionBlocks: Bool
}

public struct PluginInvocationSymbolGraphResult {
Expand Down Expand Up @@ -960,6 +961,7 @@ fileprivate extension PluginInvocationSymbolGraphOptions {
self.minimumAccessLevel = .init(options.minimumAccessLevel)
self.includeSynthesized = options.includeSynthesized
self.includeSPI = options.includeSPI
self.emitExtensionBlocks = options.emitExtensionBlocks
}
}

Expand Down

0 comments on commit 26f5077

Please sign in to comment.