Skip to content

Commit 1a1ae07

Browse files
committed
Support -print-target-info flag
1 parent 3eafea1 commit 1a1ae07

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,35 @@ extension Driver {
551551
}
552552
}
553553

554+
/// Create a job if needed for simple requests that can be immediately
555+
/// forwarded to the frontend.
556+
public mutating func immediateForwardingJob() throws -> Job? {
557+
if parsedOptions.hasArgument(.printTargetInfo) {
558+
var commandLine: [Job.ArgTemplate] = [.flag("-frontend"),
559+
.flag("-print-target-info")]
560+
try commandLine.appendLast(.target, from: &parsedOptions)
561+
try commandLine.appendLast(.sdk, from: &parsedOptions)
562+
try commandLine.appendLast(.resourceDir, from: &parsedOptions)
563+
return Job(kind: .printTargetInfo,
564+
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
565+
commandLine: commandLine,
566+
inputs: [],
567+
outputs: [],
568+
requiresInPlaceExecution: true)
569+
}
570+
571+
if parsedOptions.hasArgument(.version) || parsedOptions.hasArgument(.version_) {
572+
return Job(kind: .versionRequest,
573+
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
574+
commandLine: [.flag("--version")],
575+
inputs: [],
576+
outputs: [],
577+
requiresInPlaceExecution: true)
578+
}
579+
580+
return nil
581+
}
582+
554583
/// Run the driver.
555584
public mutating func run(
556585
resolver: ArgsResolver,
@@ -567,17 +596,18 @@ extension Driver {
567596
return
568597
}
569598

570-
if parsedOptions.hasArgument(.version) || parsedOptions.hasArgument(.version_) {
571-
// Follow gcc/clang behavior and use stdout for --version and stderr for -v.
572-
try printVersion(outputStream: &stdoutStream)
573-
return
574-
}
575599
if parsedOptions.hasArgument(.v) {
576600
try printVersion(outputStream: &stderrStream)
577601
}
578602

579-
// Plan the build.
580-
let jobs = try planBuild()
603+
let jobs: [Job]
604+
if let job = try immediateForwardingJob() {
605+
jobs = [job]
606+
} else {
607+
// Plan the build.
608+
jobs = try planBuild()
609+
}
610+
581611
if jobs.isEmpty { return }
582612

583613
// If we're only supposed to print the jobs, do so now.

Sources/SwiftDriver/Jobs/Job.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public struct Job: Codable, Equatable {
2727
case interpret
2828
case repl
2929
case verifyDebugInfo = "verify-debug-info"
30+
case printTargetInfo = "print-target-info"
31+
case versionRequest = "version-request"
3032
}
3133

3234
public enum ArgTemplate: Equatable {

0 commit comments

Comments
 (0)