Skip to content

[5.5] Ensure that verbose (-v) mode applies to in-place execution. #716

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Sources/SwiftDriver/Driver/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,13 @@ extension Driver {
stderrStream <<< "swift-driver version: " <<< Driver.driverSourceVersion <<< " "
stderrStream.flush()
}
// In verbose mode, print out the job
if parsedOptions.contains(.v) {
let arguments: [String] = try executor.resolver.resolveArgumentList(for: inPlaceJob,
forceResponseFiles: forceResponseFiles)
stdoutStream <<< arguments.map { $0.spm_shellEscaped() }.joined(separator: " ") <<< "\n"
stdoutStream.flush()
}
try executor.execute(job: inPlaceJob,
forceResponseFiles: forceResponseFiles,
recordedInputModificationDates: recordedInputModificationDates)
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftDriverTests/IntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import TSCBasic


#if os(macOS)
private func bundleRoot() -> AbsolutePath {
internal func bundleRoot() -> AbsolutePath {
for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") {
return AbsolutePath(bundle.bundlePath).parentDirectory
}
Expand Down
24 changes: 24 additions & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3565,6 +3565,30 @@ final class SwiftDriverTests: XCTestCase {
}
}

func testVerboseImmediateMode() throws {
// There is nothing particularly macOS-specific about this test other than
// the use of some macOS-specific XCTest functionality to determine the
// test bundle that contains the swift-driver executable.
#if os(macOS)
try withTemporaryDirectory { path in
let input = path.appending(component: "ImmediateTest.swift")
try localFileSystem.writeFileContents(input) { $0 <<< "print(\"Hello, World\")" }
let binDir = bundleRoot()
let driver = binDir.appending(component: "swift-driver")
let args = [driver.description, "--driver-mode=swift", "-v", input.description]
// Immediate mode takes over the process with `exec` so we need to create
// a separate process to capture its output here
let result = try TSCBasic.Process.checkNonZeroExit(
arguments: args,
environment: ProcessEnv.vars
)
// Make sure the interpret job description was printed
XCTAssertTrue(result.contains("-frontend -interpret \(input.description)"))
XCTAssertTrue(result.contains("Hello, World"))
}
#endif
}

func testDiagnosticOptions() throws {
do {
var driver = try Driver(args: ["swift", "-no-warnings-as-errors", "-warnings-as-errors", "foo.swift"])
Expand Down