Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Support Swift 5.7 dependencies #73

Merged
merged 5 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
34 changes: 26 additions & 8 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
"version": "1.0.3"
}
},
{
"package": "swift-collections",
"repositoryURL": "https://github.com/apple/swift-collections.git",
"state": {
"branch": null,
"revision": "48254824bb4248676bf7ce56014ff57b142b77eb",
"version": "1.0.2"
}
},
{
"package": "swift-crypto",
"repositoryURL": "https://github.com/apple/swift-crypto.git",
Expand All @@ -23,35 +32,44 @@
"package": "swift-driver",
"repositoryURL": "https://github.com/apple/swift-driver.git",
"state": {
"branch": "release/5.6",
"revision": "9982f32f96a2e0e597d1b4a0af4a7e997dc471be",
"branch": "release/5.7",
"revision": "3d1af45a920fb1a4c3a1a3ca416fdd49dc8d48b3",
"version": null
}
},
{
"package": "llbuild",
"repositoryURL": "https://github.com/apple/swift-llbuild.git",
"state": {
"branch": "release/5.6",
"revision": "acd686530e56122d916acd49a166beb9198e9b87",
"branch": "release/5.7",
"revision": "e2c27ee7ae7bd82ba35e97bac3c453faa582afd9",
"version": null
}
},
{
"package": "SwiftPM",
"repositoryURL": "https://github.com/apple/swift-package-manager.git",
"state": {
"branch": "release/5.6",
"revision": "286f6dc58e7211d925c3c8ef28593b45f8bfdd85",
"branch": "release/5.7",
"revision": "9f3157bfb7d5dc06cac36b4c86e441136067b7ce",
"version": null
}
},
{
"package": "swift-system",
"repositoryURL": "https://github.com/apple/swift-system.git",
"state": {
"branch": null,
"revision": "836bc4557b74fe6d2660218d56e3ce96aff76574",
"version": "1.1.1"
}
},
{
"package": "swift-tools-support-core",
"repositoryURL": "https://github.com/apple/swift-tools-support-core.git",
"state": {
"branch": "release/5.6",
"revision": "f6c8048a76e280d0f14cc378b8b5c3cfb77c61fb",
"branch": "release/5.7",
"revision": "184eba382f6abbb362ffc02942d790ff35019ad4",
"version": null
}
},
Expand Down
8 changes: 7 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
import PackageDescription

let dependencies: [Package.Dependency]
#if swift(>=5.6)
#if swift(>=5.7)
dependencies = [
.package(url: "https://github.com/apple/swift-argument-parser.git", .exact("1.0.3")),
.package(name: "SwiftPM", url: "https://github.com/apple/swift-package-manager.git", .branch("release/5.7")),
.package(url: "https://github.com/apple/swift-tools-support-core.git", .branch("release/5.7")),
]
#elseif swift(>=5.6)
dependencies = [
.package(url: "https://github.com/apple/swift-argument-parser.git", .exact("1.0.3")),
.package(name: "SwiftPM", url: "https://github.com/apple/swift-package-manager.git", .branch("release/5.6")),
Expand Down
5 changes: 4 additions & 1 deletion Sources/CreateXCFramework/PackageInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ struct PackageInfo {

self.toolchain = try UserToolchain(destination: try .hostDestination())

#if swift(>=5.6)
#if swift(>=5.7)
let loader = ManifestLoader(toolchain: self.toolchain)
self.workspace = try Workspace(forRootPackage: root, customManifestLoader: loader)
#elseif swift(>=5.6)
let resources = ToolchainConfiguration(swiftCompilerPath: self.toolchain.swiftCompilerPath)
let loader = ManifestLoader(toolchain: resources)
self.workspace = try Workspace(forRootPackage: root, customManifestLoader: loader)
Expand Down
2 changes: 1 addition & 1 deletion Sources/CreateXCFramework/ProjectGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct ProjectGenerator {

var projectPath: AbsolutePath {
let dir = AbsolutePath(self.package.projectBuildDirectory.path)
return buildXcodeprojPath(outputDir: dir, projectName: self.package.manifest.displayName)
return XcodeProject.makePath(outputDir: dir, projectName: self.package.manifest.displayName)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This global method is moved to a static method.

}


Expand Down
27 changes: 26 additions & 1 deletion Sources/CreateXCFramework/Zipper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import PackageGraph
import PackageModel
import TSCBasic
import Workspace
import Basics

struct Zipper {

Expand Down Expand Up @@ -54,7 +55,9 @@ struct Zipper {
}

func checksum (file: Foundation.URL) throws -> Foundation.URL {
#if swift(>=5.6)
#if swift(>=5.7)
let sum = try checksum(forBinaryArtifactAt: AbsolutePath(file.path))
#elseif swift(>=5.6)
let sum = try self.package.workspace.checksum(forBinaryArtifactAt: AbsolutePath(file.path))
#else
let sum = self.package.workspace.checksum(forBinaryArtifactAt: AbsolutePath(file.path), diagnostics: self.package.diagnostics)
Expand Down Expand Up @@ -106,6 +109,28 @@ struct Zipper {
func clean (file: Foundation.URL) throws {
try FileManager.default.removeItem(at: file)
}

#if swift(>=5.7)
private func checksum(forBinaryArtifactAt path: AbsolutePath) throws -> String {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

checksum(forBinaryArtifactAt:) is moved from Workspace to Workspace.BinaryArtifactsManager.
Unfortunately, workspace.binaryArtifactsManager is concealed from externals.

So I ported the same implementation from the original SwiftPM codes.

https://github.com/apple/swift-package-manager/blob/release/5.7/Sources/Workspace/Workspace%2BBinaryArtifacts.swift#L390-L413

let fileSystem = localFileSystem
let checksumAlgorithm = SHA256()
let archiver = ZipArchiver(fileSystem: fileSystem)

// Validate the path has a supported extension.
guard let pathExtension = path.extension, archiver.supportedExtensions.contains(pathExtension) else {
let supportedExtensionList = archiver.supportedExtensions.joined(separator: ", ")
throw StringError("unexpected file type; supported extensions are: \(supportedExtensionList)")
}

// Ensure that the path with the accepted extension is a file.
guard fileSystem.isFile(path) else {
throw StringError("file not found at path: \(path.pathString)")
}

let contents = try fileSystem.readFileContents(path)
return checksumAlgorithm.hash(contents).hexadecimalRepresentation
}
#endif
}

#if swift(>=5.6)
Expand Down