Skip to content

armgit / xtool

Public Imported from GitHub
0

Cross-platform Xcode replacement. Build and deploy iOS apps with SwiftPM on Linux, Windows, macOS.

Support app icon, root resources

Kabir Oberai1a44e866134c
diff --git a/Sources/PackLib/PackSchema.swift b/Sources/PackLib/PackSchema.swift
index 2073fa7..b375a94 100644
--- a/Sources/PackLib/PackSchema.swift
+++ b/Sources/PackLib/PackSchema.swift
@@ -14,6 +14,8 @@ public struct PackSchemaBase: Codable, Sendable {
public var product: String?
public var infoPath: String?
+ public var iconPath: String?
+ public var resources: [String]?
}
public struct PackSchema: Sendable {
@@ -47,6 +49,13 @@ public struct PackSchema: Sendable {
case (nil, nil):
throw StringError("supersign.yml: Must specify either orgID or bundleID")
}
+
+ if let iconPath = base.iconPath {
+ let ext = URL(fileURLWithPath: iconPath).pathExtension
+ guard ext == "png" else {
+ throw StringError("supersign.yml: iconPath should have a 'png' path extension. Got '\(ext)'.")
+ }
+ }
}
public static let `default` = try! PackSchema(validating: .init(
diff --git a/Sources/PackLib/Packer.swift b/Sources/PackLib/Packer.swift
index 748d1e2..4ad2370 100644
--- a/Sources/PackLib/Packer.swift
+++ b/Sources/PackLib/Packer.swift
@@ -73,6 +73,15 @@ public struct Packer: Sendable {
)
let outputURL = output.url
+
+ @Sendable func packFileToRoot(srcName: String) async throws {
+ let srcURL = URL(fileURLWithPath: srcName)
+ let destURL = outputURL.appendingPathComponent(srcURL.lastPathComponent)
+ try FileManager.default.copyItem(at: srcURL, to: destURL)
+
+ try Task.checkCancellation()
+ }
+
@Sendable func packFile(srcName: String, dstName: String? = nil, sign: Bool = false) async throws {
let srcURL = URL(fileURLWithPath: srcName, relativeTo: binDir)
let dstURL = URL(fileURLWithPath: dstName ?? srcURL.lastPathComponent, relativeTo: outputURL)
@@ -100,16 +109,30 @@ public struct Packer: Sendable {
}
case .library(let name):
try await packFile(srcName: "lib\(name).dylib", dstName: "Frameworks/lib\(name).dylib", sign: true)
+ case .root(let source):
+ try await packFileToRoot(srcName: source)
}
}
}
+ if let iconPath = plan.iconPath {
+ group.addTask {
+ try await packFileToRoot(srcName: iconPath)
+ }
+ }
group.addTask {
try await packFile(srcName: "\(plan.product)-App", dstName: plan.product)
}
group.addTask {
+ var info = plan.infoPlist
+
+ if let iconPath = plan.iconPath {
+ let iconName = URL(fileURLWithPath: iconPath).deletingPathExtension().lastPathComponent
+ info["CFBundleIconFile"] = iconName
+ }
+
let infoPath = outputURL.appendingPathComponent("Info.plist")
let encodedPlist = try PropertyListSerialization.data(
- fromPropertyList: plan.infoPlist,
+ fromPropertyList: info,
format: .xml,
options: 0
)
diff --git a/Sources/PackLib/Planner.swift b/Sources/PackLib/Planner.swift
index 90dac15..29f3b7d 100644
--- a/Sources/PackLib/Planner.swift
+++ b/Sources/PackLib/Planner.swift
@@ -107,6 +107,10 @@ public struct Planner: Sendable {
}
}
+ if let rootResources = schema.base.resources {
+ resources += rootResources.map { .root(source: $0) }
+ }
+
let bundleID = schema.idSpecifier.formBundleID(product: library.name)
var infoPlist: [String: Sendable] = [
@@ -148,7 +152,8 @@ public struct Planner: Sendable {
deploymentTarget: deploymentTarget,
bundleID: bundleID,
infoPlist: infoPlist,
- resources: resources
+ resources: resources,
+ iconPath: self.schema.base.iconPath
)
}
@@ -211,12 +216,14 @@ public struct Plan: Sendable {
public var bundleID: String
public var infoPlist: [String: any Sendable]
public var resources: [Resource]
+ public var iconPath: String?
}
public enum Resource: Codable, Sendable {
case bundle(package: String, target: String)
case binaryTarget(name: String)
case library(name: String)
+ case root(source: String)
}
private struct PackageDependency: Decodable {
diff --git a/Sources/PackLib/XcodePacker.swift b/Sources/PackLib/XcodePacker.swift
index d7ba141..37abdc4 100644
--- a/Sources/PackLib/XcodePacker.swift
+++ b/Sources/PackLib/XcodePacker.swift
@@ -80,6 +80,10 @@ public struct XcodePacker {
localPackagesGroup: ""
)
)
+
+ // TODO: Handle plan.resources of type .root
+ // TODO: Handle plan.iconPath
+
let generator = ProjectGenerator(project: project)
let xcodeproj = projectDir + "\(plan.product).xcodeproj"
let xcworkspace = supersignDir + "\(plan.product).xcworkspace"