Skip to content

Commit

Permalink
Reimplement a small bit of ObjC in Swift.
Browse files Browse the repository at this point in the history
This prevents us from needing an entirely separate module for just one ObjC file.
  • Loading branch information
bjhomer committed Jul 27, 2021
1 parent 3cfaf4f commit f54988e
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 74 deletions.
22 changes: 7 additions & 15 deletions Package.swift
Expand Up @@ -35,10 +35,13 @@ let package = Package(
path: "Sources/Model/ObjC",
publicHeadersPath: ".",
cSettings: [.headerSearchPath("../../Event Logging/private")]),

.target(
name: "AutomatticTracksModel",
dependencies: ["AutomatticTracksModelObjC", "Sentry",
"CocoaLumberjack"
dependencies: [
"AutomatticTracksModelObjC",
"Sentry",
"CocoaLumberjack"
],
path: "Sources/Model/Swift"),

Expand All @@ -56,25 +59,15 @@ let package = Package(
publicHeadersPath: ".",
cSettings: [.headerSearchPath("private")]),



.target(
name: "AutomatticCrashLoggingObjC",
dependencies: ["Sentry"],
path: "Sources/Remote Logging/Crash Logging/ObjC",
publicHeadersPath: "."),

.target(
name: "AutomatticRemoteLogging",
dependencies: ["Sentry",
.product(name: "Clibsodium", package: "Sodium"),
"Sodium",
.product(name: "CocoaLumberjackSwift", package: "CocoaLumberjack"),
"AutomatticTracksModel",
"AutomatticTracksEventLogging",
"AutomatticCrashLoggingObjC"],
path: "Sources/Remote Logging",
exclude: ["Crash Logging/ObjC"]),
"AutomatticTracksEventLogging"],
path: "Sources/Remote Logging"),



Expand All @@ -99,7 +92,6 @@ let package = Package(
dependencies: [
"AutomatticTracks",
"AutomatticTracksEventLogging",
"AutomatticCrashLoggingObjC",
"AutomatticTracksModel",
.product(name: "OHHTTPStubsSwift", package: "OHHTTPStubs"),
.product(name: "CocoaLumberjackSwift", package: "CocoaLumberjack")
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -24,7 +24,7 @@ import AutomatticTracksEventLogging
import AutomatticRemoteLogging

// Running experiments using the internal 'ExPlat' tool
import AutomatticABTesting
import AutomatticExperiments

// Displaying crash logs in your app
import AutomatticCrashLoggingUI
Expand Down
Expand Up @@ -58,6 +58,7 @@ private extension UIApplication {
let sharedAppSelector = Selector(("sharedApplication"))
if let appClass = NSClassFromString("UIApplication"),
let performableClass = (appClass as Any) as? NSObjectProtocol,
performableClass.responds(to: sharedAppSelector),
let performResult = performableClass.perform(sharedAppSelector),
let app = performResult.takeUnretainedValue() as? UIApplication
{
Expand Down
Expand Up @@ -5,7 +5,6 @@ import CocoaLumberjack
#if SWIFT_PACKAGE
import AutomatticTracksEventLogging
import AutomatticTracksModel
import AutomatticCrashLoggingObjC
import CocoaLumberjackSwift
#endif

Expand Down
10 changes: 0 additions & 10 deletions Sources/Remote Logging/Crash Logging/ObjC/SentryClient+Shim.h

This file was deleted.

40 changes: 0 additions & 40 deletions Sources/Remote Logging/Crash Logging/ObjC/SentryClient+Shim.m

This file was deleted.

@@ -0,0 +1,6 @@
import Foundation

#if SWIFT_PACKAGE
@_exported import AutomatticTracksModel
@_exported import AutomatticTracksModelObjC
#endif
53 changes: 53 additions & 0 deletions Sources/Remote Logging/Crash Logging/SentryClient+Shim.swift
@@ -0,0 +1,53 @@
//
// SentryClient+Shim.swift
// AutomatticTracksiOS
//
// Created by BJ Homer on 7/27/21.
//

import Foundation
import Sentry


@objc
private protocol SentryClient_InternalMethods {
@objc(prepareEvent:withScope:alwaysAttachStacktrace:isCrashEvent:)
func prepareEvent(_ e: Sentry.Event,
withScope: Sentry.Scope,
alwaysAttachStacktrace: Bool,
isCrashEvent:Bool
) -> Sentry.Event?
}

extension Sentry.Client {
/*
* A wrapper around a private method in `SentryClient`. If it's unavailable (say the library
changes),
* the worst that should happen is that the stack trace is no longer available on events sent
manually using this method.
*
* We can remove this once the Sentry SDK allows for capturing events and being notified once
they're delivered.
* ref: https://github.com/getsentry/sentry-cocoa/issues/660
*/
@objc(addStackTraceToEvent:forClient:)
func addStackTrace(to event: Sentry.Event, for client: Sentry.Client) -> Sentry.Event {

let sel = #selector(SentryClient_InternalMethods.prepareEvent(_:withScope:alwaysAttachStacktrace:isCrashEvent:))

if !client.responds(to: sel) {
return event
}

let scope = SentrySDK.currentHub().getScope()
guard let eventWithStackTrace = (self as AnyObject).prepareEvent(event, withScope: scope, alwaysAttachStacktrace: true, isCrashEvent: false)
else {
return event
}

if let stackTrace = eventWithStackTrace.threads?.first?.stacktrace {
eventWithStackTrace.stacktrace = stackTrace
}
return event
}
}

This file was deleted.

0 comments on commit f54988e

Please sign in to comment.