-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Support swift package migrate with --build-system swiftbuild #8888
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
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
13 changes: 13 additions & 0 deletions
13
Fixtures/SwiftMigrate/ExistentialAnyWithCommonPluginDependencyMigration/Package.swift
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,13 @@ | ||
// swift-tools-version:5.8 | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "ExistentialAnyMigration", | ||
targets: [ | ||
.target(name: "Library", dependencies: ["CommonLibrary"], plugins: [.plugin(name: "Plugin")]), | ||
.plugin(name: "Plugin", capability: .buildTool, dependencies: ["Tool"]), | ||
.executableTarget(name: "Tool", dependencies: ["CommonLibrary"]), | ||
.target(name: "CommonLibrary"), | ||
] | ||
) |
17 changes: 17 additions & 0 deletions
17
...wiftMigrate/ExistentialAnyWithCommonPluginDependencyMigration/Plugins/Plugin/Plugin.swift
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,17 @@ | ||
import PackagePlugin | ||
import Foundation | ||
|
||
@main struct Plugin: BuildToolPlugin { | ||
func createBuildCommands(context: PluginContext, target: Target) throws -> [Command] { | ||
let tool = try context.tool(named: "Tool") | ||
let output = context.pluginWorkDirectory.appending(["generated.swift"]) | ||
return [ | ||
.buildCommand( | ||
displayName: "Plugin", | ||
executable: tool.path, | ||
arguments: [output], | ||
inputFiles: [], | ||
outputFiles: [output]) | ||
] | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...rate/ExistentialAnyWithCommonPluginDependencyMigration/Sources/CommonLibrary/Common.swift
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,6 @@ | ||
public func common() {} | ||
|
||
|
||
protocol P {} | ||
|
||
func needsMigration(_ p: P) {} |
6 changes: 6 additions & 0 deletions
6
...SwiftMigrate/ExistentialAnyWithCommonPluginDependencyMigration/Sources/Library/Test.swift
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,6 @@ | ||
import CommonLibrary | ||
|
||
func bar() { | ||
generatedFunction() | ||
common() | ||
} |
13 changes: 13 additions & 0 deletions
13
...es/SwiftMigrate/ExistentialAnyWithCommonPluginDependencyMigration/Sources/Tool/tool.swift
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,13 @@ | ||
import Foundation | ||
import CommonLibrary | ||
|
||
@main struct Entry { | ||
public static func main() async throws { | ||
common() | ||
let outputPath = CommandLine.arguments[1] | ||
let contents = """ | ||
func generatedFunction() {} | ||
""" | ||
FileManager.default.createFile(atPath: outputPath, contents: contents.data(using: .utf8)) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Fixtures/SwiftMigrate/ExistentialAnyWithPluginMigration/Package.swift
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,12 @@ | ||
// swift-tools-version:5.8 | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "ExistentialAnyMigration", | ||
targets: [ | ||
.target(name: "Library", plugins: [.plugin(name: "Plugin")]), | ||
.plugin(name: "Plugin", capability: .buildTool, dependencies: ["Tool"]), | ||
.executableTarget(name: "Tool"), | ||
] | ||
) |
17 changes: 17 additions & 0 deletions
17
Fixtures/SwiftMigrate/ExistentialAnyWithPluginMigration/Plugins/Plugin/Plugin.swift
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,17 @@ | ||
import PackagePlugin | ||
import Foundation | ||
|
||
@main struct Plugin: BuildToolPlugin { | ||
func createBuildCommands(context: PluginContext, target: Target) throws -> [Command] { | ||
let tool = try context.tool(named: "Tool") | ||
let output = context.pluginWorkDirectory.appending(["generated.swift"]) | ||
return [ | ||
.buildCommand( | ||
displayName: "Plugin", | ||
executable: tool.path, | ||
arguments: [output], | ||
inputFiles: [], | ||
outputFiles: [output]) | ||
] | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Fixtures/SwiftMigrate/ExistentialAnyWithPluginMigration/Sources/Library/Test.swift
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,20 @@ | ||
protocol P { | ||
} | ||
|
||
func test1(_: P) { | ||
} | ||
|
||
func test2(_: P.Protocol) { | ||
} | ||
|
||
func test3() { | ||
let _: [P?] = [] | ||
} | ||
|
||
func test4() { | ||
var x = 42 | ||
} | ||
|
||
func bar() { | ||
generatedFunction() | ||
} |
12 changes: 12 additions & 0 deletions
12
Fixtures/SwiftMigrate/ExistentialAnyWithPluginMigration/Sources/Tool/tool.swift
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,12 @@ | ||
import Foundation | ||
|
||
@main struct Entry { | ||
public static func main() async throws { | ||
let outputPath = CommandLine.arguments[1] | ||
let contents = """ | ||
func generatedFunction() {} | ||
func dontmodifyme(_: P) {} | ||
""" | ||
FileManager.default.createFile(atPath: outputPath, contents: contents.data(using: .utf8)) | ||
} | ||
} |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is a problem with using a "name" here as a string unless we can 100% make sure that it would distinguish between host and target builds of the same module (i.e. in BuildOperation we use
module.name
which won't make a distinction)...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need a test that uses a target as a plugin dependency to make sure that we don't override the diagnostics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added another test here to ensure only one fix-it is applied even if the sources need to be built twice as a common dependency of host tools and target content. I think using the name here is in line with the fact that the list of targets may be user provided - names uniquely identify targets in the manifest model, just not once they've been lowered to targets building for a specific platform
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My concern is that we do allow passing flags like -Xswiftc-host or whatever it's spelled so there could be a difference in fix-its produced when building for host and destination, if we use simply a name instead of an identifier that includes target information we'd just override diagnostic files in that map.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now they'd be concatenated instead of one overriding the other, so the entry corresponding to "Foo" includes the diagnostic paths for Foo when built for the host and those when built for the target, and we rely on SwiftFixIt to deduplicate them. I'm not sure we want to drop the host diagnostics entirely because that feels arbitrary imo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see, yeah, that sounds okay, SwiftFixIt should be able to handle that!