Skip to content

Commit 7659cbe

Browse files
authored
SPM Support (#2280)
1 parent ea6d86d commit 7659cbe

28 files changed

+149
-50
lines changed

.github/workflows/flutter.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,33 @@ jobs:
9797
;;
9898
esac
9999
100+
spm:
101+
name: "SPM"
102+
runs-on: macos-15
103+
timeout-minutes: 30
104+
defaults:
105+
run:
106+
shell: bash
107+
working-directory: flutter/example
108+
strategy:
109+
fail-fast: false
110+
matrix:
111+
target: [ios, macos]
112+
113+
steps:
114+
- uses: actions/checkout@v4
115+
- uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1 # [email protected]
116+
with:
117+
channel: main
118+
- run: flutter upgrade
119+
- run: flutter config --enable-swift-package-manager
120+
- name: Run on iOS
121+
if: matrix.target == 'ios'
122+
run: flutter build ios --no-codesign
123+
- name: Run on macOS
124+
if: matrix.target == 'macos'
125+
run: flutter build macos
126+
100127
analyze:
101128
uses: ./.github/workflows/analyze.yml
102129
with:

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Features
66

77
- Add SentryReplayQuality setting (`options.experimental.replay.quality`) ([#2582](https://github.com/getsentry/sentry-dart/pull/2582))
8+
- SPM Support ([#2280](https://github.com/getsentry/sentry-dart/pull/2280))
89

910
### Dependencies
1011

flutter/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ build/
1010
.cxx/
1111

1212
.vscode/launch.json
13+
cocoa_bindings_temp
14+
15+
ios/sentry_flutter/Package.resolved
16+
1317
temp

flutter/ios/.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,8 @@ Icon?
3434
.tags*
3535

3636
/Flutter/Generated.xcconfig
37-
/Flutter/flutter_export_environment.sh
37+
/Flutter/flutter_export_environment.sh
38+
39+
.build
40+
.swiftpm
41+
Package.resolved

flutter/ios/Assets/.gitkeep

Whitespace-only changes.

flutter/ios/Classes/SentryFlutterPlugin.h

Lines changed: 0 additions & 10 deletions
This file was deleted.

flutter/ios/Classes/SentryFlutterPlugin.m

Lines changed: 0 additions & 15 deletions
This file was deleted.

flutter/ios/sentry_flutter.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Sentry SDK for Flutter with support to native through sentry-cocoa.
1414
s.authors = "Sentry"
1515
s.source = { :git => "https://github.com/getsentry/sentry-dart.git",
1616
:tag => s.version.to_s }
17-
s.source_files = 'Classes/**/*'
18-
s.public_header_files = 'Classes/**/*.h'
17+
s.source_files = 'sentry_flutter/Sources/**/*'
18+
s.public_header_files = 'sentry_flutter/Sources/**/*.h'
1919
s.dependency 'Sentry/HybridSDK', '8.43.0'
2020
s.ios.dependency 'Flutter'
2121
s.osx.dependency 'FlutterMacOS'

flutter/ios/sentry_flutter/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// swift-tools-version: 5.9
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "sentry_flutter",
8+
platforms: [
9+
.iOS("12.0"),
10+
.macOS("10.13")
11+
],
12+
products: [
13+
.library(name: "sentry-flutter", targets: ["sentry_flutter", "sentry_flutter_objc"])
14+
],
15+
dependencies: [
16+
.package(url: "https://github.com/getsentry/sentry-cocoa", from: "8.43.0")
17+
],
18+
targets: [
19+
.target(
20+
name: "sentry_flutter",
21+
dependencies: [
22+
"sentry_flutter_objc",
23+
.product(name: "Sentry", package: "sentry-cocoa")
24+
]
25+
),
26+
// SPM does not support mixed-language targets, so we need to move the ObjC files into a separate one
27+
.target(
28+
name: "sentry_flutter_objc",
29+
dependencies: [
30+
.product(name: "Sentry", package: "sentry-cocoa")
31+
]
32+
)
33+
]
34+
)

flutter/ios/Classes/SentryFlutterPluginApple.swift renamed to flutter/ios/sentry_flutter/Sources/sentry_flutter/SentryFlutterPlugin.swift

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
import Sentry
2+
3+
#if SWIFT_PACKAGE
4+
import Sentry._Hybrid
5+
import sentry_flutter_objc
6+
#endif
7+
28
#if os(iOS)
39
import Flutter
410
import UIKit
@@ -11,7 +17,7 @@ import CoreVideo
1117
// swiftlint:disable file_length function_body_length
1218

1319
// swiftlint:disable:next type_body_length
14-
public class SentryFlutterPluginApple: NSObject, FlutterPlugin {
20+
public class SentryFlutterPlugin: NSObject, FlutterPlugin {
1521
private let channel: FlutterMethodChannel
1622

1723
private static let nativeClientName = "sentry.cocoa.flutter"
@@ -27,7 +33,7 @@ public class SentryFlutterPluginApple: NSObject, FlutterPlugin {
2733
let channel = FlutterMethodChannel(name: "sentry_flutter", binaryMessenger: registrar.messenger)
2834
#endif
2935

30-
let instance = SentryFlutterPluginApple(channel: channel)
36+
let instance = SentryFlutterPlugin(channel: channel)
3137
registrar.addMethodCallDelegate(instance, channel: channel)
3238
}
3339

@@ -294,7 +300,7 @@ public class SentryFlutterPluginApple: NSObject, FlutterPlugin {
294300
}
295301

296302
let version = PrivateSentrySDKOnly.getSdkVersionString()
297-
PrivateSentrySDKOnly.setSdkName(SentryFlutterPluginApple.nativeClientName, andVersionString: version)
303+
PrivateSentrySDKOnly.setSdkName(SentryFlutterPlugin.nativeClientName, andVersionString: version)
298304

299305
// note : for now, in sentry-cocoa, beforeSend is not called before captureEnvelope
300306
options.beforeSend = { event in
@@ -337,9 +343,9 @@ public class SentryFlutterPluginApple: NSObject, FlutterPlugin {
337343

338344
#if canImport(UIKit) && !SENTRY_NO_UIKIT
339345
#if os(iOS) || os(tvOS)
340-
let breadcrumbConverter = SentryFlutterReplayBreadcrumbConverter()
341-
let screenshotProvider = SentryFlutterReplayScreenshotProvider(channel: self.channel)
342-
PrivateSentrySDKOnly.configureSessionReplay(with: breadcrumbConverter, screenshotProvider: screenshotProvider)
346+
let breadcrumbConverter = SentryFlutterReplayBreadcrumbConverter()
347+
let screenshotProvider = SentryFlutterReplayScreenshotProvider(channel: self.channel)
348+
PrivateSentrySDKOnly.configureSessionReplay(with: breadcrumbConverter, screenshotProvider: screenshotProvider)
343349
#endif
344350
#endif
345351

@@ -358,7 +364,7 @@ public class SentryFlutterPluginApple: NSObject, FlutterPlugin {
358364
if isValidSdk(sdk: sdk) {
359365

360366
switch sdk["name"] as? String {
361-
case SentryFlutterPluginApple.nativeClientName:
367+
case SentryFlutterPlugin.nativeClientName:
362368
#if os(OSX)
363369
let origin = "mac"
364370
#elseif os(watchOS)
@@ -473,7 +479,7 @@ public class SentryFlutterPluginApple: NSObject, FlutterPlugin {
473479
let isColdStart = appStartMeasurement.type == .cold
474480

475481
let item: [String: Any] = [
476-
"pluginRegistrationTime": SentryFlutterPluginApple.pluginRegistrationTime,
482+
"pluginRegistrationTime": SentryFlutterPlugin.pluginRegistrationTime,
477483
"appStartTime": appStartTime,
478484
"isColdStart": isColdStart,
479485
"nativeSpanTimes": nativeSpanTimes

flutter/ios/Classes/SentryFlutterReplayBreadcrumbConverter.m renamed to flutter/ios/sentry_flutter/Sources/sentry_flutter_objc/SentryFlutterReplayBreadcrumbConverter.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
#import "SentryFlutterReplayBreadcrumbConverter.h"
1+
#import "include/SentryFlutterReplayBreadcrumbConverter.h"
22

33
@import Sentry;
44

5+
#if SWIFT_PACKAGE
6+
@import Sentry._Hybrid;
7+
#endif
8+
59
#if SENTRY_TARGET_REPLAY_SUPPORTED
610

711
@implementation SentryFlutterReplayBreadcrumbConverter {

flutter/ios/Classes/SentryFlutterReplayScreenshotProvider.m renamed to flutter/ios/sentry_flutter/Sources/sentry_flutter_objc/SentryFlutterReplayScreenshotProvider.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
@import Sentry;
22

3+
#if SWIFT_PACKAGE
4+
@import Sentry._Hybrid;
5+
#endif
6+
37
#if SENTRY_TARGET_REPLAY_SUPPORTED
48
#import "SentryFlutterReplayScreenshotProvider.h"
59
#import <Flutter/Flutter.h>

flutter/macos/Classes/SentryFlutter.swift

Lines changed: 0 additions & 1 deletion
This file was deleted.

flutter/macos/Classes/SentryFlutterPlugin.h

Lines changed: 0 additions & 1 deletion
This file was deleted.

flutter/macos/Classes/SentryFlutterPlugin.m

Lines changed: 0 additions & 1 deletion
This file was deleted.

flutter/macos/Classes/SentryFlutterPluginApple.swift

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../ios/sentry_flutter/Package.swift
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../ios/sentry_flutter/Sources/sentry_flutter/SentryFlutter.swift
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../ios/sentry_flutter/Sources/sentry_flutter/SentryFlutterPlugin.swift
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../ios/sentry_flutter/Sources/sentry_flutter_objc/SentryFlutterReplayBreadcrumbConverter.m
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../ios/sentry_flutter/Sources/sentry_flutter_objc/SentryFlutterReplayScreenshotProvider.m
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../ios/sentry_flutter/Sources/sentry_flutter_objc/include/SentryFlutterReplayBreadcrumbConverter.h
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../ios/sentry_flutter/Sources/sentry_flutter_objc/include/SentryFlutterReplayScreenshotProvider.h

flutter/scripts/update-cocoa.sh

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,55 @@
22
set -euo pipefail
33

44
cd $(dirname "$0")/../ios
5-
file='sentry_flutter.podspec'
6-
content=$(cat $file)
7-
regex="('Sentry/HybridSDK', *)'([0-9\.]+(\-[a-z0-9\.]+)?)'"
8-
if ! [[ $content =~ $regex ]]; then
5+
6+
get_podspec_version() {
7+
local file='sentry_flutter.podspec'
8+
local content=$(cat $file)
9+
regex="('Sentry/HybridSDK', *)'([0-9\.]+(\-[a-z0-9\.]+)?)'"
10+
if ! [[ $content =~ $regex ]]; then
11+
echo "Failed to find the plugin version in $file"
12+
exit 1
13+
else
14+
echo "${BASH_REMATCH[2]}"
15+
fi
16+
}
17+
18+
set_podspec_version() {
19+
local file='sentry_flutter.podspec'
20+
local content=$(cat $file)
21+
regex="('Sentry/HybridSDK', *)'([0-9\.]+(\-[a-z0-9\.]+)?)'"
22+
if ! [[ $content =~ $regex ]]; then
23+
echo "Failed to find the plugin version in $file"
24+
exit 1
25+
else
26+
newValue="${BASH_REMATCH[1]}'$1'"
27+
echo "${content/${BASH_REMATCH[0]}/$newValue}" >$file
28+
fi
29+
}
30+
31+
set_spm_version() {
32+
local file='sentry_flutter/Package.swift'
33+
local content=$(cat $file)
34+
regex="(url: *['\"]https://github.com/getsentry/sentry-cocoa['\"], *from: *)['\"]([0-9\.]+(-[a-z0-9\.]+)?)['\"]"
35+
if ! [[ $content =~ $regex ]]; then
936
echo "Failed to find the plugin version in $file"
1037
exit 1
11-
fi
38+
else
39+
newValue="${BASH_REMATCH[1]}\"$1\""
40+
echo "${content/${BASH_REMATCH[0]}/$newValue}" >$file
41+
fi
42+
}
1243

1344
case $1 in
1445
get-version)
15-
echo ${BASH_REMATCH[2]}
46+
echo $(get_podspec_version)
1647
;;
1748
get-repo)
1849
echo "https://github.com/getsentry/sentry-cocoa.git"
1950
;;
2051
set-version)
21-
newValue="${BASH_REMATCH[1]}'$2'"
22-
echo "${content/${BASH_REMATCH[0]}/$newValue}" >$file
23-
../scripts/generate-cocoa-bindings.sh "$2"
52+
set_podspec_version "$2"
53+
set_spm_version "$2"
2454
;;
2555
*)
2656
echo "Unknown argument $1"

0 commit comments

Comments
 (0)