Skip to content

Commit 0464ef6

Browse files
committed
[PackageSyntax] Implement mechanical package manifest editing
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.
1 parent 5e638b0 commit 0464ef6

23 files changed

+4313
-1328
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// swift-tools-version:5.3
2+
import PackageDescription
3+
4+
let package = Package(
5+
name: "MyPackage"
6+
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// swift-tools-version:5.3
2+
import PackageDescription
3+
4+
let package = Package(
5+
name: "MyPackage2",
6+
products: [
7+
.library(name: "Library", targets: ["Library"])
8+
],
9+
targets: [
10+
.target(name: "Library")
11+
]
12+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let x = 42

Package.swift

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ This allowis some clients (such as IDEs) that use SwiftPM's data model but not i
2828
to not have to depend on SwiftDriver, SwiftLLBuild, etc. We should probably have better names here,
2929
though that could break some clients.
3030
*/
31-
let swiftPMDataModelProduct = (
31+
var swiftPMDataModelProduct = (
3232
name: "SwiftPMDataModel",
3333
targets: [
3434
"SourceControl",
@@ -42,6 +42,10 @@ let swiftPMDataModelProduct = (
4242
]
4343
)
4444

45+
#if compiler(>=5.5)
46+
swiftPMDataModelProduct.targets.append("PackageSyntax")
47+
#endif
48+
4549
/** The `libSwiftPM` set of interfaces to programatically work with Swift
4650
packages. `libSwiftPM` includes all of the SwiftPM code except the
4751
command line tools, while `libSwiftPMDataModel` includes only the data model.
@@ -62,6 +66,14 @@ automatic linking type with `-auto` suffix appended to product's name.
6266
*/
6367
let autoProducts = [swiftPMProduct, swiftPMDataModelProduct]
6468

69+
var commandsDependencies: [Target.Dependency] = ["SwiftToolsSupport-auto", "Basics", "Build", "PackageGraph", "SourceControl", "Xcodeproj", "Workspace", "XCBuildSupport", "ArgumentParser", "PackageCollections"]
70+
var commandsSwiftSettings: [SwiftSetting]? = nil
71+
72+
#if compiler(>=5.5)
73+
commandsDependencies.append("PackageSyntax")
74+
commandsSwiftSettings = [.define("BUILD_PACKAGE_SYNTAX")]
75+
#endif
76+
6577
let package = Package(
6678
name: "SwiftPM",
6779
platforms: [macOSPlatform],
@@ -219,7 +231,8 @@ let package = Package(
219231
.target(
220232
/** High-level commands */
221233
name: "Commands",
222-
dependencies: ["SwiftToolsSupport-auto", "Basics", "Build", "PackageGraph", "SourceControl", "Xcodeproj", "Workspace", "XCBuildSupport", "ArgumentParser", "PackageCollections"]),
234+
dependencies: commandsDependencies,
235+
swiftSettings: commandsSwiftSettings),
223236
.target(
224237
/** The main executable provided by SwiftPM */
225238
name: "swift-package",
@@ -265,7 +278,8 @@ let package = Package(
265278
dependencies: ["Build", "SPMTestSupport"]),
266279
.testTarget(
267280
name: "CommandsTests",
268-
dependencies: ["swift-build", "swift-package", "swift-test", "swift-run", "Commands", "Workspace", "SPMTestSupport"]),
281+
dependencies: ["swift-build", "swift-package", "swift-test", "swift-run", "Commands", "Workspace", "SPMTestSupport"],
282+
swiftSettings: commandsSwiftSettings),
269283
.testTarget(
270284
name: "WorkspaceTests",
271285
dependencies: ["Workspace", "SPMTestSupport"]),
@@ -371,3 +385,23 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
371385
.package(path: "../swift-crypto"),
372386
]
373387
}
388+
389+
#if compiler(>=5.5)
390+
// SwiftSyntax depends on lib_InternalSwiftSyntaxParser from the toolchain,
391+
// which had an ABI break in Swift 5.5. As a result, we shouldn't attempt to
392+
// compile PackageSyntax with an earlier compiler version. Although PackageSyntax
393+
// should compile with any 5.5 compiler, it will only be functional when built
394+
// with a toolchain that has a compatible parser library.
395+
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
396+
package.dependencies += [.package(url: "https://github.com/apple/swift-syntax.git", .branch(relatedDependenciesBranch))]
397+
} else {
398+
package.dependencies += [.package(path: "../swift-syntax")]
399+
}
400+
401+
package.targets += [
402+
.target(name: "PackageSyntax",
403+
dependencies: ["Workspace", "PackageModel", "PackageLoading",
404+
"SourceControl", "SwiftSyntax", "SwiftToolsSupport-auto"]),
405+
.testTarget(name: "PackageSyntaxTests", dependencies: ["PackageSyntax", "SPMTestSupport", "SwiftSyntax"]),
406+
]
407+
#endif

0 commit comments

Comments
 (0)