Skip to content

[Commands] Initial implementation of swift package add-setting command #8532

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
Apr 24, 2025

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Apr 20, 2025

Motivation:

Adds a way to programmatically insert new settings into a package manifest.

Currently only some Swift settings are supported, namely: enable{Upcoming, Experimental}Feature, swiftLanguageMode and strictMemorySafety; but the command could be expanded to support more Swift (C, C++, linker) settings in the future.

Modifications:

  • Add a new "package" sub-command named "add-setting" that accepts a target and a list of --swift Name[=Value]? pairs for each new swift setting to add. Each setting would make sure that manifest is new enough to support it.
  • Add new manifest refactoring action - AddSwiftSetting that would add swiftSettings: to a target or modify the existing one.
  • Expands existing way to check whether manifest is too old to support custom versions. This is doe to make sure that users don't add settings that are not supported by the manifest tools version i.e. swiftLanguageMode was introduced in 6.0 tools.

Result:

A new swift package add-setting --target <name> [--swift Name[=Value]?]+ command that allows users to programmatically add new settings to package manifests.


switch setting {
case .experimentalFeature:
editResult = try AddSwiftSetting.experimentalFeature(
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if the user adds the same setting a second time? And if that setting has a different value than the already added setting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The compiler would take the last value.

Copy link
Contributor

Choose a reason for hiding this comment

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

I did some work in #8534 to make add-dependency idempotent if possible. Doing the same sort of thing here is less important here since adding the same setting twice wont result in a package that wont build, but could be worth looking at just to keep the resulting settings collections free of dupes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I looked into that while working on that and without some support from swift-syntax to match the nodes in general we won't be able to do match...

Copy link
Contributor

Choose a reason for hiding this comment

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

would we be able, at a minimum, to inform the user of the duplicate, and different settings? If this is the case, is there value in prompting the user which value they want to use?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't do that because it would lead to false positive warnings since we cannot really figure out what is what so if they have the setting with different conditions we'll just keep warning about it for no reason.

@xedin xedin force-pushed the add-setting-command branch from 093ac2f to 5d2bdf2 Compare April 21, 2025 17:24
@xedin
Copy link
Contributor Author

xedin commented Apr 23, 2025

@swift-ci please test

@xedin xedin force-pushed the add-setting-command branch from 5d2bdf2 to 2a109f8 Compare April 23, 2025 19:06
@xedin
Copy link
Contributor Author

xedin commented Apr 23, 2025

Re-organized imports a bit to avoid imported what we don't need here.

@xedin
Copy link
Contributor Author

xedin commented Apr 23, 2025

@swift-ci please test

@xedin xedin force-pushed the add-setting-command branch from 2a109f8 to 44ed477 Compare April 23, 2025 21:51
@xedin
Copy link
Contributor Author

xedin commented Apr 23, 2025

@swift-ci please test

Add a way to programmatically insert new settings into a package
manifest.

Currently only some Swift settings are supported, namely:
`enable{Upcoming, Experimental}Feature`, `swiftLanguageMode` and
`strictMemorySafety`; but the command could be expanded to support
more Swift (C, C++, linker) settings in the future.
@xedin xedin force-pushed the add-setting-command branch from 44ed477 to eccff82 Compare April 23, 2025 23:27
@xedin
Copy link
Contributor Author

xedin commented Apr 23, 2025

@swift-ci please test

@xedin
Copy link
Contributor Author

xedin commented Apr 23, 2025

@swift-ci please test Windows platform

@xedin xedin merged commit e952244 into swiftlang:main Apr 24, 2025
6 checks passed
bkhouri pushed a commit to bkhouri/swift-package-manager that referenced this pull request Apr 24, 2025
…and (swiftlang#8532)

### Motivation:

Adds a way to programmatically insert new settings into a package
manifest.

Currently only some Swift settings are supported, namely:
`enable{Upcoming, Experimental}Feature`, `swiftLanguageMode` and
`strictMemorySafety`; but the command could be expanded to support more
Swift (C, C++, linker) settings in the future.

### Modifications:

- Add a new "package" sub-command named "add-setting" that accepts a
target and a list of `--swift Name[=Value]?` pairs for each new swift
setting to add. Each setting would make sure that manifest is new enough
to support it.
- Add new manifest refactoring action - AddSwiftSetting that would add
`swiftSettings:` to a target or modify the existing one.
- Expands existing way to check whether manifest is too old to support
custom versions. This is doe to make sure that users don't add settings
that are not supported by the manifest tools version i.e.
`swiftLanguageMode` was introduced in 6.0 tools.

### Result:

A new `swift package add-setting --target <name> [--swift
Name[=Value]?]+` command that allows users to programmatically add new
settings to package manifests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants