pack: support pre-compiled asset catalogs via assetCatalog.compiledDir
- Commit
2a4a06711838bf13ce27625c503ab74358cf82e4- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-18 15:10 UTC (17 days ago)
- Parents
2af0b67
actool is Mac-only, so apps building on Linux (e.g. FindFamily in Modern-Apps) commit actool output (Assets.car, loose icons, assets-partial-Info.plist). PackSchema now decodes assetCatalog.compiledDir, Planner carries it to the app product, and Packer copies every file in that directory into the .app except *.sha256 sidecars and the partial plist, which is merged into Info.plist instead. Verified with a scratch driver against the real FindFamily xtool.yml/Resources: schema decodes and the copy yields exactly Assets.car + [email protected].
Diff
Sources/PackLib/PackSchema.swift
diff --git a/Sources/PackLib/PackSchema.swift b/Sources/PackLib/PackSchema.swiftindex 297c424..8e48c0e 100644--- a/Sources/PackLib/PackSchema.swift+++ b/Sources/PackLib/PackSchema.swift@@ -20,6 +20,18 @@ public struct PackSchemaBase: Codable, Sendable { public var iconPath: String? public var resources: [String]? + /// Pre-compiled asset catalog (fork extension for Linux, where `actool`+ /// is unavailable). `compiledDir` points at a directory produced on a Mac+ /// by `actool` (e.g. `Assets.car`, loose icon PNGs and+ /// `assets-partial-Info.plist`). Every file in the directory except+ /// `*.sha256` sidecars and the partial plist is copied verbatim into the+ /// `.app`; the partial plist is merged into the app's `Info.plist`.+ public var assetCatalog: AssetCatalog?++ public struct AssetCatalog: Codable, Sendable {+ public var compiledDir: String?+ }+ public var extensions: [Extension]? /// Skip auto-creating the LSP support file if it's missing.@@ -75,6 +87,10 @@ public struct PackSchema: Sendable { throw StringError("xtool.yml: iconPath should have a 'png' path extension. Got '\(ext)'.") } }++ if let compiledDir = base.assetCatalog?.compiledDir, compiledDir.isEmpty {+ throw StringError("xtool.yml: assetCatalog.compiledDir must not be empty when present.")+ } } // swiftlint:disable:next force_try
Sources/PackLib/Packer.swift
diff --git a/Sources/PackLib/Packer.swift b/Sources/PackLib/Packer.swiftindex 6506fe7..04458cc 100644--- a/Sources/PackLib/Packer.swift+++ b/Sources/PackLib/Packer.swift@@ -191,6 +191,11 @@ public struct Packer: Sendable { try await packFileToRoot(srcName: iconPath) } }+ if let compiledAssetDir = product.compiledAssetDir {+ group.addTask {+ try await Packer.copyCompiledAssets(from: URL(fileURLWithPath: compiledAssetDir), to: outputURL)+ }+ } group.addTask { try await packFile(srcName: product.targetName, dstName: product.product) }@@ -208,6 +213,19 @@ public struct Packer: Sendable { info["CFBundleIconFile"] = iconName } + if let compiledAssetDir = product.compiledAssetDir {+ let partialURL = URL(fileURLWithPath: compiledAssetDir)+ .appendingPathComponent("assets-partial-Info.plist")+ if FileManager.default.fileExists(atPath: partialURL.path) {+ let data = try Data(contentsOf: partialURL)+ let partial = try PropertyListSerialization.propertyList(from: data, format: nil)+ guard let partial = partial as? [String: any Sendable] else {+ throw StringError("assets-partial-Info.plist has invalid format: expected a dictionary.")+ }+ info.merge(partial, uniquingKeysWith: { $1 })+ }+ }+ let infoPath = outputURL.appendingPathComponent("Info.plist") let encodedPlist = try PropertyListSerialization.data( fromPropertyList: info,@@ -218,6 +236,33 @@ public struct Packer: Sendable { } } + /// Files in a compiled asset directory that belong in the `.app`:+ /// everything except `*.sha256` sidecars and the partial Info.plist+ /// (the latter is merged into `Info.plist`, not copied).+ static func compiledAssetFileNames(in dir: URL) throws -> [String] {+ guard FileManager.default.fileExists(atPath: dir.path) else {+ throw StringError("assetCatalog.compiledDir not found: '\(dir.path)'")+ }+ return try FileManager.default.contentsOfDirectory(atPath: dir.path)+ .filter { !$0.hasSuffix(".sha256") && $0 != "assets-partial-Info.plist" }+ .sorted()+ }++ static func copyCompiledAssets(from dir: URL, to outputURL: URL) async throws {+ for name in try compiledAssetFileNames(in: dir) {+ let src = dir.appendingPathComponent(name)+ var isDir: ObjCBool = false+ guard FileManager.default.fileExists(atPath: src.path, isDirectory: &isDir) else { continue }+ let dest = outputURL.appendingPathComponent(name)+ if isDir.boolValue {+ try FileManager.default.copyItem(at: src, to: dest)+ } else {+ try FileManager.default.copyItem(at: src, to: dest)+ }+ try Task.checkCancellation()+ }+ }+ static func cfBundleSupportedPlatforms(for triple: String) -> [String] { let components = triple.split(separator: "-").map(String.init) guard let appleIndex = components.firstIndex(of: "apple"),
Sources/PackLib/Planner.swift
diff --git a/Sources/PackLib/Planner.swift b/Sources/PackLib/Planner.swiftindex df2f012..bf5a269 100644--- a/Sources/PackLib/Planner.swift+++ b/Sources/PackLib/Planner.swift@@ -85,7 +85,8 @@ public struct Planner: Sendable { idSpecifier: schema.idSpecifier, iconPath: schema.iconPath, rootResources: schema.resources,- entitlementsPath: schema.entitlementsPath+ entitlementsPath: schema.entitlementsPath,+ compiledAssetDir: schema.assetCatalog?.compiledDir ) let extensionProducts: [Plan.Product]@@ -101,7 +102,8 @@ public struct Planner: Sendable { idSpecifier: ext.bundleID.flatMap(PackSchema.IDSpecifier.bundleID) ?? .orgID(app.bundleID), iconPath: nil, rootResources: ext.resources,- entitlementsPath: ext.entitlementsPath+ entitlementsPath: ext.entitlementsPath,+ compiledAssetDir: nil ) } }@@ -123,7 +125,8 @@ public struct Planner: Sendable { idSpecifier: PackSchema.IDSpecifier, iconPath: String?, rootResources: [String]?,- entitlementsPath: String?+ entitlementsPath: String?,+ compiledAssetDir: String? ) async throws -> Plan.Product { let library = try selectLibrary( from: graph.root.products?.filter { $0.type == .autoLibrary } ?? [],@@ -214,7 +217,8 @@ public struct Planner: Sendable { infoPlist: infoPlist, resources: resources, iconPath: iconPath,- entitlementsPath: entitlementsPath+ entitlementsPath: entitlementsPath,+ compiledAssetDir: compiledAssetDir ) } @@ -319,6 +323,8 @@ public struct Plan: Sendable { public var resources: [Resource] public var iconPath: String? public var entitlementsPath: String?+ /// Directory of pre-compiled asset-catalog output (see PackSchema).+ public var compiledAssetDir: String? public var targetName: String { "\(self.product)-\(self.type.targetSuffix)"
Tests/XToolTests/PackerTests.swift
diff --git a/Tests/XToolTests/PackerTests.swift b/Tests/XToolTests/PackerTests.swiftindex 5aabda8..67fd641 100644--- a/Tests/XToolTests/PackerTests.swift+++ b/Tests/XToolTests/PackerTests.swift@@ -1,3 +1,4 @@+import Foundation import Testing @testable import PackLib @@ -13,3 +14,27 @@ import Testing #expect(Packer.cfBundleSupportedPlatforms(for: "unknown-triple") == ["iPhoneOS"]) }++@Test func compiledAssetFileNamesExcludesSidecarsAndPartialPlist() throws {+ let dir = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)+ try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)+ defer { try? FileManager.default.removeItem(at: dir) }+ for name in ["Assets.car", "[email protected]", "Assets.xcassets.sha256", "assets-partial-Info.plist"] {+ try Data().write(to: dir.appendingPathComponent(name))+ }+ #expect(try Packer.compiledAssetFileNames(in: dir) == ["[email protected]", "Assets.car"])+ #expect(throws: (any Error).self) {+ try Packer.compiledAssetFileNames(in: dir.appendingPathComponent("missing"))+ }+}++@Test func packSchemaDecodesAssetCatalogCompiledDir() throws {+ let base = try YAMLTestDecode()+ #expect(base.assetCatalog?.compiledDir == "Resources")+}++private func YAMLTestDecode() throws -> PackSchemaBase {+ // Exercises the same Codable shape xtool.yml uses in Modern-Apps.+ let json = #"{"version":1,"bundleID":"cc.findfamily.app.1","assetCatalog":{"compiledDir":"Resources"}}"#+ return try JSONDecoder().decode(PackSchemaBase.self, from: Data(json.utf8))+}