Skip to content

Commit 2c03297

Browse files
authored
Handle new cert bundle name in gRPC-C++ (#3037)
* Bump to gRPC-C++ 0.0.9 This release includes grpc/grpc#19082 which changes the certificate bundle name to make it possible to have voth gRPC-C++ and gRPC in the same project. * Defer loading bundles until needed. * Handle certificante bundle rename in gRPC-C++ 0.0.9
1 parent 7e798c5 commit 2c03297

File tree

2 files changed

+53
-26
lines changed

2 files changed

+53
-26
lines changed

FirebaseFirestore.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Google Cloud Firestore is a NoSQL document database built for automatic scaling,
5353

5454
s.dependency 'FirebaseAuthInterop', '~> 1.0'
5555
s.dependency 'FirebaseCore', '~> 6.0'
56-
s.dependency 'gRPC-C++', '0.0.8'
56+
s.dependency 'gRPC-C++', '0.0.9'
5757
s.dependency 'leveldb-library', '~> 1.20'
5858
s.dependency 'Protobuf', '~> 3.1'
5959
s.dependency 'nanopb', '~> 0.3.901'

Firestore/core/src/firebase/firestore/remote/grpc_root_certificate_finder_apple.mm

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,48 @@
6767
/**
6868
* Finds gRPCCertificates.bundle inside the given parent, if it exists.
6969
*
70-
* This function exists mostly to handle differences in platforms.
71-
* On iOS, resources are nested directly within the top-level of the parent
72-
* bundle, but on macOS this will actually be in Contents/Resources.
70+
* This function exists mostly to handle differences in platforms. On iOS,
71+
* resources are nested directly within the top-level of the parent bundle, but
72+
* on macOS this will actually be in Contents/Resources.
7373
*
7474
* @param parent A framework or app bundle to check.
7575
* @return The nested gRPCCertificates.bundle if found, otherwise nil.
7676
*/
7777
NSBundle* _Nullable FindCertBundleInParent(NSBundle* _Nullable parent) {
7878
if (!parent) return nil;
7979

80-
NSString* path = [parent pathForResource:@"gRPCCertificates"
81-
ofType:@"bundle"];
82-
if (!path) return nil;
80+
static NSString* const bundle_names[] = {
81+
// gRPC-C++ 0.0.9 changed the name of the resource bundle to allow it to
82+
// coexist with Objective-C gRPC.
83+
@"gRPCCertificates-Cpp",
8384

84-
return [[NSBundle alloc] initWithPath:path];
85+
// Older gRPC-C++ or Objective-C gRPC use this name.
86+
@"gRPCCertificates",
87+
};
88+
89+
for (NSString* bundle_name : bundle_names) {
90+
NSString* path = [parent pathForResource:bundle_name ofType:@"bundle"];
91+
if (path) {
92+
return [[NSBundle alloc] initWithPath:path];
93+
}
94+
}
95+
96+
return nil;
97+
}
98+
99+
using BundleLoader = NSBundle* _Nullable (*)(void);
100+
101+
// CocoaPods: try to load from the gRPC-C++ Framework.
102+
NSBundle* _Nullable FindGrpcCppFrameworkBundle() {
103+
return [NSBundle bundleWithIdentifier:@"org.cocoapods.grpcpp"];
104+
}
105+
106+
// CocoaPods: also allow loading from the Objective-C gRPC Framework.
107+
NSBundle* _Nullable FindGrpcObjcFrameworkBundle() {
108+
return [NSBundle bundleWithIdentifier:@"org.cocoapods.GRPCClient"];
85109
}
86110

111+
// Carthage: try to load from the FirebaseFirestore.framework
87112
NSBundle* _Nullable FindFirestoreFrameworkBundle() {
88113
// Load FIRFirestore reflectively to avoid a circular reference at build time.
89114
Class firestore_class = objc_getClass("FIRFirestore");
@@ -92,34 +117,36 @@
92117
return [NSBundle bundleForClass:firestore_class];
93118
}
94119

120+
// Carthage and manual projects: users manually adding resources to the project
121+
// may add the certificate to the main application bundle. Note that
122+
// `mainBundle` is nil for unit tests of library projects.
123+
NSBundle* _Nullable FindMainBundle() {
124+
return [NSBundle mainBundle];
125+
}
126+
95127
/**
96128
* Finds the path to the roots.pem certificates file, wherever it may be.
97129
*
98-
* Carthage users will find roots.pem inside gRPCCertificates.bundle in
99-
* the main bundle.
130+
* Carthage users will find roots.pem inside gRPCCertificates.bundle in the
131+
* main bundle.
100132
*
101-
* There have been enough variations and workarounds posted on this that
102-
* this also accepts the roots.pem file outside gRPCCertificates.bundle.
133+
* There have been enough variations and workarounds posted on this that this
134+
* also accepts the roots.pem file outside gRPCCertificates.bundle.
103135
*/
104136
NSString* FindPathToCertificatesFile() {
105-
// Certificates file might be present in either the gRPC-C++ framework or (for
106-
// some projects) in the main bundle.
107-
NSBundle* bundles[] = {
108-
// CocoaPods: try to load from the gRPC-C++ Framework.
109-
[NSBundle bundleWithIdentifier:@"org.cocoapods.grpcpp"],
110-
111-
// Carthage: try to load from the FirebaseFirestore.framework
112-
FindFirestoreFrameworkBundle(),
113-
114-
// Carthage and manual projects: users manually adding resources to the
115-
// project may add the certificate to the main application bundle. Note
116-
// that `mainBundle` is nil for unit tests of library projects.
117-
[NSBundle mainBundle],
137+
// Certificates file might be present in gRPC frameworks, Firestore, or the
138+
// main bundle.
139+
static BundleLoader loaders[] = {
140+
FindGrpcCppFrameworkBundle,
141+
FindGrpcObjcFrameworkBundle,
142+
FindFirestoreFrameworkBundle,
143+
FindMainBundle,
118144
};
119145

120146
NSString* path = nil;
121147

122-
for (NSBundle* parent : bundles) {
148+
for (BundleLoader loader : loaders) {
149+
NSBundle* parent = loader();
123150
if (!parent) continue;
124151

125152
NSBundle* certs_bundle = FindCertBundleInParent(parent);

0 commit comments

Comments
 (0)