Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add swift package add-target-plugin command #8432

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

hi2gage
Copy link
Contributor

@hi2gage hi2gage commented Mar 30, 2025

Adds swift package add-target-plugin command for adding plugins to target from CLI

Motivation:

Featured requested in #8169

Allows users to add package plugins to targets via command line.

Forums Discussion

Modifications:

Add new add-target-plugin command which aligns with the existing add-target-dependency command

> swift package add-target-plugin --help
OVERVIEW: Add a new target plugin to the manifest

USAGE: swift package add-target-plugin <plugin-name> <target-name> [--package <package>]

ARGUMENTS:
  <plugin-name>           The name of the new plugin
  <target-name>           The name of the target to update

OPTIONS:
  --package <package>     The package in which the plugin resides
  --version               Show the version.
  -h, -help, --help       Show help information.

Result:

After running the following command:

swift package add-target-plugin OpenAPIGenerator myTarget --package swift-openapi-generator

The following addition will be made to the Package.swift manifest:

.target(
  name: "myTarget",
  plugins: [
    .plugin(name: "OpenAPIGenerator", package: "swift-openapi-generator")
  ]
)

@dschaefer2
Copy link
Member

@swift-ci please test

@dschaefer2
Copy link
Member

@swift-ci please test self hosted windows

@bkhouri
Copy link
Contributor

bkhouri commented Apr 1, 2025

@swift-ci please test windows

@MaxDesiatov MaxDesiatov changed the title Add add plugin command Add swift package add-target-plugin command Apr 1, 2025
@hi2gage
Copy link
Contributor Author

hi2gage commented Apr 1, 2025

@bkhouri is windows (non self hosted) being flakey or is this somehow related to changes I made?

It looks like #8434 passed so maybe I need rebase in the new changes?

@hi2gage hi2gage force-pushed the add_add-plugin_command branch from 31f2020 to d0fe9a8 Compare April 7, 2025 15:32
@hi2gage
Copy link
Contributor Author

hi2gage commented Apr 7, 2025

@dschaefer2 @bkhouri just want to bump this, I rebased the new changes.

@hi2gage
Copy link
Contributor Author

hi2gage commented Apr 7, 2025

@swift-ci please test self hosted windows

@bkhouri
Copy link
Contributor

bkhouri commented Apr 7, 2025

@swift-ci please test

@bkhouri
Copy link
Contributor

bkhouri commented Apr 7, 2025

@swift-ci test self hosted windows

1 similar comment
@bkhouri
Copy link
Contributor

bkhouri commented Apr 8, 2025

@swift-ci test self hosted windows

Copy link
Contributor

@bkhouri bkhouri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could I ask that we add a bit more automated tests?

let contents: String = try fs.readFileContents(manifest)

XCTAssertMatch(contents, .contains(#".plugin(name: "other-product"#))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: I really appreciate the automated tests to validate the behaviour we want. Could I trouble you to add a few more that would check different use cases and fault injections?

  • Calling add-target-plugin on a non-existing package
  • Calling add-target-plugin providing all four combination of a valid/invalid plugin name and target name.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants