Skip to content

Commit 7376043

Browse files
chore(firebase_core): create a swift package of shared iOS source code for all plugins (#13540)
1 parent d3cfc0e commit 7376043

File tree

7 files changed

+134
-0
lines changed

7 files changed

+134
-0
lines changed

Package.swift

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// swift-tools-version: 5.9
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
// Copyright 2024, the Chromium project authors. Please see the AUTHORS file
5+
// for details. All rights reserved. Use of this source code is governed by a
6+
// BSD-style license that can be found in the LICENSE file.
7+
8+
import Foundation
9+
import PackageDescription
10+
11+
enum ConfigurationError: Error {
12+
case fileNotFound(String)
13+
case parsingError(String)
14+
case invalidFormat(String)
15+
}
16+
17+
func loadFirebaseSDKVersion() throws -> String {
18+
let firebaseCoreScriptPath = NSString.path(withComponents: [
19+
"packages",
20+
"firebase_core",
21+
"firebase_core",
22+
"ios",
23+
"firebase_sdk_version.rb",
24+
])
25+
26+
do {
27+
let content = try String(contentsOfFile: firebaseCoreScriptPath, encoding: .utf8)
28+
let pattern = #"def firebase_sdk_version!\(\)\n\s+'([^']+)'\nend"#
29+
if let regex = try? NSRegularExpression(pattern: pattern, options: []),
30+
let match = regex.firstMatch(
31+
in: content,
32+
range: NSRange(content.startIndex..., in: content)
33+
) {
34+
if let versionRange = Range(match.range(at: 1), in: content) {
35+
return String(content[versionRange])
36+
} else {
37+
throw ConfigurationError.invalidFormat("Invalid format in firebase_sdk_version.rb")
38+
}
39+
} else {
40+
throw ConfigurationError.parsingError("No match found in firebase_sdk_version.rb")
41+
}
42+
} catch {
43+
throw ConfigurationError
44+
.fileNotFound("Error loading or parsing firebase_sdk_version.rb: \(error)")
45+
}
46+
}
47+
48+
let firebase_sdk_version_string: String
49+
50+
do {
51+
firebase_sdk_version_string = try loadFirebaseSDKVersion()
52+
} catch {
53+
fatalError("Failed to load configuration: \(error)")
54+
}
55+
56+
guard let firebase_sdk_version = Version(firebase_sdk_version_string) else {
57+
fatalError("Invalid Firebase SDK version: \(firebase_sdk_version_string)")
58+
}
59+
60+
// Shared Swift package manager code for firebase core
61+
let package = Package(
62+
name: "remote_firebase_core",
63+
platforms: [
64+
.iOS("13.0"),
65+
.macOS("10.15"),
66+
],
67+
products: [
68+
.library(name: "firebase-core-shared", targets: ["firebase_core_shared"]),
69+
],
70+
dependencies: [
71+
.package(url: "https://github.com/firebase/firebase-ios-sdk", exact: firebase_sdk_version),
72+
],
73+
targets: [
74+
.target(
75+
name: "firebase_core_shared",
76+
dependencies: [
77+
.product(name: "FirebaseInstallations", package: "firebase-ios-sdk"),
78+
],
79+
path: "Sources/firebase_core_shared",
80+
publicHeadersPath: "include"
81+
),
82+
]
83+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebasePlugin.m
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebasePluginRegistry.m
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebasePlugin.h
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebasePluginRegistry.h

melos.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ command:
2121
dart run scripts/generate_dataconnect_version.dart && \
2222
git add packages/firebase_vertexai/firebase_vertexai/lib/src/vertex_version.dart && \
2323
git add packages/firebase_data_connect/firebase_data_connect/lib/src/dataconnect_version.dart
24+
post: |
25+
dart run scripts/generate_tag_spm_firebase_core.dart
2426
2527
bootstrap:
2628
# It seems so that running "pub get" in parallel has some issues (like
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2024 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
// ignore_for_file: avoid_print
5+
6+
import 'dart:io';
7+
import 'package:yaml/yaml.dart';
8+
9+
void main(List<String> args) {
10+
// Define the path to the pubspec.yaml file
11+
const pubspecPath = 'packages/firebase_core/firebase_core/pubspec.yaml';
12+
13+
// Read the pubspec.yaml file
14+
final pubspecFile = File(pubspecPath);
15+
if (!pubspecFile.existsSync()) {
16+
print('Error: pubspec.yaml file not found at $pubspecPath');
17+
return;
18+
}
19+
20+
// Parse the YAML content
21+
final pubspecContent = pubspecFile.readAsStringSync();
22+
final pubspecYaml = loadYaml(pubspecContent);
23+
24+
// Extract the version
25+
final version = pubspecYaml['version'];
26+
if (version == null) {
27+
print('Error: Version not found in pubspec.yaml');
28+
return;
29+
}
30+
31+
const packageIdentifier = 'firebase-core-swift';
32+
33+
// Generate the tag
34+
final tag = '$version-$packageIdentifier';
35+
print('Generated tag for firebase core swift: $tag');
36+
37+
// Run the git tag command
38+
final result = Process.runSync('git', ['tag', tag]);
39+
40+
if (result.exitCode == 0) {
41+
print('Git tag created successfully for firebase core swift: $tag');
42+
} else {
43+
print('Error creating git tag: ${result.stderr}');
44+
}
45+
}

0 commit comments

Comments
 (0)