Skip to content

Add emit extension block symbols option to dump-symbol-graph and SymbolGraphOptions #5892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 @@ -316,5 +316,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 @@ -674,6 +674,7 @@ public struct PluginInvocationSymbolGraphOptions {
}
public var includeSynthesized: Bool
public var includeSPI: Bool
public var emitExtensionBlocks: Bool
}

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

Expand Down