From e475f16d53a84eed87c70cade18be603fbf409d9 Mon Sep 17 00:00:00 2001 From: Mert Buran Date: Tue, 27 Jul 2021 13:53:39 +0200 Subject: [PATCH] Crash Reporter re-enabled for SPM --- Cartfile | 1 + Cartfile.private | 1 - .../xcschemes}/DatadogCrashReporting.xcscheme | 0 Makefile | 4 +- Package.swift | 13 ++++++ .../DDCrashReportingPluginType.swift | 40 +------------------ Sources/Datadog/DatadogConfiguration.swift | 2 - .../DatadogConfiguration+objc.swift | 2 - .../CTProject.xcodeproj/project.pbxproj | 6 +++ .../carthage/CTProject/ViewController.swift | 2 + dependency-manager-tests/carthage/Makefile | 4 +- .../SPMProject.xcodeproj.src/project.pbxproj | 18 ++++----- .../spm/SPMProject/ViewController.swift | 2 + .../enable-crash-reporting.sh | 13 ------ 14 files changed, 38 insertions(+), 70 deletions(-) delete mode 100644 Cartfile.private rename {tools/crash-reporting-patch => Datadog/Datadog.xcodeproj/xcshareddata/xcschemes}/DatadogCrashReporting.xcscheme (100%) delete mode 100755 tools/crash-reporting-patch/enable-crash-reporting.sh diff --git a/Cartfile b/Cartfile index 8d56f1a933..44747c45a4 100644 --- a/Cartfile +++ b/Cartfile @@ -1 +1,2 @@ github "lyft/Kronos" ~> 4.2 +github "microsoft/plcrashreporter" == 1.8.1 diff --git a/Cartfile.private b/Cartfile.private deleted file mode 100644 index 1d4c1dfaee..0000000000 --- a/Cartfile.private +++ /dev/null @@ -1 +0,0 @@ -github "microsoft/plcrashreporter" ~> 1.8.1 diff --git a/tools/crash-reporting-patch/DatadogCrashReporting.xcscheme b/Datadog/Datadog.xcodeproj/xcshareddata/xcschemes/DatadogCrashReporting.xcscheme similarity index 100% rename from tools/crash-reporting-patch/DatadogCrashReporting.xcscheme rename to Datadog/Datadog.xcodeproj/xcshareddata/xcschemes/DatadogCrashReporting.xcscheme diff --git a/Makefile b/Makefile index f96720d558..4260bbc104 100644 --- a/Makefile +++ b/Makefile @@ -17,9 +17,8 @@ export DD_SDK_TESTING_XCCONFIG_CI define DD_SDK_BASE_XCCONFIG // Active compilation conditions - only enabled on local machine:\n // - DD_SDK_ENABLE_INTERNAL_MONITORING - enables Internal Monitoring APIs\n -// - DD_SDK_ENABLE_EXPERIMENTAL_APIS - enables APIs which are not available in released version of the SDK\n // - DD_SDK_COMPILED_FOR_TESTING - conditions the SDK code compiled for testing\n -SWIFT_ACTIVE_COMPILATION_CONDITIONS = $(inherited) DD_SDK_ENABLE_INTERNAL_MONITORING DD_SDK_ENABLE_EXPERIMENTAL_APIS DD_SDK_COMPILED_FOR_TESTING\n +SWIFT_ACTIVE_COMPILATION_CONDITIONS = $(inherited) DD_SDK_ENABLE_INTERNAL_MONITORING DD_SDK_COMPILED_FOR_TESTING\n \n // To build only active architecture for all configurations.\n // TODO: RUMM-1200 We can perhaps remove this fix when carthage supports pre-build xcframeworks.\n @@ -43,7 +42,6 @@ export DD_SDK_DATADOG_XCCONFIG # Installs tools and dependencies with homebrew. # Do not call 'brew update' and instead let Bitrise use its own brew bottle mirror. dependencies: - @./tools/crash-reporting-patch/enable-crash-reporting.sh @echo "โš™๏ธ Installing dependencies..." @brew list swiftlint &>/dev/null || brew install swiftlint @brew upgrade carthage diff --git a/Package.swift b/Package.swift index 5296e93f25..8638cab917 100644 --- a/Package.swift +++ b/Package.swift @@ -28,9 +28,15 @@ let package = Package( type: .static, targets: ["DatadogObjc"] ), + .library( + name: "DatadogCrashReporting", + type: .static, + targets: ["DatadogCrashReporting"] + ), ], dependencies: [ .package(name: "Kronos", url: "https://github.com/lyft/Kronos.git", from: "4.2.1"), + .package(name: "PLCrashReporter", url: "https://github.com/microsoft/plcrashreporter.git", from: "1.8.1"), ], targets: [ .target( @@ -50,5 +56,12 @@ let package = Package( .target( name: "_Datadog_Private" ), + .target( + name: "DatadogCrashReporting", + dependencies: [ + "Datadog", + .product(name: "CrashReporter", package: "PLCrashReporter"), + ] + ) ] ) diff --git a/Sources/Datadog/CrashReporting/DDCrashReportingPluginType.swift b/Sources/Datadog/CrashReporting/DDCrashReportingPluginType.swift index 64ece945b0..f87e9ec1c7 100644 --- a/Sources/Datadog/CrashReporting/DDCrashReportingPluginType.swift +++ b/Sources/Datadog/CrashReporting/DDCrashReportingPluginType.swift @@ -6,7 +6,6 @@ import Foundation -#if DD_SDK_ENABLE_EXPERIMENTAL_APIS /// Crash Report format supported by Datadog SDK. @objc public class DDCrashReport: NSObject { @@ -21,12 +20,12 @@ public class DDCrashReport: NSObject { /// The last context injected through `inject(context:)` internal let context: Data? - #if DD_SDK_ENABLE_INTERNAL_MONITORING +#if DD_SDK_ENABLE_INTERNAL_MONITORING /// Additional diagnostic information about the crash report, collected for `DatadogCrashReporting` observability. /// Available only if internal monitoring is enabled, disabled by default. /// See: `Datadog.Configuration.Builder.enableInternalMonitoring(clientToken:)`. public var diagnosticInfo: [String: Encodable] = [:] - #endif +#endif public init( date: Date?, @@ -65,38 +64,3 @@ public protocol DDCrashReportingPluginType: AnyObject { /// It is called on a background thread and succeeding calls are synchronized. func inject(context: Data) } - -#else - -@objc -internal class DDCrashReport: NSObject { - internal let date: Date? - internal let type: String - internal let message: String - internal let stackTrace: String - internal let context: Data? - #if DD_SDK_ENABLE_INTERNAL_MONITORING - internal var diagnosticInfo: [String: Encodable] = [:] - #endif - internal init( - date: Date?, - type: String, - message: String, - stackTrace: String, - context: Data? - ) { - self.date = date - self.type = type - self.message = message - self.stackTrace = stackTrace - self.context = context - } -} - -@objc -internal protocol DDCrashReportingPluginType: class { - func readPendingCrashReport(completion: (DDCrashReport?) -> Bool) - func inject(context: Data) -} - -#endif diff --git a/Sources/Datadog/DatadogConfiguration.swift b/Sources/Datadog/DatadogConfiguration.swift index b0dafa676f..a0ca996085 100644 --- a/Sources/Datadog/DatadogConfiguration.swift +++ b/Sources/Datadog/DatadogConfiguration.swift @@ -613,7 +613,6 @@ extension Datadog { return self } -#if DD_SDK_ENABLE_EXPERIMENTAL_APIS // MARK: - Crash Reporting Configuration /// Enables the crash reporting feature. @@ -630,7 +629,6 @@ extension Datadog { configuration.crashReportingPlugin = crashReportingPlugin return self } -#endif #if DD_SDK_ENABLE_INTERNAL_MONITORING // MARK: - Internal Monitoring Configuration diff --git a/Sources/DatadogObjc/DatadogConfiguration+objc.swift b/Sources/DatadogObjc/DatadogConfiguration+objc.swift index ee8e4aa86b..1eb4ef6700 100644 --- a/Sources/DatadogObjc/DatadogConfiguration+objc.swift +++ b/Sources/DatadogObjc/DatadogConfiguration+objc.swift @@ -190,12 +190,10 @@ public class DDConfigurationBuilder: NSObject { _ = sdkBuilder.enableRUM(enabled) } -#if DD_SDK_ENABLE_EXPERIMENTAL_APIS @objc public func enableCrashReporting(using crashReportingPlugin: DDCrashReportingPluginType) { _ = sdkBuilder.enableCrashReporting(using: crashReportingPlugin) } -#endif @objc public func set(endpoint: DDEndpoint) { diff --git a/dependency-manager-tests/carthage/CTProject.xcodeproj/project.pbxproj b/dependency-manager-tests/carthage/CTProject.xcodeproj/project.pbxproj index 275e11d161..bc7d22c723 100644 --- a/dependency-manager-tests/carthage/CTProject.xcodeproj/project.pbxproj +++ b/dependency-manager-tests/carthage/CTProject.xcodeproj/project.pbxproj @@ -20,6 +20,9 @@ 9E9D5E8B25F90FC6002F12A0 /* DatadogObjc.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9E9D5E8625F90FC6002F12A0 /* DatadogObjc.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 9E9D5E8C25F90FC6002F12A0 /* Datadog.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9E9D5E8725F90FC6002F12A0 /* Datadog.xcframework */; }; 9E9D5E8D25F90FC6002F12A0 /* Datadog.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9E9D5E8725F90FC6002F12A0 /* Datadog.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 9EF87B8C26B04E1F00998076 /* CrashReporter.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 615D9E652604B5AB006DC6D1 /* CrashReporter.xcframework */; }; + 9EF87B8D26B04E1F00998076 /* CrashReporter.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 615D9E652604B5AB006DC6D1 /* CrashReporter.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 9EF87B8E26B04E1F00998076 /* DatadogCrashReporting.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 615D9E6A2604B5B1006DC6D1 /* DatadogCrashReporting.xcframework */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -46,6 +49,7 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( + 9EF87B8D26B04E1F00998076 /* CrashReporter.xcframework in Embed Frameworks */, 9E9D5E8D25F90FC6002F12A0 /* Datadog.xcframework in Embed Frameworks */, 9E9D5E8B25F90FC6002F12A0 /* DatadogObjc.xcframework in Embed Frameworks */, 9E9D5E8925F90FC6002F12A0 /* Kronos.xcframework in Embed Frameworks */, @@ -83,9 +87,11 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 9EF87B8C26B04E1F00998076 /* CrashReporter.xcframework in Frameworks */, 9E9D5E8C25F90FC6002F12A0 /* Datadog.xcframework in Frameworks */, 9E9D5E8A25F90FC6002F12A0 /* DatadogObjc.xcframework in Frameworks */, 9E9D5E8825F90FC6002F12A0 /* Kronos.xcframework in Frameworks */, + 9EF87B8E26B04E1F00998076 /* DatadogCrashReporting.xcframework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/dependency-manager-tests/carthage/CTProject/ViewController.swift b/dependency-manager-tests/carthage/CTProject/ViewController.swift index e87dabcb4a..2e8416afae 100644 --- a/dependency-manager-tests/carthage/CTProject/ViewController.swift +++ b/dependency-manager-tests/carthage/CTProject/ViewController.swift @@ -7,6 +7,7 @@ import UIKit import Datadog import DatadogObjc +import DatadogCrashReporting internal class ViewController: UIViewController { private var logger: Logger! // swiftlint:disable:this implicitly_unwrapped_optional @@ -19,6 +20,7 @@ internal class ViewController: UIViewController { trackingConsent: .granted, configuration: Datadog.Configuration .builderUsing(clientToken: "abc", environment: "tests") + .enableCrashReporting(using: DDCrashReportingPlugin()) .build() ) diff --git a/dependency-manager-tests/carthage/Makefile b/dependency-manager-tests/carthage/Makefile index 4231cef06c..30f515e429 100644 --- a/dependency-manager-tests/carthage/Makefile +++ b/dependency-manager-tests/carthage/Makefile @@ -15,7 +15,7 @@ test: @echo "๐Ÿงช Check if expected frameworks exist in $(PWD)/Carthage/Build/" @[ -e "Carthage/Build/Datadog.xcframework" ] && echo "Datadog.xcframework - OK" || { echo "Datadog.xcframework - missing"; false; } @[ -e "Carthage/Build/DatadogObjc.xcframework" ] && echo "DatadogObjc.xcframework - OK" || { echo "DatadogObjc.xcframework - missing"; false; } - @[ ! -e "Carthage/Build/DatadogCrashReporting.xcframework" ] && echo "DatadogCrashReporting.xcframework - is not there ๐Ÿ‘" || { echo "DatadogCrashReporting.xcframework - should not be there"; false; } + @[ -e "Carthage/Build/DatadogCrashReporting.xcframework" ] && echo "DatadogCrashReporting.xcframework - OK" || { echo "DatadogCrashReporting.xcframework - missing"; false; } @[ -e "Carthage/Build/Kronos.xcframework" ] && echo "Kronos.xcframework - OK" || { echo "Kronos.xcframework - missing"; false; } - @[ ! -e "Carthage/Build/CrashReporter.xcframework" ] && echo "CrashReporter.xcframework - is not there ๐Ÿ‘" || { echo "CrashReporter.xcframework - should not be there"; false; } + @[ -e "Carthage/Build/CrashReporter.xcframework" ] && echo "CrashReporter.xcframework - OK" || { echo "CrashReporter.xcframework - missing"; false; } @echo "๐Ÿงช SUCCEEDED" diff --git a/dependency-manager-tests/spm/SPMProject.xcodeproj.src/project.pbxproj b/dependency-manager-tests/spm/SPMProject.xcodeproj.src/project.pbxproj index 197806c610..650b9ed423 100644 --- a/dependency-manager-tests/spm/SPMProject.xcodeproj.src/project.pbxproj +++ b/dependency-manager-tests/spm/SPMProject.xcodeproj.src/project.pbxproj @@ -14,7 +14,7 @@ 61C363E624374D6000C4D4E6 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 61C363E424374D6000C4D4E6 /* LaunchScreen.storyboard */; }; 61C363F124374D6100C4D4E6 /* SPMProjectTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61C363F024374D6100C4D4E6 /* SPMProjectTests.swift */; }; 61C363FC24374D6100C4D4E6 /* SPMProjectUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61C363FB24374D6100C4D4E6 /* SPMProjectUITests.swift */; }; - 61DA9CB6260BA1FA00366408 /* DatadogStatic in Frameworks */ = {isa = PBXBuildFile; productRef = 61DA9CB5260BA1FA00366408 /* DatadogStatic */; }; + 9E73374026B0123500917C24 /* DatadogCrashReporting in Frameworks */ = {isa = PBXBuildFile; productRef = 9E73373F26B0123500917C24 /* DatadogCrashReporting */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -70,7 +70,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 61DA9CB6260BA1FA00366408 /* DatadogStatic in Frameworks */, + 9E73374026B0123500917C24 /* DatadogCrashReporting in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -180,7 +180,7 @@ ); name = SPMProject; packageProductDependencies = ( - 61DA9CB5260BA1FA00366408 /* DatadogStatic */, + 9E73373F26B0123500917C24 /* DatadogCrashReporting */, ); productName = SPMProject; productReference = 61C363D624374D5F00C4D4E6 /* SPMProject.app */; @@ -255,7 +255,7 @@ ); mainGroup = 61C363CD24374D5F00C4D4E6; packageReferences = ( - 61C3640924374DF200C4D4E6 /* XCRemoteSwiftPackageReference "dd-sdk-ios" */, + 9E73373E26B0123500917C24 /* XCRemoteSwiftPackageReference "dd-sdk-ios" */, ); productRefGroup = 61C363D724374D5F00C4D4E6 /* Products */; projectDirPath = ""; @@ -676,9 +676,9 @@ /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ - 61C3640924374DF200C4D4E6 /* XCRemoteSwiftPackageReference "dd-sdk-ios" */ = { + 9E73373E26B0123500917C24 /* XCRemoteSwiftPackageReference "dd-sdk-ios" */ = { isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/DataDog/dd-sdk-ios"; + repositoryURL = "https://github.com/DataDog/dd-sdk-ios/"; requirement = { branch = REMOTE_GIT_REFERENCE; kind = branch; @@ -687,10 +687,10 @@ /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ - 61DA9CB5260BA1FA00366408 /* DatadogStatic */ = { + 9E73373F26B0123500917C24 /* DatadogCrashReporting */ = { isa = XCSwiftPackageProductDependency; - package = 61C3640924374DF200C4D4E6 /* XCRemoteSwiftPackageReference "dd-sdk-ios" */; - productName = DatadogStatic; + package = 9E73373E26B0123500917C24 /* XCRemoteSwiftPackageReference "dd-sdk-ios" */; + productName = DatadogCrashReporting; }; /* End XCSwiftPackageProductDependency section */ }; diff --git a/dependency-manager-tests/spm/SPMProject/ViewController.swift b/dependency-manager-tests/spm/SPMProject/ViewController.swift index 09b1090579..b268b849eb 100644 --- a/dependency-manager-tests/spm/SPMProject/ViewController.swift +++ b/dependency-manager-tests/spm/SPMProject/ViewController.swift @@ -6,6 +6,7 @@ import UIKit import Datadog +import DatadogCrashReporting internal class ViewController: UIViewController { private var logger: Logger! // swiftlint:disable:this implicitly_unwrapped_optional @@ -18,6 +19,7 @@ internal class ViewController: UIViewController { trackingConsent: .granted, configuration: Datadog.Configuration .builderUsing(clientToken: "abc", environment: "tests") + .enableCrashReporting(using: DDCrashReportingPlugin()) .build() ) diff --git a/tools/crash-reporting-patch/enable-crash-reporting.sh b/tools/crash-reporting-patch/enable-crash-reporting.sh deleted file mode 100755 index 7ea30349dd..0000000000 --- a/tools/crash-reporting-patch/enable-crash-reporting.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/zsh - -if [ ! -f "Package.swift" ]; then - echo "\`enable-crash-reporting.sh\` must be run in repository root folder: \`./tools/crash-reporting-patch/enable-crash-reporting.sh\`"; exit 1 -fi - -echo "โš™๏ธ Enabling development setup for Crash Reporting feature..." - -# Install `DatadogCrashReporting.xcscheme` to `xcuserdata` folder -SCHEME_SOURCE="tools/crash-reporting-patch/DatadogCrashReporting.xcscheme" -SCHEME_TARGET="Datadog/Datadog.xcodeproj/xcuserdata/$(whoami).xcuserdatad/xcschemes" -mkdir -p "${SCHEME_TARGET}" -cp "${SCHEME_SOURCE}" "${SCHEME_TARGET}"