Skip to content

Pass dump-symbol-graph flags to symbolgraph-extract #3682

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
Aug 26, 2021
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
25 changes: 23 additions & 2 deletions Sources/Commands/SwiftPackageTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,26 @@ extension SwiftPackageTool {
struct DumpSymbolGraph: SwiftCommand {
static let configuration = CommandConfiguration(
abstract: "Dump Symbol Graph")
static let defaultMinimumAccessLevel = AccessLevel.public

@OptionGroup(_hiddenFromHelp: true)
var swiftOptions: SwiftToolOptions


@Flag(help: "Pretty-print the output JSON.")
var prettyPrint = false

@Flag(help: "Skip members inherited through classes or default implementations.")
var skipSynthesizedMembers = false

@Option(help: "Include symbols with this access level or more. Possible values: \(AccessLevel.allValueStrings.joined(separator: " | "))")
var minimumAccessLevel = defaultMinimumAccessLevel

@Flag(help: "Skip emitting doc comments for members inherited through classes or default implementations.")
var skipInheritedDocs = false

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

func run(_ swiftTool: SwiftTool) throws {
let symbolGraphExtract = try SymbolGraphExtract(
tool: swiftTool.getToolchain().getSymbolGraphExtract())
Expand All @@ -511,7 +527,12 @@ extension SwiftPackageTool {
try buildOp.build()

try symbolGraphExtract.dumpSymbolGraph(
buildPlan: buildOp.buildPlan!
buildPlan: buildOp.buildPlan!,
prettyPrint: prettyPrint,
skipSynthesisedMembers: skipSynthesizedMembers,
minimumAccessLevel: minimumAccessLevel,
skipInheritedDocs: skipInheritedDocs,
includeSPISymbols: includeSPISymbols
)
}
}
Expand Down
26 changes: 25 additions & 1 deletion Sources/Commands/SymbolGraphExtract.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import PackageGraph
import PackageModel
import SourceControl
import Workspace
import ArgumentParser

/// A wrapper for swift-symbolgraph-extract tool.
public struct SymbolGraphExtract {
Expand All @@ -29,7 +30,12 @@ public struct SymbolGraphExtract {
}

public func dumpSymbolGraph(
buildPlan: BuildPlan
buildPlan: BuildPlan,
prettyPrint: Bool,
skipSynthesisedMembers: Bool,
minimumAccessLevel: AccessLevel,
skipInheritedDocs: Bool,
includeSPISymbols: Bool
) throws {
let buildParameters = buildPlan.buildParameters
let symbolGraphDirectory = buildPlan.buildParameters.symbolGraph
Expand All @@ -47,6 +53,14 @@ public struct SymbolGraphExtract {

args += ["-output-dir", symbolGraphDirectory.pathString]

if prettyPrint { args.append("-pretty-print") }
if skipSynthesisedMembers { args.append("-skip-synthesized-members") }
if minimumAccessLevel != SwiftPackageTool.DumpSymbolGraph.defaultMinimumAccessLevel {
args += ["-minimum-access-level", minimumAccessLevel.rawValue]
}
if skipInheritedDocs { args.append("-skip-inherited-docs") }
if includeSPISymbols { args.append("-include-spi-symbols") }

print("-- Emitting symbol graph for", target.name)
try runTool(args)
}
Expand All @@ -65,6 +79,16 @@ public struct SymbolGraphExtract {
}
}

/// Access control levels.
public enum AccessLevel: String, RawRepresentable, CustomStringConvertible, CaseIterable {
// The cases reflect those found in `include/swift/AST/AttrKind.h` of the swift compiler (at commit 03f55d7bb4204ca54841218eb7cc175ae798e3bd)
case `private`, `fileprivate`, `internal`, `public`, `open`

public var description: String { rawValue }
}

extension AccessLevel: ExpressibleByArgument {}

extension BuildParameters {
/// The directory containing artifacts generated by the symbolgraph-extract tool.
var symbolGraph: AbsolutePath {
Expand Down