Skip to content

Commit

Permalink
fix(core): auth Swift support requires FLTFirebaseCorePlugin & `mes…
Browse files Browse the repository at this point in the history
…sages` to be shared (#16774)
  • Loading branch information
russellwheatley authored and Lyokone committed Dec 4, 2024
1 parent d5778f8 commit f89483c
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 3 deletions.
16 changes: 14 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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(
Expand All @@ -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\""),
]
),
]
)
1 change: 1 addition & 0 deletions Sources/firebase_core_shared/FLTFirebaseCorePlugin.m
1 change: 1 addition & 0 deletions Sources/firebase_core_shared/include/messages.g.h
1 change: 1 addition & 0 deletions Sources/firebase_core_shared/messages.g.m
2 changes: 1 addition & 1 deletion melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <FlutterPlugin, FLTFirebasePlugin, FirebaseCoreHostApi, FirebaseAppHostApi>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <FlutterMacOS/FlutterMacOS.h>
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -33,6 +34,8 @@ void main(List<String> args) async {
versionFile.writeAsStringSync(firebaseiOSVersion);
}
}
// Update the versions in root Package.swift
updateVersionsPackageSwift(firebaseiOSVersion);
}

Future<melos.MelosWorkspace> getMelosWorkspace() async {
Expand Down Expand Up @@ -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',
);
}

0 comments on commit f89483c

Please sign in to comment.