Skip to content

SwiftPM does not build all dependency executables before invoking plugin build command #5636

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

Conversation

abertelrud
Copy link
Contributor

@abertelrud abertelrud commented Jul 1, 2022

Background & Motivation

Plugins can specify dependencies on executables. Currently, those executables get built before running build tool commands returned by the plugin if those dependencies were either:

  • the path of the executable of a build tool command returned by the plugin, or
  • explicitly included by the plugin in the list of input dependencies to a build command returned by the plugin

This could potentially be more efficient than building all dependencies, since a plugin could depend on two separate executables and then return commands that only used one or the other of them. This would result in SwiftPM only building the executables that were actually mentioned by build commands.

However: This led to confusion and multiple bug reports of failures resulting from not building the executables before trying to use them. One common case is with SwiftProtobuf, which uses protoc as the executable and then a SwiftPM-built executable as one of the parameters to protoc. If the plugin didn't explicitly include the code generation executable in the list of input dependencies in the build tools command it returns, the build would fail and it wouldn't be clear why.

Changes

Make the list of input dependencies of an llbuild command that runs a plugin-provided build tool include the paths of all the tools on which the plugin has declared a dependency, not just the one that appears as an executable in the build command.

This can cause more command line tools to be built but is less confusing overall since a dependency on an executable by a plugin understandably implies that the executable should be built no matter what.

Note that if the plugin doesn't return any build commands, none of the dependencies need to be built. That behavior is preserved.

Specific Modifications:

  • include the paths of the depended-upon tools in the input dependencies to the plugin-provided build tool commands
  • stop special-casing the executable path of build tool commands (any tool there is now included in the list of input dependencies from tools)
  • add a unit test

Results

The executables declared by a plugin are built before any build command returned by the plugin (though not if the plugin doesn't return any commands, which is a no-op).

Note also that this new behavior of building the executables up-front more closely matches the behavior in Xcode 14.

rdar://93679015

@abertelrud
Copy link
Contributor Author

@swift-ci please smoke test

@abertelrud abertelrud marked this pull request as draft July 1, 2022 16:57
@abertelrud abertelrud self-assigned this Jul 1, 2022
@abertelrud
Copy link
Contributor Author

Looks like there is at least one test to update (because it codified the previous dependency) in addition to adding the new one.

@abertelrud abertelrud force-pushed the eng/95759599-plugin-executable-dependencies-not-being-built branch from b16a83a to c46337c Compare July 1, 2022 20:26
@abertelrud
Copy link
Contributor Author

@swift-ci please smoke test

@abertelrud abertelrud force-pushed the eng/95759599-plugin-executable-dependencies-not-being-built branch from c46337c to d653002 Compare July 1, 2022 20:29
…gin build command

Make the list of input dependencies of an llbuild command that runs a plugin-provided build tool also have dependencies on the paths of all the tools on which the plugin has declared a dependency, not just the one that appears as an executable in the build command.

Also adds a mildly elaborate unit test to make sure this works.

rdar://93679015
@abertelrud abertelrud force-pushed the eng/95759599-plugin-executable-dependencies-not-being-built branch from d653002 to e26c128 Compare July 4, 2022 22:03
@abertelrud abertelrud changed the title WIP: SwiftPM does not always build dependency executable before invoking build tool plugin SwiftPM does not build all dependency executables before invoking plugin build command Jul 4, 2022
@abertelrud abertelrud marked this pull request as ready for review July 4, 2022 22:18
@abertelrud
Copy link
Contributor Author

@swift-ci please smoke test

@abertelrud abertelrud added the ready Author believes the PR is ready to be merged & any feedback has been addressed label Jul 4, 2022
@@ -395,7 +400,7 @@ extension PackageGraph {
arguments: arguments,
environment: environment,
workingDirectory: workingDirectory),
inputFiles: inputFiles,
inputFiles: toolPaths + inputFiles,
Copy link
Contributor Author

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. Nothing particularly risky or anything that requires extra scrutiny, I think, but it seemed worth calling out amid all the more mundane changes.

@abertelrud abertelrud merged commit a6ac80f into swiftlang:main Jul 5, 2022
abertelrud added a commit to abertelrud/swift-package-manager that referenced this pull request Jul 5, 2022
…ng plugin build command (swiftlang#5636)

Make the list of input dependencies of an llbuild command that runs a plugin-provided build tool also have dependencies on the paths of all the tools on which the plugin has declared a dependency, not just the one that appears as an executable in the build command.

Also adds a mildly elaborate unit test to make sure this works.

rdar://93679015
(cherry picked from commit a6ac80f)
@abertelrud abertelrud deleted the eng/95759599-plugin-executable-dependencies-not-being-built branch July 5, 2022 18:30
abertelrud added a commit that referenced this pull request Jul 5, 2022
…ng plugin build command (#5636) (#5642)

Make the list of input dependencies of an llbuild command that runs a plugin-provided build tool also have dependencies on the paths of all the tools on which the plugin has declared a dependency, not just the one that appears as an executable in the build command.

Also adds a mildly elaborate unit test to make sure this works.

rdar://93679015
(cherry picked from commit a6ac80f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready Author believes the PR is ready to be merged & any feedback has been addressed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants