Skip to content

Commit a13011a

Browse files
authored
Merge pull request #753 from artemcm/55SilenceTheExecutors
[5.5] Add `.silent` mode to the ToolExecutionDelegate to be used in integrated driver mode
2 parents 6e29a42 + 473aea6 commit a13011a

File tree

5 files changed

+43
-7
lines changed

5 files changed

+43
-7
lines changed

Package.resolved

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,11 +1074,14 @@ extension Driver {
10741074
mutating func createToolExecutionDelegate() -> ToolExecutionDelegate {
10751075
var mode: ToolExecutionDelegate.Mode = .regular
10761076

1077-
// FIXME: Old driver does _something_ if both are passed. Not sure if we want to support that.
1077+
// FIXME: Old driver does _something_ if both -parseable-output and -v are passed.
1078+
// Not sure if we want to support that.
10781079
if parsedOptions.contains(.parseableOutput) {
10791080
mode = .parsableOutput
10801081
} else if parsedOptions.contains(.v) {
10811082
mode = .verbose
1083+
} else if integratedDriver {
1084+
mode = .silent
10821085
}
10831086

10841087
return ToolExecutionDelegate(

Sources/SwiftDriver/Driver/ToolExecutionDelegate.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import Glibc
3737
case verbose
3838
case parsableOutput
3939
case regular
40+
case silent
4041
}
4142

4243
public let mode: Mode
@@ -70,7 +71,7 @@ import Glibc
7071
diagnosticEngine.emit(.remark_job_lifecycle("Starting", job))
7172
}
7273
switch mode {
73-
case .regular:
74+
case .regular, .silent:
7475
break
7576
case .verbose:
7677
stdoutStream <<< arguments.map { $0.spm_shellEscaped() }.joined(separator: " ") <<< "\n"
@@ -100,6 +101,9 @@ import Glibc
100101
#endif
101102

102103
switch mode {
104+
case .silent:
105+
break
106+
103107
case .regular, .verbose:
104108
let output = (try? result.utf8Output() + result.utf8stderrOutput()) ?? ""
105109
if !output.isEmpty {
@@ -139,7 +143,7 @@ import Glibc
139143
diagnosticEngine.emit(.remark_job_lifecycle("Skipped", job))
140144
}
141145
switch mode {
142-
case .regular, .verbose:
146+
case .regular, .verbose, .silent:
143147
break
144148
case .parsableOutput:
145149
let skippedMessage = SkippedMessage(inputs: job.displayInputs.map{ $0.file.name })

Tests/SwiftDriverTests/ParsableMessageTests.swift

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,32 @@ final class ParsableMessageTests: XCTestCase {
344344
}
345345
}
346346

347+
func testSilentIntegratedMode() throws {
348+
do {
349+
try withTemporaryDirectory { path in
350+
try withHijackedBufferedErrorStream(in: path) { errorBuffer in
351+
let main = path.appending(component: "main.swift")
352+
let output = path.appending(component: "main.o")
353+
try localFileSystem.writeFileContents(main) {
354+
$0 <<< "nonexistentPrint(\"hello, compilation error!\")"
355+
}
356+
let diags = DiagnosticsEngine()
357+
let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? []
358+
var driver = try Driver(args: ["swiftc", main.pathString,
359+
"-o", output.pathString] + sdkArgumentsForTesting,
360+
env: ProcessEnv.vars,
361+
diagnosticsEngine: diags,
362+
fileSystem: localFileSystem,
363+
integratedDriver: true)
364+
let jobs = try driver.planBuild()
365+
XCTAssertThrowsError(try driver.run(jobs: jobs))
366+
let invocationErrorOutput = try localFileSystem.readFileContents(errorBuffer).description
367+
XCTAssertFalse(invocationErrorOutput.contains("error: cannot find 'nonexistentPrint' in scope"))
368+
}
369+
}
370+
}
371+
}
372+
347373
func testFrontendMessages() throws {
348374
do {
349375
try withTemporaryDirectory { path in
@@ -360,7 +386,8 @@ final class ParsableMessageTests: XCTestCase {
360386
"-o", output.pathString] + sdkArgumentsForTesting,
361387
env: ProcessEnv.vars,
362388
diagnosticsEngine: diags,
363-
fileSystem: localFileSystem)
389+
fileSystem: localFileSystem,
390+
integratedDriver: false)
364391
let jobs = try driver.planBuild()
365392
XCTAssertEqual(jobs.removingAutolinkExtractJobs().map(\.kind), [.compile, .link])
366393
XCTAssertEqual(jobs[0].outputs.count, 1)

Tests/TestUtilities/DriverExtensions.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ extension Driver {
2121
args: [String],
2222
env: [String: String] = ProcessEnv.vars,
2323
diagnosticsEngine: DiagnosticsEngine = DiagnosticsEngine(handlers: [Driver.stderrDiagnosticsHandler]),
24-
fileSystem: FileSystem = localFileSystem
24+
fileSystem: FileSystem = localFileSystem,
25+
integratedDriver: Bool = true
2526
) throws {
2627
let executor = try SwiftDriverExecutor(diagnosticsEngine: diagnosticsEngine,
2728
processSet: ProcessSet(),
@@ -31,7 +32,8 @@ extension Driver {
3132
env: env,
3233
diagnosticsEngine: diagnosticsEngine,
3334
fileSystem: fileSystem,
34-
executor: executor)
35+
executor: executor,
36+
integratedDriver: integratedDriver)
3537
}
3638

3739
/// For tests that need to set the sdk path.

0 commit comments

Comments
 (0)