Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid loading xcframeworks as Bundles #3213

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 10 additions & 11 deletions Source/XCDBLD/FrameworkBundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,24 @@ import Result
/// - parameter platformName: If given, only sends bundles from an XCFramework with a matching `SupportedPlatform`.
/// - parameter variant: If given along with `platformName`, only sends bundles from an XCFramework with a matching `SupportedPlatformVariant`.
public func frameworkBundlesInURL(_ url: URL, compatibleWith platformName: String? = nil, variant: String? = nil) -> SignalProducer<Bundle, DecodingError> {
guard let bundle = Bundle(url: url) else {
return .empty
}

switch bundle.object(forInfoDictionaryKey: "CFBundlePackageType") as? String {
case "XFWK":
switch url.pathExtension {
case "xcframework":
elliottwilliams marked this conversation as resolved.
Show resolved Hide resolved
let decoder = PropertyListDecoder()
let infoData = bundle.infoDictionary.flatMap({ try? PropertyListSerialization.data(fromPropertyList: $0, format: .binary, options: 0) }) ?? Data()
let xcframework = Result<XCFramework, DecodingError>(catching: { try decoder.decode(XCFramework.self, from: infoData) })
return SignalProducer(result: xcframework)

return SignalProducer(value: url.appendingPathComponent("Info.plist"))
.attemptMap { try Data(contentsOf: $0) }
.attemptMap { try decoder.decode(XCFramework.self, from: $0) }
.mapError { $0.error as? DecodingError ?? .dataCorrupted(.init(codingPath: [], debugDescription: $0.description)) }
.map({ $0.availableLibraries }).flatten()
.filter { library in
guard let platformName = platformName else { return true }
return library.supportedPlatform == platformName && library.supportedPlatformVariant == variant
}
.map({ Bundle(url: url.appendingPathComponent($0.identifier).appendingPathComponent($0.path)) })
.skipNil()
default: // Typically "FMWK" but not required
return SignalProducer(value: bundle)
default:
return SignalProducer(value: Bundle(url: url))
.skipNil()
}
}

Expand Down