Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 42 additions & 41 deletions ReleaseTooling/Sources/ZipBuilder/FrameworkBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,6 @@ struct FrameworkBuilder {
}
umbrellaHeader = umbrellaHeaderURL.lastPathComponent
}
// Add an Info.plist. Required by Carthage and SPM binary xcframeworks.
CarthageUtils.generatePlistContents(forName: frameworkName,
withVersion: podInfo.version,
to: frameworkDir)

// TODO: copy PrivateHeaders directory as well if it exists. SDWebImage is an example pod.

Expand Down Expand Up @@ -639,33 +635,7 @@ struct FrameworkBuilder {
"\(framework): \(error)")
}

// Move any privacy manifest-containing resource bundles into the
// platform framework.
try? fileManager.contentsOfDirectory(
at: frameworkPath.deletingLastPathComponent(),
includingPropertiesForKeys: nil
)
.filter { $0.pathExtension == "bundle" }
// TODO(ncooke3): Once the zip is built with Xcode 15, the following
// `filter` can be removed. The following block exists to preserve
// how resources (e.g. like FIAM's) are packaged for use in Xcode 14.
.filter { bundleURL in
let dirEnum = fileManager.enumerator(atPath: bundleURL.path)
var containsPrivacyManifest = false
while let relativeFilePath = dirEnum?.nextObject() as? String {
if relativeFilePath.hasSuffix("PrivacyInfo.xcprivacy") {
containsPrivacyManifest = true
break
}
}
return containsPrivacyManifest
}
// Bundles are moved rather than copied to prevent them from being
// packaged in a `Resources` directory at the root of the xcframework.
.forEach { try! fileManager.moveItem(
at: $0,
to: platformFrameworkDir.appendingPathComponent($0.lastPathComponent)
) }
processPrivacyManifests(fileManager, frameworkPath, platformFrameworkDir)

// Headers from slice
do {
Expand All @@ -688,25 +658,23 @@ struct FrameworkBuilder {
fatalError("Could not create framework directory needed to build \(framework): \(error)")
}

// Info.plist from `fromFolder`
do {
let infoPlistSrc = fromFolder.appendingPathComponent("Info.plist").resolvingSymlinksInPath()
let infoPlistDst = platformFrameworkDir.appendingPathComponent("Info.plist")
try fileManager.copyItem(at: infoPlistSrc, to: infoPlistDst)
} catch {
fatalError("Could not create framework directory needed to build \(framework): \(error)")
}

// Copy the binary to the right location.
// Copy the binary and Info.plist to the right location.
let binaryName = frameworkPath.lastPathComponent.replacingOccurrences(of: ".framework",
with: "")
let fatBinary = frameworkPath.appendingPathComponent(binaryName).resolvingSymlinksInPath()
let infoPlist = frameworkPath.appendingPathComponent("Info.plist").resolvingSymlinksInPath()
let infoPlistDestination = platformFrameworkDir.appendingPathComponent("Info.plist")
let fatBinaryDestination = platformFrameworkDir.appendingPathComponent(framework)
do {
try fileManager.copyItem(at: fatBinary, to: fatBinaryDestination)
} catch {
fatalError("Could not copy fat binary to framework directory for \(framework): \(error)")
}
do {
try fileManager.copyItem(at: infoPlist, to: infoPlistDestination)
} catch {
// The Catalyst and macos Info.plist's are in another location. Ignore failure.
}

// Use the appropriate moduleMaps
packageModuleMaps(inFrameworks: [frameworkPath],
Expand All @@ -719,6 +687,39 @@ struct FrameworkBuilder {
return frameworksBuilt
}

/// Process privacy manifests.
///
/// Move any privacy manifest-containing resource bundles into the platform framework.
func processPrivacyManifests(_ fileManager: FileManager,
_ frameworkPath: URL,
_ platformFrameworkDir: URL) {
try? fileManager.contentsOfDirectory(
at: frameworkPath.deletingLastPathComponent(),
includingPropertiesForKeys: nil
)
.filter { $0.pathExtension == "bundle" }
// TODO(ncooke3): Once the zip is built with Xcode 15, the following
// `filter` can be removed. The following block exists to preserve
// how resources (e.g. like FIAM's) are packaged for use in Xcode 14.
.filter { bundleURL in
let dirEnum = fileManager.enumerator(atPath: bundleURL.path)
var containsPrivacyManifest = false
while let relativeFilePath = dirEnum?.nextObject() as? String {
if relativeFilePath.hasSuffix("PrivacyInfo.xcprivacy") {
containsPrivacyManifest = true
break
}
}
return containsPrivacyManifest
}
// Bundles are moved rather than copied to prevent them from being
// packaged in a `Resources` directory at the root of the xcframework.
.forEach { try! fileManager.moveItem(
at: $0,
to: platformFrameworkDir.appendingPathComponent($0.lastPathComponent)
) }
}

/// Package the built frameworks into an XCFramework.
/// - Parameter withName: The framework name.
/// - Parameter frameworks: The grouped frameworks.
Expand Down