Skip to content

Commit c733048

Browse files
authored
Merge pull request #715 from artemcm/VerboseImmediateModeFix
Ensure that verbose (`-v`) mode applies to in-place execution.
2 parents bfbe34f + 4c013cc commit c733048

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
@@ -1053,6 +1053,13 @@ extension Driver {
10531053
stderrStream <<< "swift-driver version: " <<< Driver.driverSourceVersion <<< " "
10541054
stderrStream.flush()
10551055
}
1056+
// In verbose mode, print out the job
1057+
if parsedOptions.contains(.v) {
1058+
let arguments: [String] = try executor.resolver.resolveArgumentList(for: inPlaceJob,
1059+
forceResponseFiles: forceResponseFiles)
1060+
stdoutStream <<< arguments.map { $0.spm_shellEscaped() }.joined(separator: " ") <<< "\n"
1061+
stdoutStream.flush()
1062+
}
10561063
try executor.execute(job: inPlaceJob,
10571064
forceResponseFiles: forceResponseFiles,
10581065
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
@@ -3695,6 +3695,30 @@ final class SwiftDriverTests: XCTestCase {
36953695
}
36963696
}
36973697

3698+
func testVerboseImmediateMode() throws {
3699+
// There is nothing particularly macOS-specific about this test other than
3700+
// the use of some macOS-specific XCTest functionality to determine the
3701+
// test bundle that contains the swift-driver executable.
3702+
#if os(macOS)
3703+
try withTemporaryDirectory { path in
3704+
let input = path.appending(component: "ImmediateTest.swift")
3705+
try localFileSystem.writeFileContents(input) { $0 <<< "print(\"Hello, World\")" }
3706+
let binDir = bundleRoot()
3707+
let driver = binDir.appending(component: "swift-driver")
3708+
let args = [driver.description, "--driver-mode=swift", "-v", input.description]
3709+
// Immediate mode takes over the process with `exec` so we need to create
3710+
// a separate process to capture its output here
3711+
let result = try TSCBasic.Process.checkNonZeroExit(
3712+
arguments: args,
3713+
environment: ProcessEnv.vars
3714+
)
3715+
// Make sure the interpret job description was printed
3716+
XCTAssertTrue(result.contains("-frontend -interpret \(input.description)"))
3717+
XCTAssertTrue(result.contains("Hello, World"))
3718+
}
3719+
#endif
3720+
}
3721+
36983722
func testDiagnosticOptions() throws {
36993723
do {
37003724
var driver = try Driver(args: ["swift", "-no-warnings-as-errors", "-warnings-as-errors", "foo.swift"])

0 commit comments

Comments
 (0)