Skip to content

Commit 943141e

Browse files
authored
Use registerLibrary for pods in Firebase workspace (#2137)
* Add versioning to Functions and convert to FIRLibrary * Convert Firestore to FIRLibrary * Point travis to FirebaseCore pre-release for its deps * Update user agent strings to match spec
1 parent b7d4594 commit 943141e

31 files changed

+213
-204
lines changed

Example/Auth/Tests/FIRAuthTests.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#import <FirebaseAuthInterop/FIRAuthInterop.h>
2222
#import <FirebaseCore/FIRAppInternal.h>
2323
#import <FirebaseCore/FIRComponent.h>
24-
#import <FirebaseCore/FIRComponentRegistrant.h>
24+
#import <FirebaseCore/FIRLibrary.h>
2525

2626
#import "FIRAdditionalUserInfo.h"
2727
#import "FIRAuth_Internal.h"
@@ -225,7 +225,7 @@
225225
static const NSTimeInterval kWaitInterval = .5;
226226

227227
/** Category for FIRAuth to expose FIRComponentRegistrant conformance. */
228-
@interface FIRAuth () <FIRComponentRegistrant>
228+
@interface FIRAuth () <FIRLibrary>
229229
@end
230230

231231
/** @class FIRAuthTests

Example/Core/Tests/FIRAppTest.m

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
#import "FIRTestCase.h"
16+
#import "FIRTestComponents.h"
1617

1718
#import <FirebaseCore/FIRAnalyticsConfiguration+Internal.h>
1819
#import <FirebaseCore/FIRAppInternal.h>
@@ -714,25 +715,38 @@ - (void)testIsDefaultAppConfigured {
714715
XCTAssertFalse([FIRApp isDefaultAppConfigured]);
715716
}
716717

717-
- (void)testIllegalLibraryName {
718+
- (void)testInvalidLibraryName {
718719
[FIRApp registerLibrary:@"Oops>" withVersion:@"1.0.0"];
719720
XCTAssertTrue([[FIRApp firebaseUserAgent] isEqualToString:@""]);
720721
}
721722

722-
- (void)testIllegalLibraryVersion {
723-
[FIRApp registerLibrary:@"LegalName" withVersion:@"1.0.0+"];
723+
- (void)testInvalidLibraryVersion {
724+
[FIRApp registerLibrary:@"ValidName" withVersion:@"1.0.0+"];
724725
XCTAssertTrue([[FIRApp firebaseUserAgent] isEqualToString:@""]);
725726
}
726727

727728
- (void)testSingleLibrary {
728-
[FIRApp registerLibrary:@"LegalName" withVersion:@"1.0.0"];
729-
XCTAssertTrue([[FIRApp firebaseUserAgent] containsString:@"LegalName/1.0.0"]);
729+
[FIRApp registerLibrary:@"ValidName" withVersion:@"1.0.0"];
730+
XCTAssertTrue([[FIRApp firebaseUserAgent] containsString:@"ValidName/1.0.0"]);
730731
}
731732

732733
- (void)testMultipleLibraries {
733-
[FIRApp registerLibrary:@"LegalName" withVersion:@"1.0.0"];
734-
[FIRApp registerLibrary:@"LegalName2" withVersion:@"2.0.0"];
735-
XCTAssertTrue([[FIRApp firebaseUserAgent] containsString:@"LegalName/1.0.0 LegalName2/2.0.0"]);
734+
[FIRApp registerLibrary:@"ValidName" withVersion:@"1.0.0"];
735+
[FIRApp registerLibrary:@"ValidName2" withVersion:@"2.0.0"];
736+
XCTAssertTrue([[FIRApp firebaseUserAgent] containsString:@"ValidName/1.0.0 ValidName2/2.0.0"]);
737+
}
738+
739+
- (void)testRegisteringConformingLibrary {
740+
Class testClass = [FIRTestClass class];
741+
[FIRApp registerInternalLibrary:testClass withName:@"ValidName" withVersion:@"1.0.0"];
742+
XCTAssertTrue([[FIRApp firebaseUserAgent] containsString:@"ValidName/1.0.0"]);
743+
}
744+
745+
- (void)testRegisteringNonConformingLibrary {
746+
XCTAssertThrows([FIRApp registerInternalLibrary:[NSString class]
747+
withName:@"InvalidLibrary"
748+
withVersion:@"1.0.0"]);
749+
XCTAssertFalse([[FIRApp firebaseUserAgent] containsString:@"InvalidLibrary`/1.0.0"]);
736750
}
737751

738752
#pragma mark - private

Example/Core/Tests/FIRComponentContainerTest.m

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,26 @@ @interface FIRComponentContainer (TestInternal)
2626
@property(nonatomic, strong) NSMutableDictionary<NSString *, FIRComponentCreationBlock> *components;
2727
@property(nonatomic, strong) NSMutableDictionary<NSString *, id> *cachedInstances;
2828

29-
+ (void)registerAsComponentRegistrant:(Class)klass inSet:(NSMutableSet<Class> *)allRegistrants;
30-
29+
+ (void)registerAsComponentRegistrant:(Class<FIRLibrary>)klass
30+
inSet:(NSMutableSet<Class> *)allRegistrants;
3131
- (instancetype)initWithApp:(FIRApp *)app registrants:(NSMutableSet<Class> *)allRegistrants;
32+
@end
33+
34+
@interface FIRComponentContainer (TestInternalImplementations)
35+
- (instancetype)initWithApp:(FIRApp *)app
36+
components:(NSDictionary<NSString *, FIRComponentCreationBlock> *)components;
37+
@end
38+
39+
@implementation FIRComponentContainer (TestInternalImplementations)
40+
41+
- (instancetype)initWithApp:(FIRApp *)app
42+
components:(NSDictionary<NSString *, FIRComponentCreationBlock> *)components {
43+
self = [self initWithApp:app registrants:[[NSMutableSet alloc] init]];
44+
if (self) {
45+
self.components = [components mutableCopy];
46+
}
47+
return self;
48+
}
3249

3350
@end
3451

@@ -47,13 +64,6 @@ - (void)testRegisteringConformingClass {
4764
XCTAssertTrue([allRegistrants containsObject:testClass]);
4865
}
4966

50-
- (void)testRegisteringNonConformingClass {
51-
NSMutableSet<Class> *allRegistrants = [NSMutableSet<Class> set];
52-
XCTAssertThrows(
53-
[FIRComponentContainer registerAsComponentRegistrant:[NSString class] inSet:allRegistrants]);
54-
XCTAssertTrue(allRegistrants.count == 0);
55-
}
56-
5767
- (void)testComponentsPopulatedOnInit {
5868
FIRComponentContainer *container = [self containerWithRegistrants:@ [[FIRTestClass class]]];
5969

@@ -149,7 +159,6 @@ - (FIRComponentContainer *)containerWithRegistrants:(NSArray<Class> *)registrant
149159
for (Class c in registrants) {
150160
[FIRComponentContainer registerAsComponentRegistrant:c inSet:allRegistrants];
151161
}
152-
153162
return [[FIRComponentContainer alloc] initWithApp:appMock registrants:allRegistrants];
154163
}
155164

Example/Core/Tests/FIRTestComponents.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#import <FirebaseCore/FIRComponent.h>
1818
#import <FirebaseCore/FIRComponentContainer.h>
19-
#import <FirebaseCore/FIRComponentRegistrant.h>
19+
#import <FirebaseCore/FIRLibrary.h>
2020

2121
@protocol FIRComponentRegistrant;
2222

@@ -28,13 +28,12 @@
2828
@end
2929

3030
/// A test class that is a component registrant.
31-
@interface FIRTestClass
32-
: NSObject <FIRTestProtocol, FIRComponentRegistrant, FIRComponentLifecycleMaintainer>
31+
@interface FIRTestClass : NSObject <FIRTestProtocol, FIRComponentLifecycleMaintainer, FIRLibrary>
3332
@end
3433

3534
/// A test class that is a component registrant, a duplicate of FIRTestClass.
3635
@interface FIRTestClassDuplicate
37-
: NSObject <FIRTestProtocol, FIRComponentRegistrant, FIRComponentLifecycleMaintainer>
36+
: NSObject <FIRTestProtocol, FIRComponentLifecycleMaintainer, FIRLibrary>
3837
@end
3938

4039
#pragma mark - Eager Component
@@ -47,7 +46,7 @@
4746
/// A test class that is a component registrant that provides a component requiring eager
4847
/// instantiation, and is cached for easier validation that it was instantiated.
4948
@interface FIRTestClassEagerCached
50-
: NSObject <FIRTestProtocolEagerCached, FIRComponentRegistrant, FIRComponentLifecycleMaintainer>
49+
: NSObject <FIRTestProtocol, FIRComponentLifecycleMaintainer, FIRLibrary>
5150
@end
5251

5352
#pragma mark - Cached Component
@@ -59,5 +58,5 @@
5958
/// A test class that is a component registrant that provides a component that requests to be
6059
/// cached.
6160
@interface FIRTestClassCached
62-
: NSObject <FIRTestProtocolCached, FIRComponentRegistrant, FIRComponentLifecycleMaintainer>
61+
: NSObject <FIRTestProtocol, FIRComponentLifecycleMaintainer, FIRLibrary>
6362
@end

Example/Core/Tests/FIRTestComponents.m

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ @implementation FIRTestClassDuplicate
4747
- (void)doSomething {
4848
}
4949

50-
/// FIRComponentRegistrant conformance.
50+
/// FIRLibrary conformance.
5151
+ (nonnull NSArray<FIRComponent *> *)componentsToRegister {
5252
FIRComponent *testComponent =
5353
[FIRComponent componentWithProtocol:@protocol(FIRTestProtocol)
@@ -72,7 +72,7 @@ @implementation FIRTestClassEagerCached
7272
- (void)doSomethingFaster {
7373
}
7474

75-
/// FIRComponentRegistrant conformance.
75+
/// FIRLibrary conformance.
7676
+ (nonnull NSArray<FIRComponent *> *)componentsToRegister {
7777
FIRComponent *testComponent = [FIRComponent
7878
componentWithProtocol:@protocol(FIRTestProtocolEagerCached)
@@ -92,13 +92,16 @@ - (void)doSomethingFaster {
9292
- (void)appWillBeDeleted:(FIRApp *)app {
9393
}
9494

95+
- (void)doSomething {
96+
}
97+
9598
@end
9699

97100
#pragma mark - Cached Component
98101

99102
@implementation FIRTestClassCached
100103

101-
/// FIRComponentRegistrant conformance.
104+
/// FIRLibrary conformance.
102105
+ (nonnull NSArray<FIRComponent *> *)componentsToRegister {
103106
FIRComponent *testComponent = [FIRComponent
104107
componentWithProtocol:@protocol(FIRTestProtocolCached)
@@ -115,4 +118,7 @@ @implementation FIRTestClassCached
115118
- (void)appWillBeDeleted:(FIRApp *)app {
116119
}
117120

121+
- (void)doSomething {
122+
}
123+
118124
@end

Example/Database/Tests/Helpers/FIRFakeApp.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,27 @@ @interface FIRDatabaseComponent (Internal)
3939
- (instancetype)initWithApp:(FIRApp *)app;
4040
@end
4141

42+
@interface FIRComponentContainer (TestInternal)
43+
@property(nonatomic, strong) NSMutableDictionary<NSString *, FIRComponentCreationBlock> *components;
44+
@end
45+
46+
@interface FIRComponentContainer (TestInternalImplementations)
47+
- (instancetype)initWithApp:(FIRApp *)app
48+
components:(NSDictionary<NSString *, FIRComponentCreationBlock> *)components;
49+
@end
50+
51+
@implementation FIRComponentContainer (TestInternalImplementations)
52+
53+
- (instancetype)initWithApp:(FIRApp *)app
54+
components:(NSDictionary<NSString *, FIRComponentCreationBlock> *)components {
55+
self = [self initWithApp:app registrants:[[NSMutableSet alloc] init]];
56+
if (self) {
57+
self.components = [components mutableCopy];
58+
}
59+
return self;
60+
}
61+
@end
62+
4263
@implementation FIRFakeApp
4364

4465
- (instancetype)initWithName:(NSString *)name URL:(NSString *)url {

Example/Storage/Tests/Unit/FIRStorageComponentTests.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919

2020
#import <FirebaseCore/FIRAppInternal.h>
2121
#import <FirebaseCore/FIRComponent.h>
22-
#import <FirebaseCore/FIRComponentRegistrant.h>
22+
#import <FirebaseCore/FIRLibrary.h>
2323
#import <FirebaseCore/FIROptions.h>
2424

2525
#import "FIRComponentTestUtilities.h"
2626
#import "FIRStorageComponent.h"
2727

2828
// Make FIRComponentRegistrant conformance visible to the tests and expose the initializer.
29-
@interface FIRStorageComponent () <FIRComponentRegistrant>
30-
/// Internal intializer.
29+
@interface FIRStorageComponent () <FIRLibrary>
30+
/// Internal initializer.
3131
- (instancetype)initWithApp:(FIRApp *)app;
3232
@end
3333

Firebase/Auth/Source/FIRAuth.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
#import <FirebaseCore/FIRAppInternal.h>
2727
#import <FirebaseCore/FIRComponent.h>
2828
#import <FirebaseCore/FIRComponentContainer.h>
29-
#import <FirebaseCore/FIRComponentRegistrant.h>
30-
#import <FirebaseCore/FIRCoreConfigurable.h>
29+
#import <FirebaseCore/FIRLibrary.h>
3130
#import <FirebaseCore/FIRLogger.h>
3231
#import <FirebaseCore/FIROptions.h>
3332
#import <GoogleUtilities/GULAppEnvironmentUtil.h>
@@ -228,9 +227,9 @@ + (FIRActionCodeOperation)actionCodeOperationForRequestType:(NSString *)requestT
228227
#pragma mark - FIRAuth
229228

230229
#if TARGET_OS_IOS
231-
@interface FIRAuth () <FIRAuthAppDelegateHandler, FIRComponentRegistrant, FIRCoreConfigurable, FIRComponentLifecycleMaintainer>
230+
@interface FIRAuth () <FIRAuthAppDelegateHandler, FIRLibrary, FIRComponentLifecycleMaintainer>
232231
#else
233-
@interface FIRAuth () <FIRComponentRegistrant, FIRCoreConfigurable, FIRComponentLifecycleMaintainer>
232+
@interface FIRAuth () <FIRLibrary, FIRComponentLifecycleMaintainer>
234233
#endif
235234

236235
/** @property firebaseAppId
@@ -310,8 +309,9 @@ @implementation FIRAuth {
310309
}
311310

312311
+ (void)load {
313-
[FIRComponentContainer registerAsComponentRegistrant:self];
314-
[FIRApp registerAsConfigurable:self];
312+
[FIRApp registerInternalLibrary:(Class<FIRLibrary>)self
313+
withName:@"fire-auth"
314+
withVersion:[NSString stringWithUTF8String:FirebaseAuthVersionStr]];
315315
}
316316

317317
+ (void)initialize {

Firebase/Auth/Source/FirebaseAuthVersion.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@
2222

2323
const double FirebaseAuthVersionNum = FIRAuth_MINOR_VERSION;
2424

25-
const unsigned char *const FirebaseAuthVersionStr =
26-
(const unsigned char *const)STR(FIRAuth_VERSION);
25+
const char *const FirebaseAuthVersionStr = (const char *const)STR(FIRAuth_VERSION);

Firebase/Auth/Source/Public/FirebaseAuthVersion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ extern const double FirebaseAuthVersionNum;
2424
/**
2525
Version string for FirebaseAuth.
2626
*/
27-
extern const unsigned char *const FirebaseAuthVersionStr;
27+
extern const char *const FirebaseAuthVersionStr;

0 commit comments

Comments
 (0)