Skip to content

Commit

Permalink
chore(firebase_core): create a swift package of shared iOS source cod…
Browse files Browse the repository at this point in the history
…e for all plugins (#13540)
  • Loading branch information
russellwheatley authored Oct 23, 2024
1 parent d3cfc0e commit 7376043
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 0 deletions.
83 changes: 83 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -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"
),
]
)
1 change: 1 addition & 0 deletions Sources/firebase_core_shared/FLTFirebasePlugin.m
1 change: 1 addition & 0 deletions Sources/firebase_core_shared/FLTFirebasePluginRegistry.m
1 change: 1 addition & 0 deletions Sources/firebase_core_shared/include/FLTFirebasePlugin.h
2 changes: 2 additions & 0 deletions melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 45 additions & 0 deletions scripts/generate_tag_spm_firebase_core.dart
Original file line number Diff line number Diff line change
@@ -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<String> 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}');
}
}

0 comments on commit 7376043

Please sign in to comment.