Skip to content

Commit 91f290f

Browse files
committed
Pass the -dump-ast-format flag down to the frontend.
Companion PR to swiftlang/swift#77321.
1 parent bfc9c09 commit 91f290f

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

+1
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ extension Driver {
283283
try commandLine.appendLast(.lto, from: &parsedOptions)
284284
try commandLine.appendLast(.accessNotesPath, from: &parsedOptions)
285285
try commandLine.appendLast(.enableActorDataRaceChecks, .disableActorDataRaceChecks, from: &parsedOptions)
286+
try commandLine.appendLast(.dumpAstFormat, from: &parsedOptions)
286287
try commandLine.appendAll(.D, from: &parsedOptions)
287288
try commandLine.appendAll(.debugPrefixMap, .coveragePrefixMap, .filePrefixMap, from: &parsedOptions)
288289
try commandLine.appendAllArguments(.Xfrontend, from: &parsedOptions)

Sources/SwiftOptions/Options.swift

+2
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ extension Option {
293293
public static let driverVerifyFineGrainedDependencyGraphAfterEveryImport: Option = Option("-driver-verify-fine-grained-dependency-graph-after-every-import", .flag, attributes: [.helpHidden, .doesNotAffectIncrementalBuild], helpText: "Debug DriverGraph by verifying it after every import", group: .internalDebug)
294294
public static let driverWarnUnusedOptions: Option = Option("-driver-warn-unused-options", .flag, attributes: [.helpHidden], helpText: "Emit warnings for any provided options which are unused by the driver")
295295
public static let dumpApiPath: Option = Option("-dump-api-path", .separate, attributes: [.frontend, .noDriver, .cacheInvariant], helpText: "The path to output swift interface files for the compiled source files")
296+
public static let dumpAstFormat: Option = Option("-dump-ast-format", .separate, attributes: [.frontend, .noInteractive, .doesNotAffectIncrementalBuild], metaVar: "<format>", helpText: "Desired format for -dump-ast output ('default', 'json', or 'json-zlib'); no format is guaranteed stable across different compiler versions")
296297
public static let dumpAst: Option = Option("-dump-ast", .flag, attributes: [.frontend, .noInteractive, .doesNotAffectIncrementalBuild], helpText: "Parse and type-check input file(s) and dump AST(s)", group: .modes)
297298
public static let dumpAvailabilityScopes: Option = Option("-dump-availability-scopes", .flag, attributes: [.frontend, .noInteractive, .doesNotAffectIncrementalBuild], helpText: "Type-check input file(s) and dump availability scopes", group: .modes)
298299
public static let dumpClangDiagnostics: Option = Option("-dump-clang-diagnostics", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Dump Clang diagnostics to stderr")
@@ -1206,6 +1207,7 @@ extension Option {
12061207
Option.driverVerifyFineGrainedDependencyGraphAfterEveryImport,
12071208
Option.driverWarnUnusedOptions,
12081209
Option.dumpApiPath,
1210+
Option.dumpAstFormat,
12091211
Option.dumpAst,
12101212
Option.dumpAvailabilityScopes,
12111213
Option.dumpClangDiagnostics,

Tests/SwiftDriverTests/SwiftDriverTests.swift

+11
Original file line numberDiff line numberDiff line change
@@ -5392,6 +5392,17 @@ final class SwiftDriverTests: XCTestCase {
53925392
}
53935393
}
53945394

5395+
func testDumpASTFormat() throws {
5396+
var driver = try Driver(args: [
5397+
"swiftc", "-dump-ast", "-dump-ast-format", "json", "foo.swift"
5398+
])
5399+
let plannedJobs = try driver.planBuild()
5400+
XCTAssertEqual(plannedJobs[0].kind, .compile)
5401+
XCTAssertTrue(plannedJobs[0].commandLine.contains("-dump-ast"))
5402+
XCTAssertTrue(plannedJobs[0].commandLine.contains("-dump-ast-format"))
5403+
XCTAssertTrue(plannedJobs[0].commandLine.contains("json"))
5404+
}
5405+
53955406
func testDeriveSwiftDocPath() throws {
53965407
var driver = try Driver(args: [
53975408
"swiftc", "-emit-module", "/tmp/main.swift", "-emit-module-path", "test-ios-macabi.swiftmodule"

0 commit comments

Comments
 (0)