Skip to content

[SE-0301] Package Editor Commands Implementation #3034

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

6 changes: 6 additions & 0 deletions Fixtures/PackageEditor/Empty/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// swift-tools-version:5.3
import PackageDescription

let package = Package(
name: "MyPackage"
)
12 changes: 12 additions & 0 deletions Fixtures/PackageEditor/OneProduct/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// swift-tools-version:5.3
import PackageDescription

let package = Package(
name: "MyPackage2",
products: [
.library(name: "Library", targets: ["Library"])
],
targets: [
.target(name: "Library")
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let x = 42
40 changes: 37 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ This allowis some clients (such as IDEs) that use SwiftPM's data model but not i
to not have to depend on SwiftDriver, SwiftLLBuild, etc. We should probably have better names here,
though that could break some clients.
*/
let swiftPMDataModelProduct = (
var swiftPMDataModelProduct = (
name: "SwiftPMDataModel",
targets: [
"SourceControl",
Expand All @@ -33,6 +33,10 @@ let swiftPMDataModelProduct = (
]
)

#if compiler(>=5.5)
swiftPMDataModelProduct.targets.append("PackageSyntax")
#endif

/** The `libSwiftPM` set of interfaces to programatically work with Swift
packages. `libSwiftPM` includes all of the SwiftPM code except the
command line tools, while `libSwiftPMDataModel` includes only the data model.
Expand All @@ -53,6 +57,14 @@ automatic linking type with `-auto` suffix appended to product's name.
*/
let autoProducts = [swiftPMProduct, swiftPMDataModelProduct]

var commandsDependencies: [Target.Dependency] = ["SwiftToolsSupport-auto", "Basics", "Build", "PackageGraph", "SourceControl", "Xcodeproj", "Workspace", "XCBuildSupport", "ArgumentParser", "PackageCollections"]
var commandsSwiftSettings: [SwiftSetting]? = nil

#if compiler(>=5.5)
commandsDependencies.append("PackageSyntax")
commandsSwiftSettings = [.define("BUILD_PACKAGE_SYNTAX")]
#endif

let package = Package(
name: "SwiftPM",
platforms: [
Expand Down Expand Up @@ -213,7 +225,8 @@ let package = Package(
.target(
/** High-level commands */
name: "Commands",
dependencies: ["SwiftToolsSupport-auto", "Basics", "Build", "PackageGraph", "SourceControl", "Xcodeproj", "Workspace", "XCBuildSupport", "ArgumentParser", "PackageCollections"]),
dependencies: commandsDependencies,
swiftSettings: commandsSwiftSettings),
.target(
/** The main executable provided by SwiftPM */
name: "swift-package",
Expand Down Expand Up @@ -259,7 +272,8 @@ let package = Package(
dependencies: ["Build", "SPMTestSupport"]),
.testTarget(
name: "CommandsTests",
dependencies: ["swift-build", "swift-package", "swift-test", "swift-run", "Commands", "Workspace", "SPMTestSupport", "Build"]),
dependencies: ["swift-build", "swift-package", "swift-test", "swift-run", "Commands", "Workspace", "SPMTestSupport", "Build"],
swiftSettings: commandsSwiftSettings),
.testTarget(
name: "WorkspaceTests",
dependencies: ["Workspace", "SPMTestSupport"]),
Expand Down Expand Up @@ -365,3 +379,23 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
.package(path: "../swift-crypto"),
]
}

#if compiler(>=5.5)
// SwiftSyntax depends on lib_InternalSwiftSyntaxParser from the toolchain,
// which had an ABI break in Swift 5.5. As a result, we shouldn't attempt to
// compile PackageSyntax with an earlier compiler version. Although PackageSyntax
// should compile with any 5.5 compiler, it will only be functional when built
// with a toolchain that has a compatible parser library.
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
package.dependencies += [.package(url: "https://github.com/apple/swift-syntax.git", .branch(relatedDependenciesBranch))]
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be pinned to a particular release of SwiftSyntax rather than the branch? The toolchain build will use the branch, but it will presumably also set SWIFTCI_USE_LOCAL_DEPS.

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 think we should use the branch here - it ensures we only ever need to support one version of the SwiftSyntax API, which changes pretty often

Copy link
Contributor

Choose a reason for hiding this comment

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

But if it changes often, doesn't that mean that changes to the branch could suddenly break SwiftPM? i.e. would it not make sense to specify a semantic version and then when necessary update SwiftPM to use the newer version at the same time as adopting any necessary changes, in a single PR?

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 believe SwiftSyntax CI builds SwiftPM so I think we'd at least catch breaking changes pre-merge. The main problem I'm running into is that SwiftPM always needs to build against top-of-tree SwiftSyntax for the feature to work in nightly toolchains. We could also support a specific tag for local development, but it wouldn't be guaranteed to compile 100% of the time

} else {
package.dependencies += [.package(path: "../swift-syntax")]
}

package.targets += [
.target(name: "PackageSyntax",
dependencies: ["Workspace", "PackageModel", "PackageLoading",
"SourceControl", "SwiftSyntax", "SwiftToolsSupport-auto"]),
.testTarget(name: "PackageSyntaxTests", dependencies: ["PackageSyntax", "SPMTestSupport", "SwiftSyntax"]),
]
#endif
Loading