Skip to content

[Commands] swift package migrate command #8613

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 8 commits into from
May 7, 2025

Conversation

xedin
Copy link
Contributor

@xedin xedin commented May 3, 2025

Motivation:

swift package migrate could be used to migrate whole package or its individual targets to use the given feature(s) that support migration mode. This is paired with Swift compiler changes to add :migrate mode to upcoming/experimental features.

Modifications:

  • UserToolchain gained an ability to list features supported by the Swift compiler.
  • Implementation of the add-setting package command has been slightly refactored to allow use of manifest modification logic without having to call the command itself.
  • ModuleBuildDescription protocol can now list diagnostic files
  • Added SwiftMigratedCommand that accepts targets (optional) and features, performs a build and uses the newly added SwiftFixIt API to apply fix-its and AddSwiftSetting API to enable features.

Result:

SwiftPM gained a new command swift package migrate --targets <target,...> --to-feature <feature> [--to-feature <...>]

@xedin
Copy link
Contributor Author

xedin commented May 3, 2025

I'm going to add more tests once we actually get a toolchain that supports all the new functionality.

@xedin
Copy link
Contributor Author

xedin commented May 3, 2025

@swift-ci please test

@jakepetroules
Copy link
Contributor

Just so I understand this correctly, the flow is:

  • swift migrate does a build with some extra compiler flags passed, based on the migration options chosen
  • Compiler generates some diagnostics files with "fixits" in the form of file paths + line/column ranges + replacement text
  • SPM reads the diagnostics files and applies the fixits to the source files programmatically
  • SPM programmatically updates the package manifest if possible, based on the migration options chosen

Right?

@xedin
Copy link
Contributor Author

xedin commented May 3, 2025

@jakepetroules Yes, that is correct.

@xedin xedin force-pushed the swift-migrate-command branch from 0f5bf84 to 3cd5d46 Compare May 3, 2025 06:54
@xedin
Copy link
Contributor Author

xedin commented May 3, 2025

@swift-ci please test Linux platform

@xedin
Copy link
Contributor Author

xedin commented May 3, 2025

On thing I forgot to mention - we need to implement category filtering as part of SwiftFixIt still and only apply fix-its related to the selected features. I am planning to do that in a follow-up.

@xedin
Copy link
Contributor Author

xedin commented May 5, 2025

@swift-ci please test

@xedin
Copy link
Contributor Author

xedin commented May 5, 2025

@swift-ci please test Windows platform

1 similar comment
@xedin
Copy link
Contributor Author

xedin commented May 5, 2025

@swift-ci please test Windows platform

@xedin
Copy link
Contributor Author

xedin commented May 5, 2025

@dschaefer2, we have decided to make it a sub-command of package instead, so I'll have to make some changes here but the functionally everything is going to stay the same.

@xedin xedin force-pushed the swift-migrate-command branch from 3cd5d46 to 9f3ba67 Compare May 6, 2025 00:51
@xedin
Copy link
Contributor Author

xedin commented May 6, 2025

@swift-ci please test

@xedin
Copy link
Contributor Author

xedin commented May 6, 2025

@swift-ci please test Windows platform

@xedin xedin force-pushed the swift-migrate-command branch from 9f3ba67 to d8b18e5 Compare May 6, 2025 04:24
@xedin
Copy link
Contributor Author

xedin commented May 6, 2025

@swift-ci please test

@xedin xedin force-pushed the swift-migrate-command branch from d8b18e5 to e53cfc2 Compare May 6, 2025 04:30
@xedin
Copy link
Contributor Author

xedin commented May 6, 2025

@swift-ci please test

@xedin
Copy link
Contributor Author

xedin commented May 6, 2025

@swift-ci please test Windows platform

@xedin
Copy link
Contributor Author

xedin commented May 6, 2025

@swift-ci please test

@xedin
Copy link
Contributor Author

xedin commented May 6, 2025

@swift-ci please test Windows platform

1 similar comment
@xedin
Copy link
Contributor Author

xedin commented May 6, 2025

@swift-ci please test Windows platform

@xedin xedin force-pushed the swift-migrate-command branch from 52fbc59 to cad003f Compare May 6, 2025 20:10
@xedin
Copy link
Contributor Author

xedin commented May 6, 2025

@swift-ci please test Windows platform

3 similar comments
@xedin
Copy link
Contributor Author

xedin commented May 6, 2025

@swift-ci please test Windows platform

@xedin
Copy link
Contributor Author

xedin commented May 6, 2025

@swift-ci please test Windows platform

@xedin
Copy link
Contributor Author

xedin commented May 6, 2025

@swift-ci please test Windows platform

xedin added 7 commits May 6, 2025 13:47
This would make it possible to access diagnostic files through a
generic build system interface.
`swift migrate` could be used to migrate whole package or its
individual targets to use the given feature(s) that support
migration mode.
@xedin xedin force-pushed the swift-migrate-command branch from cad003f to ac92a49 Compare May 6, 2025 23:41
@xedin
Copy link
Contributor Author

xedin commented May 6, 2025

@swift-ci please test Windows platform

2 similar comments
@xedin
Copy link
Contributor Author

xedin commented May 6, 2025

@swift-ci please test Windows platform

@xedin
Copy link
Contributor Author

xedin commented May 6, 2025

@swift-ci please test Windows platform

@xedin
Copy link
Contributor Author

xedin commented May 7, 2025

@swift-ci please test Linux platform

@xedin
Copy link
Contributor Author

xedin commented May 7, 2025

@swift-ci please test macOS platform

@xedin
Copy link
Contributor Author

xedin commented May 7, 2025

@swift-ci please test

@xedin
Copy link
Contributor Author

xedin commented May 7, 2025

@swift-ci please test Windows platform

@xedin xedin merged commit 97fad74 into swiftlang:main May 7, 2025
6 checks passed
@xedin xedin changed the title [Commands] swift migrate command [Commands] swift package migrate command May 7, 2025
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