@@ -22,76 +22,42 @@ func loadFirebaseSDKVersion() throws -> String {
22
22
firestoreDirectory,
23
23
" .. " ,
24
24
" .. " ,
25
- " .. " ,
26
- " .. " ,
27
- " firebase_core " ,
28
- " firebase_core " ,
29
25
" ios " ,
30
- " firebase_sdk_version.rb " ,
31
- ] )
32
- do {
33
- let content = try String ( contentsOfFile: firebaseCoreScriptPath, encoding: . utf8)
34
- let pattern = #"def firebase_sdk_version!\(\)\n\s+'([^']+)'\nend"#
35
- if let regex = try ? NSRegularExpression ( pattern: pattern, options: [ ] ) ,
36
- let match = regex. firstMatch (
37
- in: content,
38
- range: NSRange ( content. startIndex... , in: content)
39
- ) {
40
- if let versionRange = Range ( match. range ( at: 1 ) , in: content) {
41
- return String ( content [ versionRange] )
42
- } else {
43
- throw ConfigurationError . invalidFormat ( " Invalid format in firebase_sdk_version.rb " )
44
- }
45
- } else {
46
- throw ConfigurationError . parsingError ( " No match found in firebase_sdk_version.rb " )
47
- }
48
- } catch {
49
- throw ConfigurationError
50
- . fileNotFound ( " Error loading or parsing firebase_sdk_version.rb: \( error) " )
51
- }
52
- }
53
-
54
- func loadFirebaseCoreVersion( ) throws -> String {
55
- let firebaseCorePubspecPath = NSString . path ( withComponents: [
56
- firestoreDirectory,
57
- " .. " ,
58
- " .. " ,
59
- " .. " ,
60
- " .. " ,
61
- " firebase_core " ,
62
- " firebase_core " ,
63
- " pubspec.yaml " ,
26
+ " generated_firebase_sdk_version.txt " ,
64
27
] )
65
28
do {
66
- let yamlString = try String ( contentsOfFile: firebaseCorePubspecPath, encoding: . utf8)
67
- let lines = yamlString. split ( separator: " \n " )
68
-
69
- guard let versionLine = lines. first ( where: { $0. starts ( with: " version: " ) } ) else {
70
- throw ConfigurationError . invalidFormat ( " No version line found in pubspec.yaml " )
71
- }
72
- let libraryVersion = versionLine. split ( separator: " : " ) [ 1 ] . trimmingCharacters ( in: . whitespaces)
73
- . replacingOccurrences ( of: " + " , with: " - " )
74
-
75
- return libraryVersion
29
+ let version = try String ( contentsOfFile: firebaseCoreScriptPath, encoding: . utf8)
30
+ . trimmingCharacters ( in: . whitespacesAndNewlines)
31
+ return version
76
32
} catch {
77
33
throw ConfigurationError
78
- . fileNotFound ( " Error loading or parsing firebase_core pubspec.yaml : \( error) " )
34
+ . fileNotFound ( " Error loading or parsing generated_firebase_sdk_version.txt : \( error) " )
79
35
}
80
36
}
81
37
82
- func loadPubspecVersion ( ) throws -> String {
38
+ func loadPubspecVersions ( ) throws -> ( packageVersion : String , firebaseCoreVersion : String ) {
83
39
let pubspecPath = NSString . path ( withComponents: [ firestoreDirectory, " .. " , " .. " , " pubspec.yaml " ] )
84
40
do {
85
41
let yamlString = try String ( contentsOfFile: pubspecPath, encoding: . utf8)
86
42
let lines = yamlString. split ( separator: " \n " )
87
43
88
- guard let versionLine = lines. first ( where: { $0. starts ( with: " version: " ) } ) else {
89
- throw ConfigurationError . invalidFormat ( " No version line found in pubspec.yaml " )
44
+ guard let packageVersionLine = lines. first ( where: { $0. starts ( with: " version: " ) } ) else {
45
+ throw ConfigurationError . invalidFormat ( " No package version line found in pubspec.yaml " )
90
46
}
91
- let libraryVersion = versionLine. split ( separator: " : " ) [ 1 ] . trimmingCharacters ( in: . whitespaces)
47
+ var packageVersion = packageVersionLine. split ( separator: " : " ) [ 1 ]
48
+ . trimmingCharacters ( in: . whitespaces)
92
49
. replacingOccurrences ( of: " + " , with: " - " )
50
+ packageVersion = packageVersion. replacingOccurrences ( of: " ^ " , with: " " )
51
+
52
+ guard let firebaseCoreVersionLine = lines. first ( where: { $0. contains ( " firebase_core: " ) } ) else {
53
+ throw ConfigurationError
54
+ . invalidFormat ( " No firebase_core dependency version line found in pubspec.yaml " )
55
+ }
56
+ var firebaseCoreVersion = firebaseCoreVersionLine. split ( separator: " : " ) [ 1 ]
57
+ . trimmingCharacters ( in: . whitespaces)
58
+ firebaseCoreVersion = firebaseCoreVersion. replacingOccurrences ( of: " ^ " , with: " " )
93
59
94
- return libraryVersion
60
+ return ( packageVersion , firebaseCoreVersion )
95
61
} catch {
96
62
throw ConfigurationError . fileNotFound ( " Error loading or parsing pubspec.yaml: \( error) " )
97
63
}
@@ -103,9 +69,9 @@ let firebase_core_version_string: String
103
69
let shared_spm_tag = " -firebase-core-swift "
104
70
105
71
do {
106
- library_version = try loadPubspecVersion ( )
72
+ library_version = try loadPubspecVersions ( ) . packageVersion
107
73
firebase_sdk_version_string = try loadFirebaseSDKVersion ( )
108
- firebase_core_version_string = try loadFirebaseCoreVersion ( )
74
+ firebase_core_version_string = try loadPubspecVersions ( ) . firebaseCoreVersion
109
75
} catch {
110
76
fatalError ( " Failed to load configuration: \( error) " )
111
77
}
@@ -114,8 +80,6 @@ guard let firebase_sdk_version = Version(firebase_sdk_version_string) else {
114
80
fatalError ( " Invalid Firebase SDK version: \( firebase_sdk_version_string) " )
115
81
}
116
82
117
- // TODO: - we can try using existing firebase_core tag once flutterfire/Package.swift is part of release cycle
118
- // but I don't think it'll work as Swift versioning requires version-[tag name]
119
83
guard let shared_spm_version = Version ( " \( firebase_core_version_string) \( shared_spm_tag) " ) else {
120
84
fatalError ( " Invalid firebase_core version: \( firebase_core_version_string) \( shared_spm_tag) " )
121
85
}
0 commit comments