Skip to content

Commit d245a1d

Browse files
authored
Merge pull request #1968 from cmcgee1024/symbol_graph_options
Add symbol graph options to swift driver
2 parents e7e3390 + 1c18141 commit d245a1d

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,8 @@ extension Driver {
907907
try commandLine.appendLast(.includeSpiSymbols, from: &parsedOptions)
908908
try commandLine.appendLast(.emitExtensionBlockSymbols, .omitExtensionBlockSymbols, from: &parsedOptions)
909909
try commandLine.appendLast(.symbolGraphMinimumAccessLevel, from: &parsedOptions)
910+
try commandLine.appendLast(.symbolGraphPrettyPrint, from: &parsedOptions)
911+
try commandLine.appendLast(.symbolGraphSkipSynthesizedMembers, from: &parsedOptions)
910912
}
911913

912914
mutating func addEntry(_ entries: inout [VirtualPath.Handle: [FileType: VirtualPath.Handle]], input: TypedVirtualPath?, output: TypedVirtualPath) throws {

Sources/SwiftOptions/Options.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,8 @@ extension Option {
889889
public static let switchCheckingInvocationThresholdEQ: Option = Option("-switch-checking-invocation-threshold=", .joined, attributes: [.helpHidden, .frontend, .noDriver])
890890
public static let symbolGraphAllowAvailabilityPlatforms: Option = Option("-symbol-graph-allow-availability-platforms", .separate, attributes: [.helpHidden, .frontend, .noInteractive, .supplementaryOutput], metaVar: "<platforms>", helpText: "Restrict availability metadata to the given platforms, e.g. 'macOS,Swift'")
891891
public static let symbolGraphBlockAvailabilityPlatforms: Option = Option("-symbol-graph-block-availability-platforms", .separate, attributes: [.helpHidden, .frontend, .noInteractive, .supplementaryOutput], metaVar: "<platforms>", helpText: "Remove the given platforms from symbol graph availability metadata, e.g. 'macOS,Swift'")
892+
public static let symbolGraphPrettyPrint: Option = Option("-symbol-graph-pretty-print", .flag, attributes: [.helpHidden, .noInteractive], helpText: "Pretty-print the output symbol graph JSON")
893+
public static let symbolGraphSkipSynthesizedMembers: Option = Option("-symbol-graph-skip-synthesized-members", .flag, attributes: [.helpHidden, .noInteractive], helpText: "Skip members inherited through classes or default implementations")
892894
public static let symbolGraphMinimumAccessLevel: Option = Option("-symbol-graph-minimum-access-level", .separate, attributes: [.helpHidden, .frontend, .noInteractive, .supplementaryOutput], metaVar: "<level>", helpText: "Include symbols with this access level or more when emitting a symbol graph")
893895
public static let sysroot: Option = Option("-sysroot", .separate, attributes: [.frontend, .synthesizeInterface, .argumentIsPath], metaVar: "<sysroot>", helpText: "Native Platform sysroot")
894896
public static let S: Option = Option("-S", .flag, alias: Option.emitAssembly, attributes: [.frontend, .noInteractive], group: .modes)
@@ -1860,6 +1862,8 @@ extension Option {
18601862
Option.symbolGraphAllowAvailabilityPlatforms,
18611863
Option.symbolGraphBlockAvailabilityPlatforms,
18621864
Option.symbolGraphMinimumAccessLevel,
1865+
Option.symbolGraphPrettyPrint,
1866+
Option.symbolGraphSkipSynthesizedMembers,
18631867
Option.sysroot,
18641868
Option.S,
18651869
Option.tabWidth,

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3550,6 +3550,32 @@ final class SwiftDriverTests: XCTestCase {
35503550
}
35513551
}
35523552

3553+
func testEmitSymbolGraphPrettyPrint() throws {
3554+
do {
3555+
let root = localFileSystem.currentWorkingDirectory!.appending(components: "foo", "bar")
3556+
3557+
var driver = try Driver(args: ["swiftc", "foo.swift", "bar.swift", "-module-name", "Test", "-emit-module-path", rebase("Test.swiftmodule", at: root), "-emit-symbol-graph", "-emit-symbol-graph-dir", "/foo/bar/", "-symbol-graph-pretty-print", "-emit-library"])
3558+
let plannedJobs = try driver.planBuild().removingAutolinkExtractJobs()
3559+
3560+
// We don't know the output file of the symbol graph, just make sure the flag is passed along.
3561+
XCTAssertJobInvocationMatches(plannedJobs[0], .flag("-emit-symbol-graph"))
3562+
XCTAssertJobInvocationMatches(plannedJobs[0], .flag("-symbol-graph-pretty-print"))
3563+
}
3564+
}
3565+
3566+
func testEmitSymbolGraphSkipSynthesizedMembers() throws {
3567+
do {
3568+
let root = localFileSystem.currentWorkingDirectory!.appending(components: "foo", "bar")
3569+
3570+
var driver = try Driver(args: ["swiftc", "foo.swift", "bar.swift", "-module-name", "Test", "-emit-module-path", rebase("Test.swiftmodule", at: root), "-emit-symbol-graph", "-emit-symbol-graph-dir", "/foo/bar/", "-symbol-graph-skip-synthesized-members", "-emit-library"])
3571+
let plannedJobs = try driver.planBuild().removingAutolinkExtractJobs()
3572+
3573+
// We don't know the output file of the symbol graph, just make sure the flag is passed along.
3574+
XCTAssertJobInvocationMatches(plannedJobs[0], .flag("-emit-symbol-graph"))
3575+
XCTAssertJobInvocationMatches(plannedJobs[0], .flag("-symbol-graph-skip-synthesized-members"))
3576+
}
3577+
}
3578+
35533579
func testEmitModuleSeparately() throws {
35543580
var envVars = ProcessEnv.block
35553581
envVars["SWIFT_DRIVER_LD_EXEC"] = ld.nativePathString(escaped: false)

0 commit comments

Comments
 (0)