Skip to content

Stop build if there were build-tool plugin failures #5946

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
Dec 8, 2022
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
6 changes: 6 additions & 0 deletions Sources/Build/BuildOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
)

// Surface any diagnostics from build tool plugins.
var succeeded = true
for (target, results) in buildToolPluginInvocationResults {
// There is one result for each plugin that gets applied to a target.
for result in results {
Expand All @@ -420,9 +421,14 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
for diag in result.diagnostics {
diagnosticsEmitter.emit(diag)
}
succeeded = succeeded && result.succeeded
}
}

if !succeeded {
throw StringError("build stopped due to build-tool plugin failures")
}

// Run any prebuild commands provided by build tool plugins. Any failure stops the build.
let prebuildCommandResults = try graph.reachableTargets.reduce(into: [:], { partial, target in
partial[target] = try buildToolPluginInvocationResults[target].map { try self.runPrebuildCommands(for: $0) }
Expand Down
2 changes: 1 addition & 1 deletion Tests/CommandsTests/PackageToolTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,7 @@ final class PackageToolTests: CommandsTestCase {
XCTAssertNotEqual(result.exitStatus, .terminated(code: 0), "output: \(output)")
XCTAssertMatch(output, .contains("This is text from the plugin"))
XCTAssertMatch(output, .contains("error: This is an error from the plugin"))
XCTAssertMatch(output, .contains("Build complete!"))
XCTAssertMatch(output, .contains("build stopped due to build-tool plugin failures"))
}
}

Expand Down