Skip to content

Commit

Permalink
feat(firestore): Swift Package Manager support (#13329)
Browse files Browse the repository at this point in the history
  • Loading branch information
russellwheatley authored Nov 12, 2024
1 parent d095c08 commit 0420eab
Show file tree
Hide file tree
Showing 93 changed files with 689 additions and 178 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/all_plugins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ jobs:
- name: 'Swift Integration Setup'
run: flutter config --enable-swift-package-manager
- name: 'Build Apps with Swift Package Manager'
run: ./.github/workflows/scripts/swift-integration.sh
run: dart ./.github/workflows/scripts/swift-integration.dart

test:
runs-on: ubuntu-latest
Expand Down
105 changes: 105 additions & 0 deletions .github/workflows/scripts/swift-integration.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// 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 'dart:io';
import 'dart:convert';

void main() async {
await buildSwiftExampleApp('ios', 'firebase_core');
await buildSwiftExampleApp('ios', 'cloud_firestore');
await buildSwiftExampleApp('macos', 'firebase_core');
await buildSwiftExampleApp('macos', 'cloud_firestore');
}

Future<void> deleteFirstLine(String filePath) async {
final file = File(filePath);

if (!file.existsSync()) {
print('File does not exist: $filePath');
return;
}

final lines = await file.readAsLines();
if (lines.isNotEmpty) {
final updatedContent = lines.skip(1).join('\n');
await file.writeAsString(updatedContent);
print('First line deleted from $filePath');
} else {
print('File is empty: $filePath');
}
}

Future<void> buildSwiftExampleApp(String platform, String plugin) async {
final initialDirectory = Directory.current;
final platformName = platform == 'ios' ? 'iOS' : 'macOS';

print('Building $plugin $platformName example app with swift (SPM)');

final directory = Directory('packages/$plugin/$plugin/example/$platform');
if (!directory.existsSync()) {
print('Directory does not exist: ${directory.path}');
exit(1);
}

if (platform == 'macos') {
await deleteFirstLine(
'packages/$plugin/$plugin/example/macos/Flutter/Flutter-Debug.xcconfig');
}
// Change to the appropriate directory
Directory.current = directory;

// Remove Podfile and deintegrate pods
await _runCommand('rm', ['Podfile']);
await _runCommand('pod', ['deintegrate']);

// Determine the arguments for the flutter build command
final flutterArgs = ['build', platform];
if (platform == 'ios') {
flutterArgs.add('--no-codesign');
}

// Run the flutter build command
final flutterResult = await _runCommand('flutter', flutterArgs);

// Check if the flutter build command was successful
if (flutterResult.exitCode != 0) {
print('Flutter build failed with exit code ${flutterResult.exitCode}.');
exit(1);
}

// Check the output for the specific string
if (flutterResult.stdout.contains('Running pod install')) {
print('Failed. Pods are being installed when they should not be.');
exit(1);
} else {
print(
'Successfully built $plugin $platformName project using Swift Package Manager.');
}

Directory.current = initialDirectory;
}

Future<ProcessResult> _runCommand(
String command, List<String> arguments) async {
final process = await Process.start(command, arguments);

// Listen to stdout
process.stdout.transform(utf8.decoder).listen((data) {
print(data);
});

// Listen to stderr
process.stderr.transform(utf8.decoder).listen((data) {
print('stderr output: $data');
});

// Wait for the process to complete
final exitCode = await process.exitCode;

if (exitCode != 0) {
print('Command failed: $command ${arguments.join(' ')}');
}

return ProcessResult(process.pid, exitCode, '', '');
}
63 changes: 0 additions & 63 deletions .github/workflows/scripts/swift-integration.sh

This file was deleted.

1 change: 1 addition & 0 deletions melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +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 && \
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 @@ -15,6 +15,7 @@
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
A83F699FC746D5736A6B5780 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E8EC7192C60686BF1D599360 /* Pods_Runner.framework */; };
78A318202AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage in Frameworks */ = {isa = PBXBuildFile; productRef = 78A3181F2AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -56,6 +57,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
78A318202AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage in Frameworks */,
A83F699FC746D5736A6B5780 /* Pods_Runner.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -131,6 +133,9 @@

/* Begin PBXNativeTarget section */
97C146ED1CF9000F007C117D /* Runner */ = {
packageProductDependencies = (
78A3181F2AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage */,
);
isa = PBXNativeTarget;
buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */;
buildPhases = (
Expand All @@ -157,6 +162,9 @@

/* Begin PBXProject section */
97C146E61CF9000F007C117D /* Project object */ = {
packageReferences = (
781AD8BC2B33823900A9FFBB /* XCLocalSwiftPackageReference "Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage" */,
);
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1510;
Expand Down Expand Up @@ -571,6 +579,18 @@
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
/* Begin XCLocalSwiftPackageReference section */
781AD8BC2B33823900A9FFBB /* XCLocalSwiftPackageReference "Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage" */ = {
isa = XCLocalSwiftPackageReference;
relativePath = Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage;
};
/* End XCLocalSwiftPackageReference section */
/* Begin XCSwiftPackageProductDependency section */
78A3181F2AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage */ = {
isa = XCSwiftPackageProductDependency;
productName = FlutterGeneratedPluginSwiftPackage;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 97C146E61CF9000F007C117D /* Project object */;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<PreActions>
<ExecutionAction
ActionType = "Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction">
<ActionContent
title = "Run Prepare Flutter Framework Script"
scriptText = "/bin/sh &quot;$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh&quot; prepare&#10;">
<EnvironmentBuildable>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "97C146ED1CF9000F007C117D"
BuildableName = "Runner.app"
BlueprintName = "Runner"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
</EnvironmentBuildable>
</ActionContent>
</ExecutionAction>
</PreActions>
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ Pod::Spec.new do |s|
s.license = { :file => '../LICENSE' }
s.authors = 'The Chromium Authors'
s.source = { :path => '.' }

s.source_files = 'Classes/**/*.{h,m}'
s.public_header_files = 'Classes/Public/*.h'
s.private_header_files = 'Classes/Private/*.h'
s.source_files = 'cloud_firestore/Sources/cloud_firestore/**/*.{h,m}'
s.public_header_files = 'cloud_firestore/Sources/cloud_firestore/include/Public/**/*.h'
s.private_header_files = 'cloud_firestore/Sources/cloud_firestore/include/Private/**/*.h'

s.ios.deployment_target = '13.0'
s.dependency 'Flutter'
Expand All @@ -37,7 +36,7 @@ Pod::Spec.new do |s|

s.static_framework = true
s.pod_target_xcconfig = {
'GCC_PREPROCESSOR_DEFINITIONS' => "LIBRARY_VERSION=\\@\\\"#{library_version}\\\" LIBRARY_NAME=\\@\\\"flutter-fire-fst\\\"",
'GCC_PREPROCESSOR_DEFINITIONS' => "LIBRARY_VERSION=\\\"#{library_version}\\\" LIBRARY_NAME=\\\"flutter-fire-fst\\\"",
'DEFINES_MODULE' => 'YES'
}
end
Loading

0 comments on commit 0420eab

Please sign in to comment.