Skip to content

Commit

Permalink
[PackageSyntax] Implement mechanical package manifest editing
Browse files Browse the repository at this point in the history
This commit adds a new module, PackageSyntax, which supports making mechanical
edits to Package.swift manifests. It also exposes a CLI interface for this functionality

[PackageSyntax] Adapt to changes in identity and package plugin APIs

[PackageSyntax] Don;t include name argument in package dependency descriptions on 5.5+

[PackageSyntax] Improve tools version coverage of PackageEditor end to end tests

[PackageSyntax] Adapt to more identity API changes

[PackageSyntax] Use new branch and revision convenience methods on 5.5+

[PackageSyntax] Run the bootstrap script without PackageSyntax if SwiftSyntax isn't checked out or --skip-package-syntax is passed

Revert "[PackageSyntax] Run the bootstrap script without PackageSyntax if SwiftSyntax isn't checked out or --skip-package-syntax is passed"

This reverts commit 6f0a920.
  • Loading branch information
owenv committed Jun 12, 2021
1 parent 5e638b0 commit 0464ef6
Show file tree
Hide file tree
Showing 23 changed files with 4,313 additions and 1,328 deletions.
@@ -0,0 +1 @@

6 changes: 6 additions & 0 deletions Fixtures/PackageEditor/Empty/Package.swift
@@ -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
@@ -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")
]
)
@@ -0,0 +1 @@
let x = 42
40 changes: 37 additions & 3 deletions Package.swift
Expand Up @@ -28,7 +28,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 @@ -42,6 +42,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 @@ -62,6 +66,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: [macOSPlatform],
Expand Down Expand Up @@ -219,7 +231,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 @@ -265,7 +278,8 @@ let package = Package(
dependencies: ["Build", "SPMTestSupport"]),
.testTarget(
name: "CommandsTests",
dependencies: ["swift-build", "swift-package", "swift-test", "swift-run", "Commands", "Workspace", "SPMTestSupport"]),
dependencies: ["swift-build", "swift-package", "swift-test", "swift-run", "Commands", "Workspace", "SPMTestSupport"],
swiftSettings: commandsSwiftSettings),
.testTarget(
name: "WorkspaceTests",
dependencies: ["Workspace", "SPMTestSupport"]),
Expand Down Expand Up @@ -371,3 +385,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))]
} 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

0 comments on commit 0464ef6

Please sign in to comment.