-
Notifications
You must be signed in to change notification settings - Fork 1.4k
refactor how plugins call the build system when using the CLI #4185
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1170,32 +1170,20 @@ final class PluginDelegate: PluginInvocationDelegate { | |
|
||
// Create a build operation. We have to disable the cache in order to get a build plan created. | ||
let outputStream = BufferedOutputByteStream() | ||
let buildOperation = BuildOperation( | ||
buildParameters: buildParameters, | ||
let buildOperation = try self.swiftTool.createBuildOperation( | ||
explicitProduct: explicitProduct, | ||
cacheBuildManifest: false, | ||
packageGraphLoader: { try self.swiftTool.loadPackageGraph(explicitProduct: explicitProduct) }, | ||
pluginScriptRunner: try self.swiftTool.getPluginScriptRunner(), | ||
pluginWorkDirectory: try self.swiftTool.getActiveWorkspace().location.pluginWorkingDirectory, | ||
outputStream: outputStream, | ||
logLevel: logLevel, | ||
fileSystem: swiftTool.fileSystem, | ||
observabilityScope: self.swiftTool.observabilityScope | ||
customBuildParameters: buildParameters, | ||
customOutputStream: outputStream, | ||
customLogLevel: logLevel | ||
) | ||
|
||
// Save the instance so it can be canceled from the interrupt handler. | ||
self.swiftTool.buildSystemRef.buildSystem = buildOperation | ||
|
||
// Get or create the build description and plan the build. | ||
let _ = try buildOperation.getBuildDescription() | ||
let buildPlan = buildOperation.buildPlan! | ||
|
||
// Run the build. This doesn't return until the build is complete. | ||
var success = true | ||
do { | ||
try buildOperation.build(subset: buildSubset) | ||
} | ||
catch { | ||
success = false | ||
let success = buildOperation.buildIgnoringError(subset: buildSubset) | ||
|
||
// Get the build plan used | ||
guard let buildPlan = buildOperation.buildPlan else { | ||
throw InternalError("invalid state, buildPlan is undefined") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the above is just a small cleanup There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is better than the |
||
} | ||
|
||
// Create and return the build result record based on what the delegate collected and what's in the build plan. | ||
|
@@ -1942,3 +1930,14 @@ private extension Basics.Diagnostic { | |
.error("missing required argument \(argument)") | ||
} | ||
} | ||
|
||
extension BuildOperation { | ||
fileprivate func buildIgnoringError(subset: BuildSubset) -> Bool { | ||
do { | ||
try self.build(subset: subset) | ||
return true | ||
} catch { | ||
return false | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can also use observabilityScope.trap instead of this, but this preserved the previous behavior exactly There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like there was only one call site for this. Do you think there will be more, or would it be better to keep this do/catch at the one callsite? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. normally you want to do something with the error, but in this case the code only seems to care about the end result. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the key change - basically use the generic swiftTool.createBuildOperation which will record things with the cancellation utility which is less error prone than doing it manually
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great.