diff --git a/Package.swift b/Package.swift new file mode 100644 index 000000000000..d0bce4a11f6b --- /dev/null +++ b/Package.swift @@ -0,0 +1,83 @@ +// swift-tools-version: 5.9 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +// Copyright 2024, 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. + +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", + platforms: [ + .iOS("13.0"), + .macOS("10.15"), + ], + products: [ + .library(name: "firebase-core-shared", targets: ["firebase_core_shared"]), + ], + dependencies: [ + .package(url: "https://github.com/firebase/firebase-ios-sdk", exact: firebase_sdk_version), + ], + targets: [ + .target( + name: "firebase_core_shared", + dependencies: [ + .product(name: "FirebaseInstallations", package: "firebase-ios-sdk"), + ], + path: "Sources/firebase_core_shared", + publicHeadersPath: "include" + ), + ] +) diff --git a/Sources/firebase_core_shared/FLTFirebasePlugin.m b/Sources/firebase_core_shared/FLTFirebasePlugin.m new file mode 120000 index 000000000000..76c49e1d4542 --- /dev/null +++ b/Sources/firebase_core_shared/FLTFirebasePlugin.m @@ -0,0 +1 @@ +../../packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebasePlugin.m \ No newline at end of file diff --git a/Sources/firebase_core_shared/FLTFirebasePluginRegistry.m b/Sources/firebase_core_shared/FLTFirebasePluginRegistry.m new file mode 120000 index 000000000000..be294affaf60 --- /dev/null +++ b/Sources/firebase_core_shared/FLTFirebasePluginRegistry.m @@ -0,0 +1 @@ +../../packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebasePluginRegistry.m \ No newline at end of file diff --git a/Sources/firebase_core_shared/include/FLTFirebasePlugin.h b/Sources/firebase_core_shared/include/FLTFirebasePlugin.h new file mode 120000 index 000000000000..6bbe0e68429a --- /dev/null +++ b/Sources/firebase_core_shared/include/FLTFirebasePlugin.h @@ -0,0 +1 @@ +../../../packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebasePlugin.h \ No newline at end of file diff --git a/Sources/firebase_core_shared/include/FLTFirebasePluginRegistry.h b/Sources/firebase_core_shared/include/FLTFirebasePluginRegistry.h new file mode 120000 index 000000000000..e0b26a14c24f --- /dev/null +++ b/Sources/firebase_core_shared/include/FLTFirebasePluginRegistry.h @@ -0,0 +1 @@ +../../../packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebasePluginRegistry.h \ No newline at end of file diff --git a/melos.yaml b/melos.yaml index fac6e008d4ec..78ba09d39ad5 100644 --- a/melos.yaml +++ b/melos.yaml @@ -21,6 +21,8 @@ command: dart run scripts/generate_dataconnect_version.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: | + dart run scripts/generate_tag_spm_firebase_core.dart bootstrap: # It seems so that running "pub get" in parallel has some issues (like diff --git a/scripts/generate_tag_spm_firebase_core.dart b/scripts/generate_tag_spm_firebase_core.dart new file mode 100644 index 000000000000..e5d9510a1418 --- /dev/null +++ b/scripts/generate_tag_spm_firebase_core.dart @@ -0,0 +1,45 @@ +// Copyright 2024 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// ignore_for_file: avoid_print + +import 'dart:io'; +import 'package:yaml/yaml.dart'; + +void main(List args) { + // 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; + } + + const packageIdentifier = 'firebase-core-swift'; + + // Generate the tag + final tag = '$version-$packageIdentifier'; + print('Generated tag for firebase core swift: $tag'); + + // Run the git tag command + final result = Process.runSync('git', ['tag', tag]); + + if (result.exitCode == 0) { + print('Git tag created successfully for firebase core swift: $tag'); + } else { + print('Error creating git tag: ${result.stderr}'); + } +}