From f89483cd9a3b4900d9b79151bb383ae35aa3dd4f Mon Sep 17 00:00:00 2001 From: Russell Wheatley Date: Wed, 4 Dec 2024 14:54:02 +0000 Subject: [PATCH] fix(core): auth Swift support requires `FLTFirebaseCorePlugin` & `messages` to be shared (#16774) --- Package.swift | 16 ++++- .../FLTFirebaseCorePlugin.m | 1 + .../include/FLTFirebaseCorePlugin.h | 1 + .../firebase_core_shared/include/messages.g.h | 1 + Sources/firebase_core_shared/messages.g.m | 1 + melos.yaml | 2 +- .../ios/firebase_core/Package.swift | 4 ++ .../firebase_core/FLTFirebaseCorePlugin.m | 14 ++++ .../Sources/firebase_core/dummy.m | 3 + .../firebase_core/FLTFirebaseCorePlugin.h | 4 ++ .../include/firebase_core/dummy.h | 3 + .../Sources/firebase_core/messages.g.m | 4 ++ ...xt_spm.dart => generate_versions_spm.dart} | 67 +++++++++++++++++++ 13 files changed, 118 insertions(+), 3 deletions(-) create mode 120000 Sources/firebase_core_shared/FLTFirebaseCorePlugin.m create mode 120000 Sources/firebase_core_shared/include/FLTFirebaseCorePlugin.h create mode 120000 Sources/firebase_core_shared/include/messages.g.h create mode 120000 Sources/firebase_core_shared/messages.g.m create mode 100644 packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/dummy.m create mode 100644 packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/dummy.h rename scripts/{generate_ios_sdk_version_txt_spm.dart => generate_versions_spm.dart} (56%) diff --git a/Package.swift b/Package.swift index 1b7b87ce483b..99d13a6fe95c 100644 --- a/Package.swift +++ b/Package.swift @@ -8,6 +8,10 @@ import Foundation import PackageDescription +// auto-generated by melos post commit hook script +let firebase_core_version: String = "3.8.0" +let firebase_ios_sdk_version: String = "11.4.0" + // Shared Swift package manager code for firebase core let package = Package( name: "remote_firebase_core", @@ -21,7 +25,10 @@ let package = Package( dependencies: [ // 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"), + .package( + url: "https://github.com/firebase/firebase-ios-sdk", + from: Version(firebase_ios_sdk_version)! + ), ], targets: [ .target( @@ -30,7 +37,12 @@ let package = Package( .product(name: "FirebaseInstallations", package: "firebase-ios-sdk"), ], path: "Sources/firebase_core_shared", - publicHeadersPath: "include" + publicHeadersPath: "include", + cSettings: [ + .headerSearchPath("include/firebase_core"), + .define("LIBRARY_VERSION", to: "\"\(firebase_core_version)\""), + .define("LIBRARY_NAME", to: "\"flutter-fire-core\""), + ] ), ] ) diff --git a/Sources/firebase_core_shared/FLTFirebaseCorePlugin.m b/Sources/firebase_core_shared/FLTFirebaseCorePlugin.m new file mode 120000 index 000000000000..e94afa3aad20 --- /dev/null +++ b/Sources/firebase_core_shared/FLTFirebaseCorePlugin.m @@ -0,0 +1 @@ +../../packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebaseCorePlugin.m \ No newline at end of file diff --git a/Sources/firebase_core_shared/include/FLTFirebaseCorePlugin.h b/Sources/firebase_core_shared/include/FLTFirebaseCorePlugin.h new file mode 120000 index 000000000000..8e3a8c248b88 --- /dev/null +++ b/Sources/firebase_core_shared/include/FLTFirebaseCorePlugin.h @@ -0,0 +1 @@ +../../../packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebaseCorePlugin.h \ No newline at end of file diff --git a/Sources/firebase_core_shared/include/messages.g.h b/Sources/firebase_core_shared/include/messages.g.h new file mode 120000 index 000000000000..3a5ff91b8660 --- /dev/null +++ b/Sources/firebase_core_shared/include/messages.g.h @@ -0,0 +1 @@ +../../../packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/messages.g.h \ No newline at end of file diff --git a/Sources/firebase_core_shared/messages.g.m b/Sources/firebase_core_shared/messages.g.m new file mode 120000 index 000000000000..9b2e6e36e348 --- /dev/null +++ b/Sources/firebase_core_shared/messages.g.m @@ -0,0 +1 @@ +../../packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/messages.g.m \ No newline at end of file diff --git a/melos.yaml b/melos.yaml index a12d8e47d9b6..a04e3758f5e5 100644 --- a/melos.yaml +++ b/melos.yaml @@ -19,7 +19,7 @@ command: preCommit: | dart run scripts/generate_vertexai_version.dart && \ dart run scripts/generate_dataconnect_version.dart && \ - dart run scripts/generate_ios_sdk_version_txt_spm.dart && \ + dart run scripts/generate_versions_spm.dart && \ git add packages/firebase_vertexai/firebase_vertexai/lib/src/vertex_version.dart && \ git add packages/firebase_data_connect/firebase_data_connect/lib/src/dataconnect_version.dart post: | diff --git a/packages/firebase_core/firebase_core/ios/firebase_core/Package.swift b/packages/firebase_core/firebase_core/ios/firebase_core/Package.swift index a39f10863fc1..9882bff1cab5 100644 --- a/packages/firebase_core/firebase_core/ios/firebase_core/Package.swift +++ b/packages/firebase_core/firebase_core/ios/firebase_core/Package.swift @@ -109,8 +109,12 @@ let package = Package( ], exclude: [ // These are now pulled in as a remote dependency from FlutterFire repo + "FLTFirebaseCorePlugin.m", "FLTFirebasePlugin.m", "FLTFirebasePluginRegistry.m", + "messages.g.m", + "include/firebase_core/FLTFirebaseCorePlugin.h", + "include/firebase_core/messages.g.h", "include/firebase_core/FLTFirebasePlugin.h", "include/firebase_core/FLTFirebasePluginRegistry.h", ], diff --git a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebaseCorePlugin.m b/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebaseCorePlugin.m index 87cb647c0eba..2fbb803dd8ad 100644 --- a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebaseCorePlugin.m +++ b/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebaseCorePlugin.m @@ -2,9 +2,23 @@ // 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/FLTFirebaseCorePlugin.h") #import "include/firebase_core/FLTFirebaseCorePlugin.h" +#else +#import "include/FLTFirebaseCorePlugin.h" +#endif + +#if __has_include("include/firebase_core/FLTFirebasePluginRegistry.h") #import "include/firebase_core/FLTFirebasePluginRegistry.h" +#else +#import "include/FLTFirebasePluginRegistry.h" +#endif + +#if __has_include("include/firebase_core/messages.g.h") #import "include/firebase_core/messages.g.h" +#else +#import "include/messages.g.h" +#endif @implementation FLTFirebaseCorePlugin { BOOL _coreInitialized; diff --git a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/dummy.m b/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/dummy.m new file mode 100644 index 000000000000..b26e56855988 --- /dev/null +++ b/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/dummy.m @@ -0,0 +1,3 @@ +// Copyright 2023, the Chromium project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. diff --git a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebaseCorePlugin.h b/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebaseCorePlugin.h index ee051e39baac..accb377c7b46 100644 --- a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebaseCorePlugin.h +++ b/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebaseCorePlugin.h @@ -10,7 +10,11 @@ #endif #import "FLTFirebasePlugin.h" +#if __has_include("include/messages.g.h") +#import "include/messages.g.h" +#else #import "messages.g.h" +#endif @interface FLTFirebaseCorePlugin : FLTFirebasePlugin diff --git a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/dummy.h b/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/dummy.h new file mode 100644 index 000000000000..b26e56855988 --- /dev/null +++ b/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/dummy.h @@ -0,0 +1,3 @@ +// Copyright 2023, the Chromium project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. diff --git a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/messages.g.m b/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/messages.g.m index a1bf4e0fbeb0..631f1932432f 100644 --- a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/messages.g.m +++ b/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/messages.g.m @@ -4,7 +4,11 @@ // Autogenerated from Pigeon (v9.2.5), do not edit directly. // See also: https://pub.dev/packages/pigeon +#if __has_include("include/firebase_core/messages.g.h") #import "include/firebase_core/messages.g.h" +#else +#import "include/messages.g.h" +#endif #if TARGET_OS_OSX #import #else diff --git a/scripts/generate_ios_sdk_version_txt_spm.dart b/scripts/generate_versions_spm.dart similarity index 56% rename from scripts/generate_ios_sdk_version_txt_spm.dart rename to scripts/generate_versions_spm.dart index 9dd55bdde5f5..6bcb7d9f716f 100644 --- a/scripts/generate_ios_sdk_version_txt_spm.dart +++ b/scripts/generate_versions_spm.dart @@ -6,6 +6,7 @@ import 'package:melos/melos.dart' as melos; import 'package:glob/glob.dart'; import 'dart:io'; import 'package:cli_util/cli_logging.dart' as logging; +import 'package:yaml/yaml.dart'; // Used to generate a simple txt file for Package.swift file to parse in order to use correct firebase-ios-sdk version @@ -33,6 +34,8 @@ void main(List args) async { versionFile.writeAsStringSync(firebaseiOSVersion); } } + // Update the versions in root Package.swift + updateVersionsPackageSwift(firebaseiOSVersion); } Future getMelosWorkspace() async { @@ -69,3 +72,67 @@ String getFirebaseiOSVersion(File firebaseCoreIosSdkVersion) { throw Exception('firebase_sdk_version.rb file does not exist.'); } } + +void updateVersionsPackageSwift(String firebaseiOSVersion) { + // Define the path to the pubspec.yaml file + const pubspecPath = 'packages/firebase_core/firebase_core/pubspec.yaml'; + + + // Read the pubspec.yaml file + final pubspecFile = File(pubspecPath); + if (!pubspecFile.existsSync()) { + print('Error: pubspec.yaml file not found at $pubspecPath'); + return; + } + + + // Parse the YAML content + final pubspecContent = pubspecFile.readAsStringSync(); + final pubspecYaml = loadYaml(pubspecContent); + + + // Extract the version + final version = pubspecYaml['version']; + if (version == null) { + print('Error: Version not found in pubspec.yaml'); + return; + } + + + // Define the path to the Package.swift file + const packageSwiftPath = 'Package.swift'; + + + // Read the Package.swift file + final packageSwiftFile = File(packageSwiftPath); + if (!packageSwiftFile.existsSync()) { + print('Error: Package.swift file not found at $packageSwiftPath'); + return; + } + + + // Read the content of Package.swift + final packageSwiftContent = packageSwiftFile.readAsStringSync(); + + + // Update the library_version_string with the new version + final updatedFirebaseCoreVersion = packageSwiftContent.replaceAll( + RegExp('let firebase_core_version: String = "[^"]+"'), + 'let firebase_core_version: String = "$version"', + ); + + + final updatedFirebaseIosVersion = updatedFirebaseCoreVersion.replaceAll( + RegExp('let firebase_ios_sdk_version: String = "[^"]+"'), + 'let firebase_ios_sdk_version: String = "$firebaseiOSVersion"', + ); + + + // Write the updated content back to Package.swift + packageSwiftFile.writeAsStringSync(updatedFirebaseIosVersion); + + + print( + 'Updated Package.swift with firebase_core version: $version & firebase-ios-sdk version: $firebaseiOSVersion', + ); +}