Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core, ios): update Package.swift and header imports for backwards compatibility #13545

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 3 additions & 50 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,6 @@
import Foundation
import PackageDescription

enum ConfigurationError: Error {
case fileNotFound(String)
case parsingError(String)
case invalidFormat(String)
}

func loadFirebaseSDKVersion() throws -> String {
let firebaseCoreScriptPath = NSString.path(withComponents: [
"packages",
"firebase_core",
"firebase_core",
"ios",
"firebase_sdk_version.rb",
])

do {
let content = try String(contentsOfFile: firebaseCoreScriptPath, encoding: .utf8)
let pattern = #"def firebase_sdk_version!\(\)\n\s+'([^']+)'\nend"#
if let regex = try? NSRegularExpression(pattern: pattern, options: []),
let match = regex.firstMatch(
in: content,
range: NSRange(content.startIndex..., in: content)
) {
if let versionRange = Range(match.range(at: 1), in: content) {
return String(content[versionRange])
} else {
throw ConfigurationError.invalidFormat("Invalid format in firebase_sdk_version.rb")
}
} else {
throw ConfigurationError.parsingError("No match found in firebase_sdk_version.rb")
}
} catch {
throw ConfigurationError
.fileNotFound("Error loading or parsing firebase_sdk_version.rb: \(error)")
}
}

let firebase_sdk_version_string: String

do {
firebase_sdk_version_string = try loadFirebaseSDKVersion()
} catch {
fatalError("Failed to load configuration: \(error)")
}

guard let firebase_sdk_version = Version(firebase_sdk_version_string) else {
fatalError("Invalid Firebase SDK version: \(firebase_sdk_version_string)")
}

// Shared Swift package manager code for firebase core
let package = Package(
name: "remote_firebase_core",
Expand All @@ -68,7 +19,9 @@ let package = Package(
.library(name: "firebase-core-shared", targets: ["firebase_core_shared"]),
],
dependencies: [
.package(url: "https://github.com/firebase/firebase-ios-sdk", exact: firebase_sdk_version),
// TODO: this is fine for now, but will require a way of retrieving the firebase-ios-sdk
// likely create a script that runs in preCommit hook of melos
.package(url: "https://github.com/firebase/firebase-ios-sdk", from: "11.0.0"),
],
targets: [
.target(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#if __has_include("include/firebase_core/FLTFirebasePlugin.h")
#import "include/firebase_core/FLTFirebasePlugin.h"
#else
#import "include/FLTFirebasePlugin.h"
#endif

// Firebase default app name.
NSString *_Nonnull const kFIRDefaultAppNameIOS = @"__FIRAPP_DEFAULT";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#if __has_include("include/firebase_core/FLTFirebasePluginRegistry.h")
#import "include/firebase_core/FLTFirebasePluginRegistry.h"
#else
#import "include/FLTFirebasePluginRegistry.h"
#endif

#if __has_include(<FirebaseCore/FIRAppInternal.h>)
#import <FirebaseCore/FIRAppInternal.h>
Expand Down
Loading