-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Migrates plugin documentation into DocC #8766
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4fc98af
WIP - migrating plugin documentation
heckj d8d8e87
enable plugin article
heckj d1ba3de
build plugin example - openAPI generator
heckj b99111c
wip plugin building articles
heckj b204671
adding availability for swift collections and swift plugin docs
heckj 30944c2
adding more availability markers from swift evolution data
heckj 2645b27
rewrite from upstream source for building command and build tool plugins
heckj 2dcde79
Apply suggestions from code review
heckj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
@Metadata { | ||
@PageImage(purpose: icon, source: command-icon) | ||
@Available("Swift", introduced: "5.6") | ||
} | ||
|
||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Plugins | ||
|
||
@Metadata { | ||
@Available("Swift", introduced: "5.6") | ||
} | ||
|
||
Extend package manager functionality with build or command plugins. | ||
|
||
## Overview | ||
|
||
Some of Swift Package Manager's functionality can be extended through _plugins_. | ||
Write package plugins using the `PackagePlugin` API provided by the Swift Package Manager. <!-- link to docs needed --> | ||
This is similar to how the package manifest is implemented — as Swift code that runs as needed in order to produce the information package manager needs. | ||
|
||
Package manager defines two extension points for plugins: | ||
|
||
- term Build Plugin: Custom build tool tasks that provide commands to run before or during the build. | ||
See <doc:EnableBuildPlugin> to see how to add an existing build plugin, or <doc:WritingBuildToolPlugin> to write your own. | ||
|
||
- term Command Plugin: Custom commands that you run using the `swift package` command line interface. | ||
See <doc:EnableCommandPlugin> to see how to add an existing command plugin, or <doc:WritingCommandPlugin> to write your own. | ||
|
||
### Plugin Capabilities | ||
|
||
Plugins have access to a representation of the package model. | ||
Command plugins can also invoke services provided by package manager to build and test products and targets defined in the package to which the plugin is applied. | ||
|
||
Every plugin runs as a separate process from the package manager. | ||
On platforms that support sandboxing, package manager wraps the plugin in a sandbox that prevents network access and attempts to write to arbitrary locations in the file system. | ||
All plugins can write to a temporary directory. | ||
|
||
Custom command plugins that need to modify the package source code can specify this requirement. | ||
If the user approves, package manager grants write access to the package directory. | ||
Build tool plugins can't modify the package source code. | ||
|
||
### Creating Plugins | ||
|
||
When creating a plugin, represent a plugin in the package manifest as a target of the `pluginTarget` type. | ||
If it should be available to other packages, also include a corresponding `pluginProduct` target. | ||
Source code for a plugin is normally located in a directory under the `Plugins` directory in the package, but this can be customized. | ||
|
||
A plugin declares which extension point it implements by defining the plugin's _capability_. | ||
This determines the entry point through which package manager will call it, and determines which actions the plugin can perform. | ||
|
||
### References | ||
|
||
- "Meet Swift Package plugins" [WWDC22 session](https://developer.apple.com/videos/play/wwdc2022-110359) | ||
- "Create Swift Package plugins" [WWDC22 session](https://developer.apple.com/videos/play/wwdc2022-110401) | ||
|
||
## Topics | ||
|
||
### Enabling Plugins | ||
|
||
- <doc:EnableCommandPlugin> | ||
- <doc:EnableBuildPlugin> | ||
|
||
### Writing Plugins | ||
|
||
- <doc:WritingCommandPlugin> | ||
- <doc:WritingBuildToolPlugin> |
60 changes: 60 additions & 0 deletions
60
Sources/PackageManagerDocs/Documentation.docc/Plugins/EnableBuildPlugin.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Enable a build plugin | ||
|
||
@Metadata { | ||
@Available("Swift", introduced: "5.6") | ||
} | ||
|
||
Extend the package manager with a build plugin from another package. | ||
|
||
## Overview | ||
|
||
A package plugin is available to the package that defines it, and if there is a corresponding plugin product, it is also available to any other package that has a direct dependency on the package that defines it. | ||
|
||
### Add a dependency | ||
|
||
To use a plugin defined in another package, add a package dependency on the package that defines the plugin. | ||
For example, to use the [swift-openapi-generator](https://github.com/apple/swift-openapi-generator), add | ||
the following dependency: | ||
|
||
```swift | ||
let package = Package( | ||
// name, platforms, products, etc. | ||
dependencies: [ | ||
// other dependencies | ||
.package(url: "https://github.com/apple/swift-openapi-generator", | ||
from: "1.0.0"), | ||
], | ||
targets: [ | ||
// targets | ||
] | ||
) | ||
``` | ||
|
||
|
||
This plugin can generate models and stubs for clients and servers from an OpenAPI definition file. | ||
|
||
### Identify the targets to enable | ||
|
||
Add the plugin to each target to which it should apply. | ||
For example, the following example enables the OpenAPI generator plugin on the executable target: | ||
|
||
```swift | ||
let package = Package( | ||
name: "Example", | ||
dependencies: [ | ||
.package(url: "https://github.com/apple/swift-openapi-generator", | ||
from: "1.0.0"), | ||
], | ||
targets: [ | ||
.executableTarget( | ||
name: "MyExample", | ||
plugins: [ | ||
.plugin(name: "OpenAPIGenerator", | ||
package: "swift-openapi-generator") | ||
] | ||
) | ||
] | ||
) | ||
``` | ||
When package manager builds the executable target, it calls the plugin and passes it a simplified version of the package model for the target to which it is applied. | ||
Any build commands returned by the plugin are be incorporated into the build graph and run at the appropriate time during the build. |
60 changes: 60 additions & 0 deletions
60
Sources/PackageManagerDocs/Documentation.docc/Plugins/EnableCommandPlugin.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Enable a command plugin | ||
|
||
@Metadata { | ||
@Available("Swift", introduced: "5.6") | ||
} | ||
|
||
Extend package manager commands with a command plugin from another package. | ||
|
||
## Overview | ||
|
||
To get access to a plugin from another package, add a dependency on the package that provides the plugin. | ||
This lets the package access any plugins from the dependency. | ||
|
||
### Add a dependency | ||
|
||
For example, to enable the plugins from [swift-docc-plugin](https://github.com/swiftlang/swift-docc-plugin), add it as a dependency: | ||
|
||
```swift | ||
let package = Package( | ||
// name, platforms, products, etc. | ||
dependencies: [ | ||
// other dependencies | ||
.package(url: "https://github.com/swiftlang/swift-docc-plugin", | ||
from: "1.0.0"), | ||
], | ||
targets: [ | ||
// targets | ||
] | ||
) | ||
``` | ||
|
||
### View available plugins | ||
|
||
Run `swift package plugin --list` to see available plugins. | ||
For full documentation on the plugin command, see <doc:PackagePlugin>. | ||
|
||
Invoke an available plugin using `swift package` followed by the plugin, and provide any parameters or options required. | ||
For example, the following command invokes the `generate-documentation` command from [swift-docc-plugin](https://github.com/swiftlang/swift-docc-plugin). | ||
|
||
```bash | ||
swift package generate-documentation | ||
``` | ||
|
||
### Pass arguments and flags to the plugin | ||
|
||
Package manager passes all command line arguments and flags after the invocation verb to the plugin. | ||
|
||
For example, if your package has multiple targets you may want to specify a single target with the parameter: `--target`. | ||
An updated example that previews the hypothetical target `MyTarget`: | ||
|
||
```bash | ||
swift package generate-documentation --target MyTarget | ||
``` | ||
|
||
### Exempting sandbox constraints | ||
|
||
Command plugins that need to write to the file system cause package manager to ask the user for approval if `swift package` is invoked from a console, or deny the request if it is not. | ||
Pass the flag `--allow-writing-to-package-directory` to the `swift package` invocation to allow the request without questions — this is particularly useful in a Continuous Integration environment. | ||
|
||
Similarly, use the `--allow-network-connections` flag to allow network connections without showing a prompt. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.