Skip to content

Commit 42459c7

Browse files
authored
print compiler output when precompiling plugins (#6279)
motivation: surface any plugins compiler errors to users changes: * always print compiler output when failing to compile plugins * restore testPluginCompilationBeforeBuilding test rdar://88547005
1 parent 62f26aa commit 42459c7

File tree

4 files changed

+27
-15
lines changed

4 files changed

+27
-15
lines changed

Sources/Build/BuildOperation.swift

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,16 +334,29 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
334334
self.buildSystemDelegate?.preparationStepStarted(preparationStepName)
335335
}
336336
func didCompilePlugin(result: PluginCompilationResult) {
337-
if !result.description.isEmpty {
338-
self.buildSystemDelegate?.preparationStepHadOutput(preparationStepName, output: result.description)
337+
self.buildSystemDelegate?.preparationStepHadOutput(
338+
preparationStepName,
339+
output: result.commandLine.joined(separator: " "),
340+
verboseOnly: true
341+
)
342+
if !result.compilerOutput.isEmpty {
343+
self.buildSystemDelegate?.preparationStepHadOutput(
344+
preparationStepName,
345+
output: result.compilerOutput,
346+
verboseOnly: false
347+
)
339348
}
340349
self.buildSystemDelegate?.preparationStepFinished(preparationStepName, result: (result.succeeded ? .succeeded : .failed))
341350
}
342351
func skippedCompilingPlugin(cachedResult: PluginCompilationResult) {
343352
// Historically we have emitted log info about cached plugins that are used. We should reconsider whether this is the right thing to do.
344353
self.buildSystemDelegate?.preparationStepStarted(preparationStepName)
345-
if !cachedResult.description.isEmpty {
346-
self.buildSystemDelegate?.preparationStepHadOutput(preparationStepName, output: cachedResult.description)
354+
if !cachedResult.compilerOutput.isEmpty {
355+
self.buildSystemDelegate?.preparationStepHadOutput(
356+
preparationStepName,
357+
output: cachedResult.compilerOutput,
358+
verboseOnly: false
359+
)
347360
}
348361
self.buildSystemDelegate?.preparationStepFinished(preparationStepName, result: (cachedResult.succeeded ? .succeeded : .failed))
349362
}

Sources/Build/BuildOperationBuildSystemDelegateHandler.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,10 +757,11 @@ final class BuildOperationBuildSystemDelegateHandler: LLBuildBuildSystemDelegate
757757
}
758758

759759
/// Invoked when an action taken before building emits output.
760-
func preparationStepHadOutput(_ name: String, output: String) {
760+
/// when verboseOnly is set to true, the output will only be printed in verbose logging mode
761+
func preparationStepHadOutput(_ name: String, output: String, verboseOnly: Bool) {
761762
queue.async {
762763
self.progressAnimation.clear()
763-
if self.logLevel.isVerbose {
764+
if !verboseOnly || self.logLevel.isVerbose {
764765
self.outputStream <<< output.spm_chomp() <<< "\n"
765766
self.outputStream.flush()
766767
}

Sources/SPMBuildCore/PluginScriptRunner.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public struct PluginCompilationResult: Equatable {
9898
public var diagnosticsFile: AbsolutePath
9999

100100
/// Any output emitted by the compiler (stdout and stderr combined).
101-
public var compilerOutput: String
101+
public var rawCompilerOutput: String
102102

103103
/// Whether the compilation result came from the cache (false means that the compiler did run).
104104
public var cached: Bool
@@ -108,21 +108,21 @@ public struct PluginCompilationResult: Equatable {
108108
commandLine: [String],
109109
executableFile: AbsolutePath,
110110
diagnosticsFile: AbsolutePath,
111-
compilerOutput: String,
111+
compilerOutput rawCompilerOutput: String,
112112
cached: Bool
113113
) {
114114
self.succeeded = succeeded
115115
self.commandLine = commandLine
116116
self.executableFile = executableFile
117117
self.diagnosticsFile = diagnosticsFile
118-
self.compilerOutput = compilerOutput
118+
self.rawCompilerOutput = rawCompilerOutput
119119
self.cached = cached
120120
}
121121
}
122122

123-
extension PluginCompilationResult: CustomStringConvertible {
124-
public var description: String {
125-
let output = compilerOutput.spm_chomp()
123+
extension PluginCompilationResult {
124+
public var compilerOutput: String {
125+
let output = self.rawCompilerOutput.spm_chomp()
126126
return output + (output.isEmpty || output.hasSuffix("\n") ? "" : "\n")
127127
}
128128
}

Tests/CommandsTests/PackageToolTests.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2878,9 +2878,7 @@ final class PackageToolTests: CommandsTestCase {
28782878
XCTAssertNotEqual(result.exitStatus, .terminated(code: 0), "output: \(output)")
28792879
XCTAssertMatch(output, .contains("Compiling plugin MyBuildToolPlugin"))
28802880
XCTAssertMatch(output, .contains("Compiling plugin MyCommandPlugin"))
2881-
#if false // sometimes this line isn't emitted; being investigated in https://bugs.swift.org/browse/SR-15831
2882-
XCTAssertMatch(output, .contains("MyCommandPlugin/plugin.swift:7:19: error: consecutive statements on a line must be separated by ';'"))
2883-
#endif
2881+
XCTAssertMatch(output, .contains("error: consecutive statements on a line must be separated by ';'"))
28842882
XCTAssertNoMatch(output, .contains("Building for debugging..."))
28852883
}
28862884
}

0 commit comments

Comments
 (0)