@@ -14,84 +14,53 @@ enum ConfigurationError: Error {
14
14
case invalidFormat( String )
15
15
}
16
16
17
- let firestoreDirectory = String ( URL ( string: #file) !. deletingLastPathComponent ( ) . absoluteString
18
- . dropLast ( ) )
17
+ let firestoreDirectory = String (
18
+ URL ( string: #file) !. deletingLastPathComponent ( ) . absoluteString
19
+ . dropLast ( ) )
19
20
20
21
func loadFirebaseSDKVersion( ) throws -> String {
21
22
let firebaseCoreScriptPath = NSString . path ( withComponents: [
22
23
firestoreDirectory,
23
24
" .. " ,
24
25
" .. " ,
25
- " .. " ,
26
- " .. " ,
27
- " firebase_core " ,
28
- " firebase_core " ,
29
26
" ios " ,
30
- " firebase_sdk_version.rb " ,
27
+ " generated_firebase_sdk_version.txt " ,
31
28
] )
32
29
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
- }
30
+ let version = try String ( contentsOfFile: firebaseCoreScriptPath, encoding: . utf8)
31
+ . trimmingCharacters ( in: . whitespacesAndNewlines)
32
+ return version
48
33
} catch {
49
- throw ConfigurationError
50
- . fileNotFound ( " Error loading or parsing firebase_sdk_version.rb: \( error) " )
34
+ throw
35
+ ConfigurationError
36
+ . fileNotFound ( " Error loading or parsing generated_firebase_sdk_version.txt: \( error) " )
51
37
}
52
38
}
53
39
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 " ,
64
- ] )
65
- 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
76
- } catch {
77
- throw ConfigurationError
78
- . fileNotFound ( " Error loading or parsing firebase_core pubspec.yaml: \( error) " )
79
- }
80
- }
81
-
82
- func loadPubspecVersion( ) throws -> String {
40
+ func loadPubspecVersions( ) throws -> ( packageVersion: String , firebaseCoreVersion: String ) {
83
41
let pubspecPath = NSString . path ( withComponents: [ firestoreDirectory, " .. " , " .. " , " pubspec.yaml " ] )
84
42
do {
85
43
let yamlString = try String ( contentsOfFile: pubspecPath, encoding: . utf8)
86
44
let lines = yamlString. split ( separator: " \n " )
87
45
88
- guard let versionLine = lines. first ( where: { $0. starts ( with: " version: " ) } ) else {
89
- throw ConfigurationError . invalidFormat ( " No version line found in pubspec.yaml " )
46
+ guard let packageVersionLine = lines. first ( where: { $0. starts ( with: " version: " ) } ) else {
47
+ throw ConfigurationError . invalidFormat ( " No package version line found in pubspec.yaml " )
90
48
}
91
- let libraryVersion = versionLine. split ( separator: " : " ) [ 1 ] . trimmingCharacters ( in: . whitespaces)
49
+ var packageVersion = packageVersionLine. split ( separator: " : " ) [ 1 ]
50
+ . trimmingCharacters ( in: . whitespaces)
92
51
. replacingOccurrences ( of: " + " , with: " - " )
52
+ packageVersion = packageVersion. replacingOccurrences ( of: " ^ " , with: " " )
53
+
54
+ guard let firebaseCoreVersionLine = lines. first ( where: { $0. contains ( " firebase_core: " ) } ) else {
55
+ throw
56
+ ConfigurationError
57
+ . invalidFormat ( " No firebase_core dependency version line found in pubspec.yaml " )
58
+ }
59
+ var firebaseCoreVersion = firebaseCoreVersionLine. split ( separator: " : " ) [ 1 ]
60
+ . trimmingCharacters ( in: . whitespaces)
61
+ firebaseCoreVersion = firebaseCoreVersion. replacingOccurrences ( of: " ^ " , with: " " )
93
62
94
- return libraryVersion
63
+ return ( packageVersion , firebaseCoreVersion )
95
64
} catch {
96
65
throw ConfigurationError . fileNotFound ( " Error loading or parsing pubspec.yaml: \( error) " )
97
66
}
@@ -103,9 +72,9 @@ let firebase_core_version_string: String
103
72
let shared_spm_tag = " -firebase-core-swift "
104
73
105
74
do {
106
- library_version = try loadPubspecVersion ( )
75
+ library_version = try loadPubspecVersions ( ) . packageVersion
107
76
firebase_sdk_version_string = try loadFirebaseSDKVersion ( )
108
- firebase_core_version_string = try loadFirebaseCoreVersion ( )
77
+ firebase_core_version_string = try loadPubspecVersions ( ) . firebaseCoreVersion
109
78
} catch {
110
79
fatalError ( " Failed to load configuration: \( error) " )
111
80
}
@@ -114,19 +83,17 @@ guard let firebase_sdk_version = Version(firebase_sdk_version_string) else {
114
83
fatalError ( " Invalid Firebase SDK version: \( firebase_sdk_version_string) " )
115
84
}
116
85
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
86
guard let shared_spm_version = Version ( " \( firebase_core_version_string) \( shared_spm_tag) " ) else {
120
87
fatalError ( " Invalid firebase_core version: \( firebase_core_version_string) \( shared_spm_tag) " )
121
88
}
122
89
123
90
let package = Package (
124
91
name: " cloud_firestore " ,
125
92
platforms: [
126
- . macOS( " 10.15 " ) ,
93
+ . macOS( " 10.15 " )
127
94
] ,
128
95
products: [
129
- . library( name: " cloud-firestore " , targets: [ " cloud_firestore " ] ) ,
96
+ . library( name: " cloud-firestore " , targets: [ " cloud_firestore " ] )
130
97
] ,
131
98
dependencies: [
132
99
. package ( url: " https://github.com/firebase/firebase-ios-sdk " , from: firebase_sdk_version) ,
@@ -141,14 +108,14 @@ let package = Package(
141
108
. product( name: " firebase-core-shared " , package : " flutterfire " ) ,
142
109
] ,
143
110
resources: [
144
- . process( " Resources " ) ,
111
+ . process( " Resources " )
145
112
] ,
146
113
cSettings: [
147
114
. headerSearchPath( " include/cloud_firestore/Private " ) ,
148
115
. headerSearchPath( " include/cloud_firestore/Public " ) ,
149
116
. define( " LIBRARY_VERSION " , to: " \" \( library_version) \" " ) ,
150
117
. define( " LIBRARY_NAME " , to: " \" flutter-fire-fst \" " ) ,
151
118
]
152
- ) ,
119
+ )
153
120
]
154
121
)
0 commit comments