Skip to content

Commit 3e620d4

Browse files
committed
Ensure that verbose (-v) mode applies to in-place execution.
For compiles which fall under our "in-place execution" flow, ensure that we print the in-place job before executing it if `-v` was specified. Resolves rdar://79295614
1 parent 41f1bb3 commit 3e620d4

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3643,6 +3643,25 @@ final class SwiftDriverTests: XCTestCase {
36433643
}
36443644
}
36453645

3646+
func testVerboseImmediateMode() throws {
3647+
try withTemporaryDirectory { path in
3648+
let input = path.appending(component: "ImmediateTest.swift")
3649+
try localFileSystem.writeFileContents(input) { $0 <<< "print(\"Hello, World\")" }
3650+
let binDir = bundleRoot()
3651+
let driver = binDir.appending(component: "swift-driver")
3652+
let args = [driver.description, "--driver-mode=swift", "-v", input.description]
3653+
// Immediate mode takes over the process with `exec` so we need to create
3654+
// a separate process to capture its output here
3655+
let result = try TSCBasic.Process.checkNonZeroExit(
3656+
arguments: args,
3657+
environment: ProcessEnv.vars
3658+
)
3659+
// Make sure the interpret job description was printed
3660+
XCTAssertTrue(result.contains("-frontend -interpret \(input.description)"))
3661+
XCTAssertTrue(result.contains("Hello, World"))
3662+
}
3663+
}
3664+
36463665
func testDiagnosticOptions() throws {
36473666
do {
36483667
var driver = try Driver(args: ["swift", "-no-warnings-as-errors", "-warnings-as-errors", "foo.swift"])

0 commit comments

Comments
 (0)