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

Commit e9c9798

Browse files
authored
Merge pull request #68 from sapharow/feature/support-xcode-13-4
Fixed issue with missing(url) on latest XCodes
2 parents 08e353a + b70a952 commit e9c9798

File tree

5 files changed

+116
-25
lines changed

5 files changed

+116
-25
lines changed

Package.resolved

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
import PackageDescription
55

66
let dependencies: [Package.Dependency]
7-
#if swift(>=5.5)
7+
#if swift(>=5.6)
8+
dependencies = [
9+
.package(url: "https://github.com/apple/swift-argument-parser.git", .exact("1.0.3")),
10+
.package(name: "SwiftPM", url: "https://github.com/apple/swift-package-manager.git", .branch("release/5.6")),
11+
.package(url: "https://github.com/apple/swift-tools-support-core.git", .exact("0.2.5"))
12+
]
13+
#elseif swift(>=5.5)
814
dependencies = [
915
.package(url: "https://github.com/apple/swift-argument-parser.git", .exact("0.4.4")),
1016
.package(name: "SwiftPM", url: "https://github.com/apple/swift-package-manager.git", .branch("release/5.5")),
@@ -18,13 +24,22 @@ dependencies = [
1824
]
1925
#endif
2026

27+
let platforms: [SupportedPlatform]
28+
#if swift(>=5.6)
29+
platforms = [
30+
.macOS(.v11),
31+
]
32+
#else
33+
platforms = [
34+
.macOS(.v10_15),
35+
]
36+
#endif
37+
2138
let package = Package(
2239
name: "swift-create-xcframework",
2340

2441
// TODO: Add Linux / Windows support
25-
platforms: [
26-
.macOS(.v10_15),
27-
],
42+
platforms: platforms,
2843

2944
products: [
3045
.executable(name: "swift-create-xcframework", targets: [ "CreateXCFramework" ]),

Sources/CreateXCFramework/PackageInfo.swift

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,20 @@
66
//
77

88
import ArgumentParser
9+
#if swift(>=5.6)
10+
import Basics
11+
#endif
912
import Build
1013
import Foundation
14+
#if swift(>=5.6)
15+
import PackageGraph
16+
#endif
1117
import PackageLoading
1218
import PackageModel
1319
import SPMBuildCore
20+
#if swift(>=5.6)
21+
import TSCBasic
22+
#endif
1423
import Workspace
1524
import Xcodeproj
1625

@@ -53,19 +62,24 @@ struct PackageInfo {
5362
}
5463

5564
// TODO: Map diagnostics to swift-log
65+
#if swift(>=5.6)
66+
let observabilitySystem = ObservabilitySystem { _, diagnostics in
67+
print("\(diagnostics.severity): \(diagnostics.message)")
68+
}
69+
#else
5670
let diagnostics = DiagnosticsEngine()
71+
#endif
5772

5873
let options: Command.Options
59-
// let package: Package
6074
let graph: PackageGraph
6175
let manifest: Manifest
62-
let toolchain: Toolchain
76+
let toolchain: UserToolchain
6377
let workspace: Workspace
6478

6579

6680
// MARK: - Initialisation
6781

68-
init (options: Command.Options) throws {
82+
init (options: Command.Options) throws { // swiftlint:disable:this function_body_length
6983
self.options = options
7084
self.rootDirectory = Foundation.URL(fileURLWithPath: options.packagePath, isDirectory: true).absoluteURL
7185
self.buildDirectory = self.rootDirectory.appendingPathComponent(options.buildPath, isDirectory: true).absoluteURL
@@ -74,15 +88,32 @@ struct PackageInfo {
7488

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

91+
#if swift(>=5.6)
92+
let resources = ToolchainConfiguration(swiftCompilerPath: self.toolchain.swiftCompilerPath)
93+
let loader = ManifestLoader(toolchain: resources)
94+
self.workspace = try Workspace(forRootPackage: root, customManifestLoader: loader)
95+
#else
7796
#if swift(>=5.5)
7897
let resources = try UserManifestResources(swiftCompiler: self.toolchain.swiftCompiler, swiftCompilerFlags: [])
7998
#else
8099
let resources = try UserManifestResources(swiftCompiler: self.toolchain.swiftCompiler)
81100
#endif
82101
let loader = ManifestLoader(manifestResources: resources)
83102
self.workspace = Workspace.create(forRootPackage: root, manifestLoader: loader)
84-
85-
#if swift(>=5.5)
103+
#endif
104+
105+
#if swift(>=5.6)
106+
self.graph = try workspace.loadPackageGraph(rootPath: root, observabilityScope: self.observabilitySystem.topScope)
107+
let workspace = self.workspace
108+
let scope = observabilitySystem.topScope
109+
self.manifest = try tsc_await {
110+
workspace.loadRootManifest(
111+
at: root,
112+
observabilityScope: scope,
113+
completion: $0
114+
)
115+
}
116+
#elseif swift(>=5.5)
86117
self.graph = try self.workspace.loadPackageGraph(rootPath: root, diagnostics: self.diagnostics)
87118
let swiftCompiler = toolchain.swiftCompiler
88119
self.manifest = try tsc_await {
@@ -165,7 +196,7 @@ struct PackageInfo {
165196
Invalid product/target name(s):
166197
\(invalidProducts.joined(separator: "\n "))
167198
168-
Available \(self.manifest.name) products:
199+
Available \(self.manifest.displayName) products:
169200
\(allLibraryProductNames.sorted().joined(separator: "\n "))
170201
171202
Additional available targets:
@@ -184,7 +215,7 @@ struct PackageInfo {
184215

185216
print (
186217
"""
187-
\nAvailable \(self.manifest.name) products:
218+
\nAvailable \(self.manifest.displayName) products:
188219
\(allLibraryProductNames.sorted().joined(separator: "\n "))
189220
190221
Additional available targets:
@@ -280,3 +311,11 @@ enum PackageValidationError: LocalizedError {
280311
}
281312
}
282313
}
314+
315+
#if swift(<5.6)
316+
extension Manifest {
317+
var displayName: String {
318+
name
319+
}
320+
}
321+
#endif

Sources/CreateXCFramework/ProjectGenerator.swift

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct ProjectGenerator {
2323

2424
var projectPath: AbsolutePath {
2525
let dir = AbsolutePath(self.package.projectBuildDirectory.path)
26-
return buildXcodeprojPath(outputDir: dir, projectName: self.package.manifest.name)
26+
return buildXcodeprojPath(outputDir: dir, projectName: self.package.manifest.displayName)
2727
}
2828

2929

@@ -72,6 +72,20 @@ struct ProjectGenerator {
7272
try makeDirectories(path)
7373

7474
// Generate the contents of project.xcodeproj (inside the .xcodeproj).
75+
#if swift(>=5.6)
76+
let project = try pbxproj (
77+
xcodeprojPath: path,
78+
graph: self.package.graph,
79+
extraDirs: [],
80+
extraFiles: [],
81+
options: XcodeprojOptions (
82+
xcconfigOverrides: (self.package.overridesXcconfig?.path).flatMap { AbsolutePath($0) },
83+
useLegacySchemeGenerator: true
84+
),
85+
fileSystem: localFileSystem,
86+
observabilityScope: self.package.observabilitySystem.topScope
87+
)
88+
#else
7589
let project = try pbxproj (
7690
xcodeprojPath: path,
7791
graph: self.package.graph,
@@ -83,6 +97,7 @@ struct ProjectGenerator {
8397
),
8498
diagnostics: self.package.diagnostics
8599
)
100+
#endif
86101

87102
return project
88103
}
@@ -122,7 +137,11 @@ extension Xcode.Project {
122137
try open(path.appending(component: "project.pbxproj")) { stream in
123138
// Serialize the project model we created to a plist, and return
124139
// its string description.
140+
#if swift(>=5.6)
141+
let str = try "// !$*UTF8*$!\n" + self.generatePlist().description
142+
#else
125143
let str = "// !$*UTF8*$!\n" + self.generatePlist().description
144+
#endif
126145
stream(str)
127146
}
128147

Sources/CreateXCFramework/Zipper.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
//
77

88
import Foundation
9+
#if swift(>=5.6)
10+
import PackageGraph
11+
#endif
912
import PackageModel
1013
import TSCBasic
1114
import Workspace
@@ -51,7 +54,11 @@ struct Zipper {
5154
}
5255

5356
func checksum (file: Foundation.URL) throws -> Foundation.URL {
57+
#if swift(>=5.6)
58+
let sum = try self.package.workspace.checksum(forBinaryArtifactAt: AbsolutePath(file.path))
59+
#else
5460
let sum = self.package.workspace.checksum(forBinaryArtifactAt: AbsolutePath(file.path), diagnostics: self.package.diagnostics)
61+
#endif
5562
let checksumFile = file.deletingPathExtension().appendingPathExtension("sha256")
5663
try Data(sum.utf8).write(to: checksumFile)
5764
return checksumFile
@@ -73,13 +80,22 @@ struct Zipper {
7380
// find the package that contains our target
7481
guard let packageRef = self.package.graph.packages.first(where: { $0.targets.contains(where: { $0.name == target }) }) else { return nil }
7582

83+
#if swift(>=5.6)
84+
guard
85+
let dependency = self.package.workspace.state.dependencies[packageRef.identity],
86+
case let .custom(version, _) = dependency.state
87+
else {
88+
return fallback.flatMap { "-" + $0 }
89+
}
90+
#else
7691
guard
7792
let dependency = self.package.workspace.state.dependencies[forNameOrIdentity: packageRef.packageName],
7893
case let .checkout(checkout) = dependency.state,
7994
let version = checkout.version
8095
else {
8196
return fallback.flatMap { "-" + $0 }
8297
}
98+
#endif
8399

84100
return "-" + version.description
85101
}
@@ -92,7 +108,9 @@ struct Zipper {
92108
}
93109
}
94110

95-
#if swift(>=5.5)
111+
#if swift(>=5.6)
112+
// Intentionally left blank
113+
#elseif swift(>=5.5)
96114
private extension ResolvedPackage {
97115
var packageName: String {
98116
self.manifestName

0 commit comments

Comments
 (0)