Skip to content

Commit d4f9e81

Browse files
authored
Merge pull request #1799 from allevato/6.1-json-ast
🍒 [6.1] Pass the `-dump-ast-format` flag down to the frontend.
2 parents 1eca275 + 55b40b9 commit d4f9e81

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ extension Driver {
276276
try commandLine.appendLast(.lto, from: &parsedOptions)
277277
try commandLine.appendLast(.accessNotesPath, from: &parsedOptions)
278278
try commandLine.appendLast(.enableActorDataRaceChecks, .disableActorDataRaceChecks, from: &parsedOptions)
279+
if isFrontendArgSupported(.dumpAstFormat) {
280+
try commandLine.appendLast(.dumpAstFormat, from: &parsedOptions)
281+
}
279282
try commandLine.appendAll(.D, from: &parsedOptions)
280283
try commandLine.appendAll(.debugPrefixMap, .coveragePrefixMap, .filePrefixMap, from: &parsedOptions)
281284
try commandLine.appendAllArguments(.Xfrontend, from: &parsedOptions)

Sources/SwiftOptions/Options.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ extension Option {
292292
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)
293293
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")
294294
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")
295+
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")
295296
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)
296297
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)
297298
public static let dumpClangDiagnostics: Option = Option("-dump-clang-diagnostics", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Dump Clang diagnostics to stderr")
@@ -1197,6 +1198,7 @@ extension Option {
11971198
Option.driverVerifyFineGrainedDependencyGraphAfterEveryImport,
11981199
Option.driverWarnUnusedOptions,
11991200
Option.dumpApiPath,
1201+
Option.dumpAstFormat,
12001202
Option.dumpAst,
12011203
Option.dumpAvailabilityScopes,
12021204
Option.dumpClangDiagnostics,

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5338,6 +5338,17 @@ final class SwiftDriverTests: XCTestCase {
53385338
}
53395339
}
53405340

5341+
func testDumpASTFormat() throws {
5342+
var driver = try Driver(args: [
5343+
"swiftc", "-dump-ast", "-dump-ast-format", "json", "foo.swift"
5344+
])
5345+
let plannedJobs = try driver.planBuild()
5346+
XCTAssertEqual(plannedJobs[0].kind, .compile)
5347+
XCTAssertTrue(plannedJobs[0].commandLine.contains("-dump-ast"))
5348+
XCTAssertTrue(plannedJobs[0].commandLine.contains("-dump-ast-format"))
5349+
XCTAssertTrue(plannedJobs[0].commandLine.contains("json"))
5350+
}
5351+
53415352
func testDeriveSwiftDocPath() throws {
53425353
var driver = try Driver(args: [
53435354
"swiftc", "-emit-module", "/tmp/main.swift", "-emit-module-path", "test-ios-macabi.swiftmodule"

0 commit comments

Comments
 (0)