Skip to content

Commit c30642d

Browse files
authored
Merge pull request #716 from artemcm/55VerboseImmediateModeFix
[5.5] Ensure that verbose (`-v`) mode applies to in-place execution.
2 parents 3a7f8bd + 0510ac8 commit c30642d

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,13 @@ extension Driver {
10231023
stderrStream <<< "swift-driver version: " <<< Driver.driverSourceVersion <<< " "
10241024
stderrStream.flush()
10251025
}
1026+
// In verbose mode, print out the job
1027+
if parsedOptions.contains(.v) {
1028+
let arguments: [String] = try executor.resolver.resolveArgumentList(for: inPlaceJob,
1029+
forceResponseFiles: forceResponseFiles)
1030+
stdoutStream <<< arguments.map { $0.spm_shellEscaped() }.joined(separator: " ") <<< "\n"
1031+
stdoutStream.flush()
1032+
}
10261033
try executor.execute(job: inPlaceJob,
10271034
forceResponseFiles: forceResponseFiles,
10281035
recordedInputModificationDates: recordedInputModificationDates)

Tests/SwiftDriverTests/IntegrationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import TSCBasic
1414

1515

1616
#if os(macOS)
17-
private func bundleRoot() -> AbsolutePath {
17+
internal func bundleRoot() -> AbsolutePath {
1818
for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") {
1919
return AbsolutePath(bundle.bundlePath).parentDirectory
2020
}

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3565,6 +3565,30 @@ final class SwiftDriverTests: XCTestCase {
35653565
}
35663566
}
35673567

3568+
func testVerboseImmediateMode() throws {
3569+
// There is nothing particularly macOS-specific about this test other than
3570+
// the use of some macOS-specific XCTest functionality to determine the
3571+
// test bundle that contains the swift-driver executable.
3572+
#if os(macOS)
3573+
try withTemporaryDirectory { path in
3574+
let input = path.appending(component: "ImmediateTest.swift")
3575+
try localFileSystem.writeFileContents(input) { $0 <<< "print(\"Hello, World\")" }
3576+
let binDir = bundleRoot()
3577+
let driver = binDir.appending(component: "swift-driver")
3578+
let args = [driver.description, "--driver-mode=swift", "-v", input.description]
3579+
// Immediate mode takes over the process with `exec` so we need to create
3580+
// a separate process to capture its output here
3581+
let result = try TSCBasic.Process.checkNonZeroExit(
3582+
arguments: args,
3583+
environment: ProcessEnv.vars
3584+
)
3585+
// Make sure the interpret job description was printed
3586+
XCTAssertTrue(result.contains("-frontend -interpret \(input.description)"))
3587+
XCTAssertTrue(result.contains("Hello, World"))
3588+
}
3589+
#endif
3590+
}
3591+
35683592
func testDiagnosticOptions() throws {
35693593
do {
35703594
var driver = try Driver(args: ["swift", "-no-warnings-as-errors", "-warnings-as-errors", "foo.swift"])

0 commit comments

Comments
 (0)