Skip to content

Commit 301c3fb

Browse files
authored
Pass symbolgraph flags to symbolgraph-extract (#3682)
Passes flags from `swift package dump-symbol-graph` to `swift-symbolgraph-extract` The following flags are added: `prettyPrint`, `skipSynthesisedMembers`, `minimumAccessLevel`, `skipInheritedDocs` and `includeSPISymbols`.
1 parent 0b0b22b commit 301c3fb

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

Sources/Commands/SwiftPackageTool.swift

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,10 +493,26 @@ extension SwiftPackageTool {
493493
struct DumpSymbolGraph: SwiftCommand {
494494
static let configuration = CommandConfiguration(
495495
abstract: "Dump Symbol Graph")
496+
static let defaultMinimumAccessLevel = AccessLevel.public
496497

497498
@OptionGroup(_hiddenFromHelp: true)
498499
var swiftOptions: SwiftToolOptions
499-
500+
501+
@Flag(help: "Pretty-print the output JSON.")
502+
var prettyPrint = false
503+
504+
@Flag(help: "Skip members inherited through classes or default implementations.")
505+
var skipSynthesizedMembers = false
506+
507+
@Option(help: "Include symbols with this access level or more. Possible values: \(AccessLevel.allValueStrings.joined(separator: " | "))")
508+
var minimumAccessLevel = defaultMinimumAccessLevel
509+
510+
@Flag(help: "Skip emitting doc comments for members inherited through classes or default implementations.")
511+
var skipInheritedDocs = false
512+
513+
@Flag(help: "Add symbols with SPI information to the symbol graph.")
514+
var includeSPISymbols = false
515+
500516
func run(_ swiftTool: SwiftTool) throws {
501517
let symbolGraphExtract = try SymbolGraphExtract(
502518
tool: swiftTool.getToolchain().getSymbolGraphExtract())
@@ -508,7 +524,12 @@ extension SwiftPackageTool {
508524
try buildOp.build()
509525

510526
try symbolGraphExtract.dumpSymbolGraph(
511-
buildPlan: buildOp.buildPlan!
527+
buildPlan: buildOp.buildPlan!,
528+
prettyPrint: prettyPrint,
529+
skipSynthesisedMembers: skipSynthesizedMembers,
530+
minimumAccessLevel: minimumAccessLevel,
531+
skipInheritedDocs: skipInheritedDocs,
532+
includeSPISymbols: includeSPISymbols
512533
)
513534
}
514535
}

Sources/Commands/SymbolGraphExtract.swift

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import PackageGraph
1919
import PackageModel
2020
import SourceControl
2121
import Workspace
22+
import ArgumentParser
2223

2324
/// A wrapper for swift-symbolgraph-extract tool.
2425
public struct SymbolGraphExtract {
@@ -29,7 +30,12 @@ public struct SymbolGraphExtract {
2930
}
3031

3132
public func dumpSymbolGraph(
32-
buildPlan: BuildPlan
33+
buildPlan: BuildPlan,
34+
prettyPrint: Bool,
35+
skipSynthesisedMembers: Bool,
36+
minimumAccessLevel: AccessLevel,
37+
skipInheritedDocs: Bool,
38+
includeSPISymbols: Bool
3339
) throws {
3440
let buildParameters = buildPlan.buildParameters
3541
let symbolGraphDirectory = buildPlan.buildParameters.symbolGraph
@@ -47,6 +53,14 @@ public struct SymbolGraphExtract {
4753

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

56+
if prettyPrint { args.append("-pretty-print") }
57+
if skipSynthesisedMembers { args.append("-skip-synthesized-members") }
58+
if minimumAccessLevel != SwiftPackageTool.DumpSymbolGraph.defaultMinimumAccessLevel {
59+
args += ["-minimum-access-level", minimumAccessLevel.rawValue]
60+
}
61+
if skipInheritedDocs { args.append("-skip-inherited-docs") }
62+
if includeSPISymbols { args.append("-include-spi-symbols") }
63+
5064
print("-- Emitting symbol graph for", target.name)
5165
try runTool(args)
5266
}
@@ -65,6 +79,16 @@ public struct SymbolGraphExtract {
6579
}
6680
}
6781

82+
/// Access control levels.
83+
public enum AccessLevel: String, RawRepresentable, CustomStringConvertible, CaseIterable {
84+
// The cases reflect those found in `include/swift/AST/AttrKind.h` of the swift compiler (at commit 03f55d7bb4204ca54841218eb7cc175ae798e3bd)
85+
case `private`, `fileprivate`, `internal`, `public`, `open`
86+
87+
public var description: String { rawValue }
88+
}
89+
90+
extension AccessLevel: ExpressibleByArgument {}
91+
6892
extension BuildParameters {
6993
/// The directory containing artifacts generated by the symbolgraph-extract tool.
7094
var symbolGraph: AbsolutePath {

0 commit comments

Comments
 (0)