Skip to content

Commit ee81927

Browse files
authored
[Release Tooling] Consistent approach to resources when building on Xcode 15 (#12821)
1 parent 14178e2 commit ee81927

File tree

3 files changed

+43
-46
lines changed

3 files changed

+43
-46
lines changed

FirebaseInAppMessaging/Sources/DefaultUI/FIRIAMDefaultDisplayImpl.m

+10-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,16 @@ + (NSBundle *)getViewResourceBundle {
6767
NSBundle *containingBundle;
6868
NSURL *bundleURL;
6969
// The containing bundle is different whether FIAM is statically or dynamically linked.
70-
for (containingBundle in @[ [NSBundle mainBundle], [NSBundle bundleForClass:myClass] ]) {
70+
for (containingBundle in @[
71+
// Statically linked.
72+
[NSBundle mainBundle],
73+
// Dynamically linked.
74+
[NSBundle bundleForClass:myClass],
75+
// Embedded static framework (zip distribution).
76+
[NSBundle bundleWithURL:[NSBundle.mainBundle.bundleURL
77+
URLByAppendingPathComponent:
78+
@"Frameworks/FirebaseInAppMessaging.framework"]]
79+
]) {
7180
bundleURL = [containingBundle URLForResource:bundledResource withExtension:@"bundle"];
7281
if (bundleURL != nil) break;
7382
}

ReleaseTooling/Sources/ZipBuilder/FrameworkBuilder.swift

+27-34
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,33 @@ struct FrameworkBuilder {
651651
platform == .catalyst || platform == .macOS ? "Resources" : ""
652652
)
653653
.resolvingSymlinksInPath()
654-
processPrivacyManifests(fileManager, frameworkPath, resourceDir)
654+
655+
// Move resource bundles into the platform framework.
656+
do {
657+
try fileManager.contentsOfDirectory(
658+
at: frameworkPath.deletingLastPathComponent(),
659+
includingPropertiesForKeys: nil
660+
)
661+
.filter { $0.pathExtension == "bundle" }
662+
// Bundles are moved rather than copied to prevent them from being
663+
// packaged in a `Resources` directory at the root of the xcframework.
664+
.forEach {
665+
// Delete `gRPCCertificates-Cpp.bundle` since it is not needed (#9184).
666+
guard $0.lastPathComponent != "gRPCCertificates-Cpp.bundle" else {
667+
try fileManager.removeItem(at: $0)
668+
return
669+
}
670+
671+
try fileManager.moveItem(
672+
at: $0,
673+
to: resourceDir.appendingPathComponent($0.lastPathComponent)
674+
)
675+
}
676+
} catch {
677+
fatalError(
678+
"Could not move resources for framework \(frameworkPath), platform \(platform). Error: \(error)"
679+
)
680+
}
655681

656682
// Use the appropriate moduleMaps
657683
packageModuleMaps(inFrameworks: [frameworkPath],
@@ -663,39 +689,6 @@ struct FrameworkBuilder {
663689
}
664690
}
665691

666-
/// Process privacy manifests.
667-
///
668-
/// Move any privacy manifest-containing resource bundles into the platform framework.
669-
func processPrivacyManifests(_ fileManager: FileManager,
670-
_ frameworkPath: URL,
671-
_ platformFrameworkDir: URL) {
672-
try? fileManager.contentsOfDirectory(
673-
at: frameworkPath.deletingLastPathComponent(),
674-
includingPropertiesForKeys: nil
675-
)
676-
.filter { $0.pathExtension == "bundle" }
677-
// TODO(ncooke3): Once the zip is built with Xcode 15, the following
678-
// `filter` can be removed. The following block exists to preserve
679-
// how resources (e.g. like FIAM's) are packaged for use in Xcode 14.
680-
.filter { bundleURL in
681-
let dirEnum = fileManager.enumerator(atPath: bundleURL.path)
682-
var containsPrivacyManifest = false
683-
while let relativeFilePath = dirEnum?.nextObject() as? String {
684-
if relativeFilePath.hasSuffix("PrivacyInfo.xcprivacy") {
685-
containsPrivacyManifest = true
686-
break
687-
}
688-
}
689-
return containsPrivacyManifest
690-
}
691-
// Bundles are moved rather than copied to prevent them from being
692-
// packaged in a `Resources` directory at the root of the xcframework.
693-
.forEach { try! fileManager.moveItem(
694-
at: $0,
695-
to: platformFrameworkDir.appendingPathComponent($0.lastPathComponent)
696-
) }
697-
}
698-
699692
/// Package the built frameworks into an XCFramework.
700693
/// - Parameter withName: The framework name.
701694
/// - Parameter frameworks: The grouped frameworks.

ReleaseTooling/Template/README.md

+6-11
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,7 @@ To integrate a Firebase SDK with your app:
4949
**Embed & Sign**. This step will enable privacy manifests to be picked up by
5050
Xcode's tooling.
5151

52-
8. If the SDK has resources, go into the Resources folders, which will be in
53-
the SDK folder. Drag all of those resources into the Project Navigator, just
54-
like the frameworks, again making sure that the target you want to add these
55-
resources to has a checkmark next to it, and that you've selected "Copy items
56-
if needed".
57-
9. Add the `-ObjC` flag to **Other Linker Settings**:
52+
8. Add the `-ObjC` flag to **Other Linker Settings**:
5853

5954
a. In your project settings, open the **Settings** panel for your target.
6055

@@ -63,7 +58,7 @@ To integrate a Firebase SDK with your app:
6358

6459
c. Double-click the setting, click the '+' button, and add `-ObjC`
6560

66-
10. Add the `-lc++` flag to **Other Linker Settings**:
61+
9. Add the `-lc++` flag to **Other Linker Settings**:
6762

6863
a. In your project settings, open the **Settings** panel for your target.
6964

@@ -72,21 +67,21 @@ To integrate a Firebase SDK with your app:
7267

7368
c. Double-click the setting, click the '+' button, and add `-lc++`
7469

75-
11. Drag the `Firebase.h` header in this directory into your project. This will
70+
10. Drag the `Firebase.h` header in this directory into your project. This will
7671
allow you to `#import "Firebase.h"` and start using any Firebase SDK that you
7772
have.
78-
12. Drag `module.modulemap` into your project and update the
73+
11. Drag `module.modulemap` into your project and update the
7974
"User Header Search Paths" in your project's Build Settings to include the
8075
directory that contains the added module map.
81-
13. If your app does not include any Swift implementation, you may need to add
76+
12. If your app does not include any Swift implementation, you may need to add
8277
a dummy Swift file to the app to prevent Swift system library missing
8378
symbol linker errors. See
8479
https://forums.swift.org/t/using-binary-swift-sdks-from-non-swift-apps/55989.
8580

8681
> ⚠ If prompted with the option to create a corresponding bridging header
8782
> for the new Swift file, select **Don't create**.
8883
89-
14. You're done! Build your target and start using Firebase.
84+
13. You're done! Build your target and start using Firebase.
9085

9186
If you want to add another SDK, repeat the steps above with the xcframeworks for
9287
the new SDK. You only need to add each framework once, so if you've already

0 commit comments

Comments
 (0)