Skip to content

Commit 134e7f2

Browse files
authored
[binary] Use Xcode built Info.plist's (#12414)
1 parent 46f0421 commit 134e7f2

File tree

1 file changed

+42
-41
lines changed

1 file changed

+42
-41
lines changed

ReleaseTooling/Sources/ZipBuilder/FrameworkBuilder.swift

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,6 @@ struct FrameworkBuilder {
380380
}
381381
umbrellaHeader = umbrellaHeaderURL.lastPathComponent
382382
}
383-
// Add an Info.plist. Required by Carthage and SPM binary xcframeworks.
384-
CarthageUtils.generatePlistContents(forName: frameworkName,
385-
withVersion: podInfo.version,
386-
to: frameworkDir)
387383

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

@@ -639,33 +635,7 @@ struct FrameworkBuilder {
639635
"\(framework): \(error)")
640636
}
641637

642-
// Move any privacy manifest-containing resource bundles into the
643-
// platform framework.
644-
try? fileManager.contentsOfDirectory(
645-
at: frameworkPath.deletingLastPathComponent(),
646-
includingPropertiesForKeys: nil
647-
)
648-
.filter { $0.pathExtension == "bundle" }
649-
// TODO(ncooke3): Once the zip is built with Xcode 15, the following
650-
// `filter` can be removed. The following block exists to preserve
651-
// how resources (e.g. like FIAM's) are packaged for use in Xcode 14.
652-
.filter { bundleURL in
653-
let dirEnum = fileManager.enumerator(atPath: bundleURL.path)
654-
var containsPrivacyManifest = false
655-
while let relativeFilePath = dirEnum?.nextObject() as? String {
656-
if relativeFilePath.hasSuffix("PrivacyInfo.xcprivacy") {
657-
containsPrivacyManifest = true
658-
break
659-
}
660-
}
661-
return containsPrivacyManifest
662-
}
663-
// Bundles are moved rather than copied to prevent them from being
664-
// packaged in a `Resources` directory at the root of the xcframework.
665-
.forEach { try! fileManager.moveItem(
666-
at: $0,
667-
to: platformFrameworkDir.appendingPathComponent($0.lastPathComponent)
668-
) }
638+
processPrivacyManifests(fileManager, frameworkPath, platformFrameworkDir)
669639

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

691-
// Info.plist from `fromFolder`
692-
do {
693-
let infoPlistSrc = fromFolder.appendingPathComponent("Info.plist").resolvingSymlinksInPath()
694-
let infoPlistDst = platformFrameworkDir.appendingPathComponent("Info.plist")
695-
try fileManager.copyItem(at: infoPlistSrc, to: infoPlistDst)
696-
} catch {
697-
fatalError("Could not create framework directory needed to build \(framework): \(error)")
698-
}
699-
700-
// Copy the binary to the right location.
661+
// Copy the binary and Info.plist to the right location.
701662
let binaryName = frameworkPath.lastPathComponent.replacingOccurrences(of: ".framework",
702663
with: "")
703664
let fatBinary = frameworkPath.appendingPathComponent(binaryName).resolvingSymlinksInPath()
665+
let infoPlist = frameworkPath.appendingPathComponent("Info.plist").resolvingSymlinksInPath()
666+
let infoPlistDestination = platformFrameworkDir.appendingPathComponent("Info.plist")
704667
let fatBinaryDestination = platformFrameworkDir.appendingPathComponent(framework)
705668
do {
706669
try fileManager.copyItem(at: fatBinary, to: fatBinaryDestination)
707670
} catch {
708671
fatalError("Could not copy fat binary to framework directory for \(framework): \(error)")
709672
}
673+
do {
674+
try fileManager.copyItem(at: infoPlist, to: infoPlistDestination)
675+
} catch {
676+
// The Catalyst and macos Info.plist's are in another location. Ignore failure.
677+
}
710678

711679
// Use the appropriate moduleMaps
712680
packageModuleMaps(inFrameworks: [frameworkPath],
@@ -719,6 +687,39 @@ struct FrameworkBuilder {
719687
return frameworksBuilt
720688
}
721689

690+
/// Process privacy manifests.
691+
///
692+
/// Move any privacy manifest-containing resource bundles into the platform framework.
693+
func processPrivacyManifests(_ fileManager: FileManager,
694+
_ frameworkPath: URL,
695+
_ platformFrameworkDir: URL) {
696+
try? fileManager.contentsOfDirectory(
697+
at: frameworkPath.deletingLastPathComponent(),
698+
includingPropertiesForKeys: nil
699+
)
700+
.filter { $0.pathExtension == "bundle" }
701+
// TODO(ncooke3): Once the zip is built with Xcode 15, the following
702+
// `filter` can be removed. The following block exists to preserve
703+
// how resources (e.g. like FIAM's) are packaged for use in Xcode 14.
704+
.filter { bundleURL in
705+
let dirEnum = fileManager.enumerator(atPath: bundleURL.path)
706+
var containsPrivacyManifest = false
707+
while let relativeFilePath = dirEnum?.nextObject() as? String {
708+
if relativeFilePath.hasSuffix("PrivacyInfo.xcprivacy") {
709+
containsPrivacyManifest = true
710+
break
711+
}
712+
}
713+
return containsPrivacyManifest
714+
}
715+
// Bundles are moved rather than copied to prevent them from being
716+
// packaged in a `Resources` directory at the root of the xcframework.
717+
.forEach { try! fileManager.moveItem(
718+
at: $0,
719+
to: platformFrameworkDir.appendingPathComponent($0.lastPathComponent)
720+
) }
721+
}
722+
722723
/// Package the built frameworks into an XCFramework.
723724
/// - Parameter withName: The framework name.
724725
/// - Parameter frameworks: The grouped frameworks.

0 commit comments

Comments
 (0)