dist: App Store validation fixes from live FindFamily submission
- Commit
b1dd5b2cfab298d91c5bc86b2660544561d79475- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-19 03:12 UTC (17 days ago)
- Parents
72d7130
- PackLib: stamp DTPlatformName/DTPlatformVersion/DTSDKName/DTSDKBuild/ DTPlatformBuild/DTXcode/DTXcodeBuild from the installed SDK (missing DTPlatformName is error 90507; DTSDKBuild must be the SDK ProductBuildVersion, e.g. 23F81a, not the marketing version) - PackLib/Dev: default build triple carries the SDK version (arm64-apple-ios26.5) so LC_BUILD_VERSION records a current SDK (error 90725), with -platform_version pinning minos to the deployment target - Mobileprovision: App Store profiles have no ProvisionedDevices; default to empty instead of failing to decode - DistributionSigning: reuse an existing profile matched by the deterministic name as well as by bundle relationship (the list response omits relationships; re-creating hits a 409 duplicate) - AppStoreConnect: buildUploads attributes per the official OpenAPI spec (no cfBundleIdentifier, assetType ASSET required, no checksums on file PATCH, buildUploads has no UPDATE); reviewSubmissions create takes no submitted attribute; reuse an open READY_FOR_REVIEW submission; declare usesNonExemptEncryption=false when unset
Diff
Sources/PackLib/Packer.swift
diff --git a/Sources/PackLib/Packer.swift b/Sources/PackLib/Packer.swiftindex 04458cc..163966d 100644--- a/Sources/PackLib/Packer.swift+++ b/Sources/PackLib/Packer.swift@@ -206,6 +206,23 @@ public struct Packer: Sendable { info["UIRequiredDeviceCapabilities"] = ["arm64"] info["LSRequiresIPhoneOS"] = true info["CFBundleSupportedPlatforms"] = Packer.cfBundleSupportedPlatforms(for: buildSettings.triple)+ // App Store upload validation requires the DT* keys Xcode+ // stamps (missing DTPlatformName is error 90507, and an+ // unrecognized SDK is 90534).+ let simulator = buildSettings.triple.contains("simulator")+ info["DTPlatformName"] = simulator ? "iphonesimulator" : "iphoneos"+ if let sdk = Packer.darwinSDKInfo() {+ info["DTPlatformVersion"] = sdk.version+ info["DTSDKName"] = "\(simulator ? "iphonesimulator" : "iphoneos")\(sdk.version)"+ // DTSDKBuild must be the SDK's ProductBuildVersion+ // (e.g. 24A94232), not the marketing version — App Store+ // rejects unknown values (BUILD_SDK_NOT_ALLOWED).+ info["DTSDKBuild"] = sdk.sdkBuild ?? sdk.xcodeBuild ?? sdk.version+ info["DTPlatformBuild"] = sdk.sdkBuild ?? sdk.xcodeBuild ?? sdk.version+ if let xcode = sdk.xcode { info["DTXcode"] = xcode }+ if let xcodeBuild = sdk.xcodeBuild { info["DTXcodeBuild"] = xcodeBuild }+ }+ info["DTCompiler"] = "com.apple.compilers.llvm.clang.1_0" } if let iconPath = product.iconPath {@@ -236,6 +253,52 @@ public struct Packer: Sendable { } } + public struct DarwinSDKInfo: Sendable {+ public var version: String+ public var sdkBuild: String?+ public var xcode: String?+ public var xcodeBuild: String?+ }++ /// Version/build of the installed iPhoneOS SDK (version from its+ /// directory name, e.g. `iPhoneOS27.1.sdk`; build from the sibling+ /// Xcode.app when present), used for the `DT*` Info.plist keys and the+ /// SDK-versioned build triple.+ public static func darwinSDKInfo() -> DarwinSDKInfo? {+ guard let sdk = try? DarwinSDK.current() else { return nil }+ let sdksDir = sdk.bundle+ .appendingPathComponent("Developer/Platforms/iPhoneOS.platform/Developer/SDKs")+ guard let names = try? FileManager.default.contentsOfDirectory(atPath: sdksDir.path) else { return nil }+ var version: String?+ for name in names.sorted() {+ // iPhoneOS27.1.sdk (skip the iPhoneOS.sdk alias)+ guard name.hasPrefix("iPhoneOS"), name.hasSuffix(".sdk") else { continue }+ let candidate = name.dropFirst("iPhoneOS".count).dropLast(".sdk".count)+ guard !candidate.isEmpty, candidate.first?.isNumber == true else { continue }+ version = String(candidate)+ break+ }+ guard let version else { return nil }++ var sdkBuild: String?+ let sdkVersionPlist = sdksDir+ .appendingPathComponent("iPhoneOS\(version).sdk/System/Library/CoreServices/SystemVersion.plist")+ if let data = try? Data(contentsOf: sdkVersionPlist),+ let plist = try? PropertyListSerialization.propertyList(from: data, format: nil) as? [String: Any] {+ sdkBuild = plist["ProductBuildVersion"] as? String+ }++ var xcode: String?+ var xcodeBuild: String?+ let xcodeInfo = sdk.bundle.appendingPathComponent("Xcode.app/Contents/Info.plist")+ if let data = try? Data(contentsOf: xcodeInfo),+ let plist = try? PropertyListSerialization.propertyList(from: data, format: nil) as? [String: Any] {+ xcode = plist["DTXcode"] as? String+ xcodeBuild = plist["DTXcodeBuild"] as? String+ }+ return DarwinSDKInfo(version: version, sdkBuild: sdkBuild, xcode: xcode, xcodeBuild: xcodeBuild)+ }+ /// 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).@@ -291,6 +354,10 @@ extension Plan.Product { [ .unsafeFlags([ "-Xlinker", "-rpath", "-Xlinker", "@executable_path/Frameworks",+ // Decouple LC_BUILD_VERSION's minos from its sdk: the build+ // triple carries the SDK version (so App Store sees a current+ // SDK, error 90725), while this pins the deployment target.+ "-Xlinker", "-platform_version", "-Xlinker", "ios", "-Xlinker", "\(deploymentTarget)", "-Xlinker", "\(Packer.darwinSDKInfo()?.version ?? deploymentTarget)", ]), ] """
Sources/XKit/Model/Mobileprovision.swift
diff --git a/Sources/XKit/Model/Mobileprovision.swift b/Sources/XKit/Model/Mobileprovision.swiftindex 79d8819..4569668 100644--- a/Sources/XKit/Model/Mobileprovision.swift+++ b/Sources/XKit/Model/Mobileprovision.swift@@ -35,6 +35,19 @@ public final class Mobileprovision: @unchecked Sendable { case certificates = "DeveloperCertificates" case entitlements = "Entitlements" }++ public init(from decoder: Decoder) throws {+ let container = try decoder.container(keyedBy: CodingKeys.self)+ name = try container.decode(String.self, forKey: .name)+ uuid = try container.decode(String.self, forKey: .uuid)+ teamIdentifiers = try container.decode([DeveloperServicesTeam.ID].self, forKey: .teamIdentifiers)+ creationDate = try container.decode(Date.self, forKey: .creationDate)+ expirationDate = try container.decode(Date.self, forKey: .expirationDate)+ // App Store profiles have no ProvisionedDevices key.+ devices = try container.decodeIfPresent([String].self, forKey: .devices) ?? []+ certificates = try container.decode([Certificate].self, forKey: .certificates)+ entitlements = try container.decode(Entitlements.self, forKey: .entitlements)+ } } let raw: mobileprovision_t
Sources/XToolSupport/AppStoreConnect.swift
diff --git a/Sources/XToolSupport/AppStoreConnect.swift b/Sources/XToolSupport/AppStoreConnect.swiftindex c580d90..85342f8 100644--- a/Sources/XToolSupport/AppStoreConnect.swift+++ b/Sources/XToolSupport/AppStoreConnect.swift@@ -223,7 +223,6 @@ struct AppStoreConnectClient: Sendable { func uploadIPA(at ipa: URL) async throws -> UploadResult { let metadata = try await Self.ipaMetadata(at: ipa) let fileSize = try FileManager.default.attributesOfItem(atPath: ipa.path)[.size] as? Int ?? 0- let checksums = try Self.checksums(of: ipa) guard let appID = try await findAppID(bundleID: metadata.bundleID) else { throw Console.Error("No App Store Connect app found for bundle id '\(metadata.bundleID)'")@@ -233,7 +232,6 @@ struct AppStoreConnectClient: Sendable { "data": .object([ "type": .string("buildUploads"), "attributes": .object([- "cfBundleIdentifier": .string(metadata.bundleID), "cfBundleShortVersionString": .string(metadata.version), "cfBundleVersion": .string(metadata.buildNumber), "platform": .string("IOS"),@@ -251,13 +249,10 @@ struct AppStoreConnectClient: Sendable { "data": .object([ "type": .string("buildUploadFiles"), "attributes": .object([+ "assetType": .string("ASSET"), "fileName": .string(ipa.lastPathComponent), "fileSize": .number(Double(fileSize)), "uti": .string("com.apple.ipa"),- "sourceFileChecksums": .object([- "file": .object(["algorithm": .string("MD5"), "hash": .string(checksums.md5)]),- "composite": .object(["algorithm": .string("MD5"), "hash": .string(checksums.md5)]),- ]), ]), "relationships": .object([ "buildUpload": .object(["data": .object(["type": .string("buildUploads"), "id": .string(uploadID)])])@@ -271,7 +266,7 @@ struct AppStoreConnectClient: Sendable { let data = try Data(contentsOf: ipa) for operation in operations {- try await uploadChunk(operation: operation, data: data)+ _ = try await uploadChunk(operation: operation, data: data) } _ = try await request(method: "PATCH", path: "/v1/buildUploadFiles/\(fileID)", body: .object([@@ -280,36 +275,32 @@ struct AppStoreConnectClient: Sendable { "id": .string(fileID), "attributes": .object([ "uploaded": .bool(true),- "sourceFileChecksums": .object([- "file": .object(["algorithm": .string("MD5"), "hash": .string(checksums.md5)]),- "composite": .object(["algorithm": .string("MD5"), "hash": .string(checksums.md5)]),- ]), ]), ]), ]))- let finished = try await request(method: "PATCH", path: "/v1/buildUploads/\(uploadID)", body: .object([- "data": .object([- "type": .string("buildUploads"),- "id": .string(uploadID),- "attributes": .object(["uploaded": .bool(true)]),- ]),- ]))+ // Marking the file uploaded starts processing; buildUploads itself+ // does not support UPDATE, so read back its state instead.+ let finished = try await request(method: "GET", path: "/v1/buildUploads/\(uploadID)") - let state = finished["data"]?["attributes"]?["state"]?.stringValue- ?? upload["data"]?["attributes"]?["state"]?.stringValue ?? "UNKNOWN"+ let state = finished["data"]?["attributes"]?["state"]?["state"]?.stringValue+ ?? upload["data"]?["attributes"]?["state"]?["state"]?.stringValue ?? "UNKNOWN" // Apple links a Build once processing starts; surface it when present.- let linkedBuild = finished["included"]?.arrayValue?- .first { $0["type"]?.stringValue == "builds" }?["id"]?.stringValue+ let linkedBuild = finished["data"]?["relationships"]?["build"]?["data"]?["id"]?.stringValue+ ?? finished["included"]?.arrayValue?+ .first { $0["type"]?.stringValue == "builds" }?["id"]?.stringValue return UploadResult(buildID: linkedBuild ?? uploadID, state: state) } - private func uploadChunk(operation: ASCJSON, data: Data) async throws {+ /// Uploads one chunk; returns the chunk's MD5 hex digest.+ private func uploadChunk(operation: ASCJSON, data: Data) async throws -> String { guard let urlString = operation["url"]?.stringValue, let url = URL(string: urlString), let method = operation["method"]?.stringValue, let offsetJSON = operation["offset"], let lengthJSON = operation["length"], case .number(let offset) = offsetJSON, case .number(let length) = lengthJSON else { throw Console.Error("Malformed upload operation: \(operation)") }+ let chunk = data.subdata(in: Int(offset)..<Int(offset + length))+ let digest = Insecure.MD5.hash(data: chunk).map { String(format: "%02x", $0) }.joined() var request = URLRequest(url: url) request.httpMethod = method for header in operation["requestHeaders"]?.arrayValue ?? [] {@@ -317,11 +308,12 @@ struct AppStoreConnectClient: Sendable { request.setValue(value, forHTTPHeaderField: name) } }- request.httpBody = data.subdata(in: Int(offset)..<Int(offset + length))+ request.httpBody = chunk let (_, response) = try await URLSession.shared.data(for: request) guard let http = response as? HTTPURLResponse, (200..<300).contains(http.statusCode) else { throw Console.Error("Chunk upload failed: \(String(describing: response))") }+ return digest } // MARK: - Review submission@@ -359,21 +351,33 @@ struct AppStoreConnectClient: Sendable { guard let buildID = try await findBuild(appID: appID, buildNumber: buildNumber, version: version) else { throw Console.Error("No processed build '\(buildNumber)' (\(version)) found for app \(appID) yet") }+ try await ensureEncryptionDeclaration(buildID: buildID) _ = try await request(method: "PATCH", path: "/v1/appStoreVersions/\(versionID)/relationships/build", body: .object([ "data": .object(["type": .string("builds"), "id": .string(buildID)]), ])) - let submission = try await request(method: "POST", path: "/v1/reviewSubmissions", body: .object([- "data": .object([- "type": .string("reviewSubmissions"),- "attributes": .object(["platform": .string("IOS"), "submitted": .bool(false)]),- "relationships": .object([- "app": .object(["data": .object(["type": .string("apps"), "id": .string(appID)])])+ // Reuse an open submission from a previous attempt when one exists.+ let submissionID: String+ let openSubmissions = try await request(+ method: "GET", path: "/v1/apps/\(appID)/reviewSubmissions",+ query: ["filter[state]": "READY_FOR_REVIEW", "fields[reviewSubmissions]": "state,platform"]+ )+ if let existing = openSubmissions["data"]?.arrayValue?.first?["id"]?.stringValue {+ submissionID = existing+ } else {+ let submission = try await request(method: "POST", path: "/v1/reviewSubmissions", body: .object([+ "data": .object([+ "type": .string("reviewSubmissions"),+ "attributes": .object(["platform": .string("IOS")]),+ "relationships": .object([+ "app": .object(["data": .object(["type": .string("apps"), "id": .string(appID)])])+ ]), ]),- ]),- ]))- guard let submissionID = submission["data"]?["id"]?.stringValue else {- throw Console.Error("reviewSubmissions create returned no id: \(submission)")+ ]))+ guard let id = submission["data"]?["id"]?.stringValue else {+ throw Console.Error("reviewSubmissions create returned no id: \(submission)")+ }+ submissionID = id } _ = try await request(method: "POST", path: "/v1/reviewSubmissionItems", body: .object([ "data": .object([@@ -446,6 +450,24 @@ struct AppStoreConnectClient: Sendable { } } + /// App Store review requires an export-compliance answer on the build.+ /// Declares `usesNonExemptEncryption=false` (standard exempt crypto)+ /// when the build has no declaration yet.+ private func ensureEncryptionDeclaration(buildID: String) async throws {+ let build = try await request(+ method: "GET", path: "/v1/builds/\(buildID)",+ query: ["fields[builds]": "usesNonExemptEncryption"]+ )+ guard build["data"]?["attributes"]?["usesNonExemptEncryption"]?.boolValue == nil else { return }+ _ = try await request(method: "PATCH", path: "/v1/builds/\(buildID)", body: .object([+ "data": .object([+ "type": .string("builds"),+ "id": .string(buildID),+ "attributes": .object(["usesNonExemptEncryption": .bool(false)]),+ ]),+ ]))+ }+ private func findBuild(appID: String, buildNumber: String, version: String) async throws -> String? { let response = try await request( method: "GET", path: "/v1/builds",
Sources/XToolSupport/DevCommand.swift
diff --git a/Sources/XToolSupport/DevCommand.swift b/Sources/XToolSupport/DevCommand.swiftindex c3b5640..a7dfa25 100644--- a/Sources/XToolSupport/DevCommand.swift+++ b/Sources/XToolSupport/DevCommand.swift@@ -22,6 +22,17 @@ struct PackOperation { static let defaultTriple = "arm64-apple-ios" + /// Default build triple carrying the installed SDK version (e.g.+ /// `arm64-apple-ios27.1`), so the Mach-O `LC_BUILD_VERSION` records a+ /// current SDK (App Store error 90725). The deployment target is pinned+ /// separately at link time (see `Plan.Product.linkerSettings`).+ static var sdkVersionedDefaultTriple: String {+ if let sdk = Packer.darwinSDKInfo() {+ return "arm64-apple-ios\(sdk.version)"+ }+ return defaultTriple+ }+ var triple: String? var buildOptions = BuildOptions(configuration: .debug) var xcode = false@@ -57,7 +68,7 @@ struct PackOperation { let buildSettings = try await BuildSettings( configuration: buildOptions.configuration,- triple: triple ?? Self.defaultTriple,+ triple: triple ?? Self.sdkVersionedDefaultTriple, options: [] )
Sources/XToolSupport/DistributionSigning.swift
diff --git a/Sources/XToolSupport/DistributionSigning.swift b/Sources/XToolSupport/DistributionSigning.swiftindex ccac216..9c2b848 100644--- a/Sources/XToolSupport/DistributionSigning.swift+++ b/Sources/XToolSupport/DistributionSigning.swift@@ -145,9 +145,13 @@ enum DistributionSigning { $0.links.next }.map(\.data).reduce(into: [], +=) for profile in profiles {+ // The list response omits relationships unless included, so the+ // deterministic name we create with is the reliable reuse key.+ let isOurs = profile.attributes?.name == "xtool app-store \(bundleID)"+ let matchesBundle = profile.relationships?.bundleId?.data?.id == bundleResource.id guard profile.attributes?.profileType?.value1 == .iosAppStore, profile.attributes?.profileState?.value1 == .active,- profile.relationships?.bundleId?.data?.id == bundleResource.id,+ isOurs || matchesBundle, let content = profile.attributes?.profileContent, let data = Data(base64Encoded: content) else { continue } return try Mobileprovision(data: data)