Skip to content

Commit 58baf11

Browse files
committed
Pass symbolgraph flags to symbolgraph-extract
Passes flags from `swift package dump-symbol-graph` to `swift-symbolgraph-extract` The following flags are added: prettyPrint, skipSynthesisedMembers, minimumAccessLevel, skipInheritedDocs and skipInheritedDocs
1 parent 50fc7f2 commit 58baf11

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
@@ -496,10 +496,26 @@ extension SwiftPackageTool {
496496
struct DumpSymbolGraph: SwiftCommand {
497497
static let configuration = CommandConfiguration(
498498
abstract: "Dump Symbol Graph")
499+
static let defaultMinimumAccessLevel = AccessLevel.public
499500

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

513529
try symbolGraphExtract.dumpSymbolGraph(
514-
buildPlan: buildOp.buildPlan!
530+
buildPlan: buildOp.buildPlan!,
531+
prettyPrint: prettyPrint,
532+
skipSynthesisedMembers: skipSynthesizedMembers,
533+
minimumAccessLevel: minimumAccessLevel,
534+
skipInheritedDocs: skipInheritedDocs,
535+
includeSPISymbols: includeSPISymbols
515536
)
516537
}
517538
}

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)