Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPM Support #2280

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8adbf8e
update folder structiure to support SPM
denrase Sep 10, 2024
a0de8e2
Merge branch 'main' into feat/spm
denrase Oct 1, 2024
0ccc10e
remove trailing comma
denrase Oct 1, 2024
a2afc01
update folder structure for mac
denrase Oct 1, 2024
16bae70
Merge branch 'main' into feat/spm
denrase Oct 8, 2024
0636b64
Merge branch 'main' into feat/spm
denrase Nov 5, 2024
9a635fa
fix spm import
denrase Nov 5, 2024
6034522
update to import correctly (u
denrase Nov 5, 2024
acc2ff0
move to swift as main spm package
denrase Nov 6, 2024
160e5a5
setup macOS
denrase Nov 6, 2024
31fcd63
prefix hybrid import with _
denrase Nov 6, 2024
866fe0f
add cl entry, update hybrid module name
denrase Nov 6, 2024
bb6d8ac
add spm to guthub workflow
denrase Nov 6, 2024
a4e2e38
update Package.swift to use remote sentry-cocoa
denrase Nov 6, 2024
c694a20
Merge branch 'main' into feat/spm
denrase Nov 11, 2024
249bb1e
bump
denrase Nov 11, 2024
00cd940
Merge branch 'main' into feat/spm
denrase Nov 25, 2024
aaf4042
Merge branch 'main' into feat/spm
denrase Dec 9, 2024
45b985e
Bump sentry cocoa version
denrase Dec 9, 2024
b2e572d
Merge branch 'main' into feat/spm
denrase Dec 11, 2024
bffad02
update script to also set sentry-cocoa verison in spm file
denrase Dec 11, 2024
cc12932
Merge branch 'main' into feat/spm
denrase Dec 11, 2024
a6d93f2
fix cl
denrase Dec 17, 2024
7dc46fd
Merge branch 'main' into feat/spm
denrase Dec 17, 2024
b1b32ca
Bump to release version
denrase Dec 17, 2024
a63be8b
Merge branch 'main' into feat/spm
denrase Dec 17, 2024
b50e0b8
only build and don’t run with spm support
denrase Dec 17, 2024
cf145b9
fix pods file
denrase Dec 17, 2024
b3d4f09
Merge branch 'main' into feat/spm
denrase Dec 19, 2024
5f38dda
remove lefover comment
denrase Dec 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/flutter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,33 @@ jobs:
;;
esac

spm:
name: "SPM"
runs-on: macos-15
timeout-minutes: 30
defaults:
run:
shell: bash
working-directory: flutter/example
strategy:
fail-fast: false
matrix:
target: [ios, macos]

steps:
- uses: actions/checkout@v4
- uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1 # [email protected]
with:
channel: main
- run: flutter upgrade
- run: flutter config --enable-swift-package-manager
- name: Run on iOS
if: matrix.target == 'ios'
run: flutter build ios --no-codesign
- name: Run on macOS
if: matrix.target == 'macos'
run: flutter build macos

analyze:
uses: ./.github/workflows/analyze.yml
with:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

- Check `SentryTracer` type in TTFD tracker ([#2508](https://github.com/getsentry/sentry-dart/pull/2508))
- Warning (in a debug build) if a potentially sensitive widget is not masked or unmasked explicitly ([#2375](https://github.com/getsentry/sentry-dart/pull/2375))
- SPM Support ([#2280](https://github.com/getsentry/sentry-dart/pull/2280))

### Dependencies

Expand Down
4 changes: 4 additions & 0 deletions flutter/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ build/
.cxx/

.vscode/launch.json
cocoa_bindings_temp

ios/sentry_flutter/Package.resolved

temp
6 changes: 5 additions & 1 deletion flutter/ios/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ Icon?
.tags*

/Flutter/Generated.xcconfig
/Flutter/flutter_export_environment.sh
/Flutter/flutter_export_environment.sh

.build
.swiftpm
Package.resolved
Empty file removed flutter/ios/Assets/.gitkeep
Empty file.
10 changes: 0 additions & 10 deletions flutter/ios/Classes/SentryFlutterPlugin.h

This file was deleted.

15 changes: 0 additions & 15 deletions flutter/ios/Classes/SentryFlutterPlugin.m

This file was deleted.

4 changes: 2 additions & 2 deletions flutter/ios/sentry_flutter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Sentry SDK for Flutter with support to native through sentry-cocoa.
s.authors = "Sentry"
s.source = { :git => "https://github.com/getsentry/sentry-dart.git",
:tag => s.version.to_s }
s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h'
s.source_files = 'sentry_flutter/Sources/**/*'
s.public_header_files = 'sentry_flutter/Sources/**/*.h'
s.dependency 'Sentry/HybridSDK', '8.42.0'
s.ios.dependency 'Flutter'
s.osx.dependency 'FlutterMacOS'
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions flutter/ios/sentry_flutter/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "sentry_flutter",
platforms: [
.iOS("12.0"),
.macOS("10.13")
],
products: [
.library(name: "sentry-flutter", targets: ["sentry_flutter", "sentry_flutter_objc"])
],
dependencies: [
.package(url: "https://github.com/getsentry/sentry-cocoa", from: "8.42.0")
],
targets: [
.target(
name: "sentry_flutter",
dependencies: [
"sentry_flutter_objc",
.product(name: "Sentry", package: "sentry-cocoa")
]
),
// SPM does not support mixed-language targets, so we need to move the ObjC files into a separate one
.target(
name: "sentry_flutter_objc",
dependencies: [
.product(name: "Sentry", package: "sentry-cocoa")
]
)
]
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import Sentry

#if SWIFT_PACKAGE
import Sentry._Hybrid
import sentry_flutter_objc
#endif

#if os(iOS)
import Flutter
import UIKit
Expand All @@ -11,7 +17,7 @@ import CoreVideo
// swiftlint:disable file_length function_body_length

// swiftlint:disable:next type_body_length
public class SentryFlutterPluginApple: NSObject, FlutterPlugin {
public class SentryFlutterPlugin: NSObject, FlutterPlugin {
buenaflor marked this conversation as resolved.
Show resolved Hide resolved
private let channel: FlutterMethodChannel

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

let instance = SentryFlutterPluginApple(channel: channel)
let instance = SentryFlutterPlugin(channel: channel)
registrar.addMethodCallDelegate(instance, channel: channel)
}

Expand Down Expand Up @@ -294,7 +300,7 @@ public class SentryFlutterPluginApple: NSObject, FlutterPlugin {
}

let version = PrivateSentrySDKOnly.getSdkVersionString()
PrivateSentrySDKOnly.setSdkName(SentryFlutterPluginApple.nativeClientName, andVersionString: version)
PrivateSentrySDKOnly.setSdkName(SentryFlutterPlugin.nativeClientName, andVersionString: version)

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

#if canImport(UIKit) && !SENTRY_NO_UIKIT
#if os(iOS) || os(tvOS)
let breadcrumbConverter = SentryFlutterReplayBreadcrumbConverter()
let screenshotProvider = SentryFlutterReplayScreenshotProvider(channel: self.channel)
PrivateSentrySDKOnly.configureSessionReplay(with: breadcrumbConverter, screenshotProvider: screenshotProvider)
let breadcrumbConverter = SentryFlutterReplayBreadcrumbConverter()
let screenshotProvider = SentryFlutterReplayScreenshotProvider(channel: self.channel)
PrivateSentrySDKOnly.configureSessionReplay(with: breadcrumbConverter, screenshotProvider: screenshotProvider)
#endif
#endif

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

switch sdk["name"] as? String {
case SentryFlutterPluginApple.nativeClientName:
case SentryFlutterPlugin.nativeClientName:
#if os(OSX)
let origin = "mac"
#elseif os(watchOS)
Expand Down Expand Up @@ -473,7 +479,7 @@ public class SentryFlutterPluginApple: NSObject, FlutterPlugin {
let isColdStart = appStartMeasurement.type == .cold

let item: [String: Any] = [
"pluginRegistrationTime": SentryFlutterPluginApple.pluginRegistrationTime,
"pluginRegistrationTime": SentryFlutterPlugin.pluginRegistrationTime,
"appStartTime": appStartTime,
"isColdStart": isColdStart,
"nativeSpanTimes": nativeSpanTimes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#import "SentryFlutterReplayBreadcrumbConverter.h"
#import "include/SentryFlutterReplayBreadcrumbConverter.h"

@import Sentry;

#if SWIFT_PACKAGE
@import Sentry._Hybrid;
#endif

#if SENTRY_TARGET_REPLAY_SUPPORTED

@implementation SentryFlutterReplayBreadcrumbConverter {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
@import Sentry;

#if SWIFT_PACKAGE
@import Sentry._Hybrid;
#endif

#if SENTRY_TARGET_REPLAY_SUPPORTED
#import "SentryFlutterReplayScreenshotProvider.h"
#import <Flutter/Flutter.h>
Expand Down
1 change: 0 additions & 1 deletion flutter/macos/Classes/SentryFlutter.swift

This file was deleted.

1 change: 0 additions & 1 deletion flutter/macos/Classes/SentryFlutterPlugin.h

This file was deleted.

1 change: 0 additions & 1 deletion flutter/macos/Classes/SentryFlutterPlugin.m

This file was deleted.

1 change: 0 additions & 1 deletion flutter/macos/Classes/SentryFlutterPluginApple.swift

This file was deleted.

1 change: 1 addition & 0 deletions flutter/macos/sentry_flutter/Package.swift
48 changes: 39 additions & 9 deletions flutter/scripts/update-cocoa.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,55 @@
set -euo pipefail

cd $(dirname "$0")/../ios
file='sentry_flutter.podspec'
content=$(cat $file)
regex="('Sentry/HybridSDK', *)'([0-9\.]+(\-[a-z0-9\.]+)?)'"
if ! [[ $content =~ $regex ]]; then

get_podspec_version() {
local file='sentry_flutter.podspec'
local content=$(cat $file)
regex="('Sentry/HybridSDK', *)'([0-9\.]+(\-[a-z0-9\.]+)?)'"
if ! [[ $content =~ $regex ]]; then
echo "Failed to find the plugin version in $file"
exit 1
else
echo "${BASH_REMATCH[2]}"
fi
}

set_podspec_version() {
local file='sentry_flutter.podspec'
local content=$(cat $file)
regex="('Sentry/HybridSDK', *)'([0-9\.]+(\-[a-z0-9\.]+)?)'"
if ! [[ $content =~ $regex ]]; then
echo "Failed to find the plugin version in $file"
exit 1
else
newValue="${BASH_REMATCH[1]}'$1'"
echo "${content/${BASH_REMATCH[0]}/$newValue}" >$file
fi
}

set_spm_version() {
local file='sentry_flutter/Package.swift'
local content=$(cat $file)
regex="(url: *['\"]https://github.com/getsentry/sentry-cocoa['\"], *from: *)['\"]([0-9\.]+(-[a-z0-9\.]+)?)['\"]"
if ! [[ $content =~ $regex ]]; then
echo "Failed to find the plugin version in $file"
exit 1
fi
else
newValue="${BASH_REMATCH[1]}\"$1\""
echo "${content/${BASH_REMATCH[0]}/$newValue}" >$file
fi
}

case $1 in
get-version)
echo ${BASH_REMATCH[2]}
echo $(get_podspec_version)
;;
get-repo)
echo "https://github.com/getsentry/sentry-cocoa.git"
;;
set-version)
newValue="${BASH_REMATCH[1]}'$2'"
echo "${content/${BASH_REMATCH[0]}/$newValue}" >$file
../scripts/generate-cocoa-bindings.sh "$2"
set_podspec_version "$2"
set_spm_version "$2"
;;
*)
echo "Unknown argument $1"
Expand Down
Loading