From 7512778844a25e6cd1f0430ce5557696c431e7af Mon Sep 17 00:00:00 2001 From: Dhiogo Brustolin Date: Mon, 4 Mar 2024 16:24:23 +0100 Subject: [PATCH] chore: Expose sentry private header to Swift (#3703) This change allows us to use Objc private classes in swift code --- Sentry.podspec | 5 ++-- Sentry.xcodeproj/project.pbxproj | 26 +++++++++++++++++-- .../Sentry/include/SentryBaseIntegration.h | 3 ++- Sources/Sentry/include/SentryInternal.h | 3 +++ Sources/Sentry/include/module.modulemap | 3 +++ Sources/Swift/Sentry.swift | 3 --- Sources/Swift/SwiftDescriptor.swift | 3 +-- 7 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 Sources/Sentry/include/SentryInternal.h create mode 100644 Sources/Sentry/include/module.modulemap delete mode 100644 Sources/Swift/Sentry.swift diff --git a/Sentry.podspec b/Sentry.podspec index 5552518372d..ab0d7a8b9f5 100644 --- a/Sentry.podspec +++ b/Sentry.podspec @@ -21,7 +21,8 @@ Pod::Spec.new do |s| 'GCC_ENABLE_CPP_EXCEPTIONS' => 'YES', 'CLANG_CXX_LANGUAGE_STANDARD' => 'c++14', 'CLANG_CXX_LIBRARY' => 'libc++', - 'APPLICATION_EXTENSION_API_ONLY' => 'YES' + 'APPLICATION_EXTENSION_API_ONLY' => 'YES', + 'SWIFT_INCLUDE_PATHS' => '${PODS_TARGET_SRCROOT}/Sources/Sentry/include' } s.watchos.pod_target_xcconfig = { 'OTHER_LDFLAGS' => '$(inherited) -framework WatchKit' @@ -31,7 +32,7 @@ Pod::Spec.new do |s| s.subspec 'Core' do |sp| sp.source_files = "Sources/Sentry/**/*.{h,hpp,m,mm,c,cpp}", - "Sources/SentryCrash/**/*.{h,hpp,m,mm,c,cpp}", "Sources/Swift/**/*.{swift,h,hpp,m,mm,c,cpp}" + "Sources/SentryCrash/**/*.{h,hpp,m,mm,c,cpp}", "Sources/Swift/**/*.{swift,h,hpp,m,mm,c,cpp}", "Sources/Sentry/include/module.modulemap" sp.public_header_files = "Sources/Sentry/Public/*.h" sp.resource_bundles = { "Sentry" => "Sources/Resources/PrivacyInfo.xcprivacy" } diff --git a/Sentry.xcodeproj/project.pbxproj b/Sentry.xcodeproj/project.pbxproj index e592ccc1cb0..dee71af03f4 100644 --- a/Sentry.xcodeproj/project.pbxproj +++ b/Sentry.xcodeproj/project.pbxproj @@ -814,6 +814,7 @@ D8B0542E2A7D2C720056BAF6 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = D8B0542D2A7D2C720056BAF6 /* PrivacyInfo.xcprivacy */; }; D8B088B629C9E3FF00213258 /* SentryTracerConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = D8B088B429C9E3FF00213258 /* SentryTracerConfiguration.h */; }; D8B088B729C9E3FF00213258 /* SentryTracerConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = D8B088B529C9E3FF00213258 /* SentryTracerConfiguration.m */; }; + D8B665BC2B95F73200BD0E7B /* SentryInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = D8B665BA2B95F54200BD0E7B /* SentryInternal.h */; }; D8B76B062808066D000A58C4 /* SentryScreenshotIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8B76B042808060E000A58C4 /* SentryScreenshotIntegrationTests.swift */; }; D8B76B0828081461000A58C4 /* TestSentryScreenShot.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8B76B0728081461000A58C4 /* TestSentryScreenShot.swift */; }; D8BBD32728FD9FC00011F850 /* SentrySwift.h in Headers */ = {isa = PBXBuildFile; fileRef = D8BBD32628FD9FBF0011F850 /* SentrySwift.h */; }; @@ -1719,7 +1720,6 @@ D8199DCF29376FF40074249E /* SentrySwiftUI.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = SentrySwiftUI.xcconfig; sourceTree = ""; }; D8199DD029377C130074249E /* SentrySwiftUI.podspec */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; path = SentrySwiftUI.podspec; sourceTree = ""; }; D81A346B291AECC7005A27A9 /* PrivateSentrySDKOnly.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PrivateSentrySDKOnly.h; path = include/HybridPublic/PrivateSentrySDKOnly.h; sourceTree = ""; }; - D81A349B291D0C0B005A27A9 /* Sentry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Sentry.swift; sourceTree = ""; }; D81A349F291D5568005A27A9 /* SentryPrivate.podspec */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; path = SentryPrivate.podspec; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; D81FDF10280EA0080045E0E4 /* SentryScreenShotTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryScreenShotTests.swift; sourceTree = ""; }; D8292D7A2A38AF04009872F7 /* HTTPHeaderSanitizer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPHeaderSanitizer.swift; sourceTree = ""; }; @@ -1780,6 +1780,8 @@ D8B0542D2A7D2C720056BAF6 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = ""; }; D8B088B429C9E3FF00213258 /* SentryTracerConfiguration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryTracerConfiguration.h; path = include/SentryTracerConfiguration.h; sourceTree = ""; }; D8B088B529C9E3FF00213258 /* SentryTracerConfiguration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryTracerConfiguration.m; sourceTree = ""; }; + D8B665BA2B95F54200BD0E7B /* SentryInternal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryInternal.h; path = include/SentryInternal.h; sourceTree = ""; }; + D8B665BB2B95F5A100BD0E7B /* module.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; name = module.modulemap; path = Sources/Sentry/include/module.modulemap; sourceTree = SOURCE_ROOT; }; D8B76B042808060E000A58C4 /* SentryScreenshotIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryScreenshotIntegrationTests.swift; sourceTree = ""; }; D8B76B0728081461000A58C4 /* TestSentryScreenShot.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestSentryScreenShot.swift; sourceTree = ""; }; D8BBD32628FD9FBF0011F850 /* SentrySwift.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentrySwift.h; path = include/SentrySwift.h; sourceTree = ""; }; @@ -2330,6 +2332,7 @@ 8ECC673625C23936000E2BF6 /* Transaction */, 8E25C94F25F836AB00DC215B /* Tools */, 63AA76931EB9C1C200D153DE /* Sentry.h */, + D8B665BA2B95F54200BD0E7B /* SentryInternal.h */, D8BBD32628FD9FBF0011F850 /* SentrySwift.h */, D81A346B291AECC7005A27A9 /* PrivateSentrySDKOnly.h */, 7B6D1260265F784000C9BE4B /* PrivateSentrySDKOnly.mm */, @@ -3326,8 +3329,8 @@ children = ( D856272A2A374A6800FB8062 /* Tools */, 7BF65060292B8EFE00BBA5A8 /* MetricKit */, - D81A349B291D0C0B005A27A9 /* Sentry.swift */, D800942628F82F3A005D3943 /* SwiftDescriptor.swift */, + D8B665BB2B95F5A100BD0E7B /* module.modulemap */, ); path = Swift; sourceTree = ""; @@ -3771,6 +3774,7 @@ 63FE715320DA4C1100CDBAE8 /* SentryCrashObjCApple.h in Headers */, 63FE710120DA4C1000CDBAE8 /* SentryCrashDate.h in Headers */, 7B4E24FC251C97B500060D68 /* SentrySession.h in Headers */, + D8B665BC2B95F73200BD0E7B /* SentryInternal.h in Headers */, 7B7D872C2486480B00D2ECFF /* SentryStacktraceBuilder.h in Headers */, 7B42C48027E08F33009B58C2 /* SentryDependencyContainer.h in Headers */, 6334314120AD9AE40077E581 /* SentryMechanism.h in Headers */, @@ -4773,6 +4777,7 @@ PRODUCT_BUNDLE_IDENTIFIER = io.sentry.Sentry; PRODUCT_NAME = Sentry; PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_INCLUDE_PATHS = "$(SRCROOT)/Sources/Sentry/include/"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; USE_HEADERMAP = YES; @@ -4813,6 +4818,7 @@ PRODUCT_BUNDLE_IDENTIFIER = io.sentry.Sentry; PRODUCT_NAME = Sentry; PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_INCLUDE_PATHS = "$(SRCROOT)/Sources/Sentry/include/"; SWIFT_VERSION = 5.0; USE_HEADERMAP = YES; }; @@ -4838,11 +4844,13 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); + MODULEMAP_PRIVATE_FILE = ""; OTHER_SWIFT_FLAGS = "-DSENTRY_USE_UIKIT"; PRODUCT_BUNDLE_IDENTIFIER = io.sentry.Sentry.tests; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; "PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = ""; + SWIFT_INCLUDE_PATHS = ""; SWIFT_OBJC_BRIDGING_HEADER = "Tests/SentryTests/SentryTests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_SWIFT3_OBJC_INFERENCE = Off; @@ -4871,11 +4879,13 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); + MODULEMAP_PRIVATE_FILE = ""; OTHER_SWIFT_FLAGS = "-DSENTRY_USE_UIKIT"; PRODUCT_BUNDLE_IDENTIFIER = io.sentry.Sentry.tests; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; "PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = ""; + SWIFT_INCLUDE_PATHS = ""; SWIFT_OBJC_BRIDGING_HEADER = "Tests/SentryTests/SentryTests-Bridging-Header.h"; SWIFT_SWIFT3_OBJC_INFERENCE = Off; SWIFT_VERSION = 5.0; @@ -4983,6 +4993,7 @@ PRODUCT_BUNDLE_IDENTIFIER = io.sentry.Sentry; PRODUCT_NAME = Sentry; PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_INCLUDE_PATHS = "$(SRCROOT)/Sources/Sentry/include/"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; USE_HEADERMAP = YES; @@ -5009,11 +5020,13 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); + MODULEMAP_PRIVATE_FILE = ""; OTHER_SWIFT_FLAGS = "-DSENTRY_USE_UIKIT"; PRODUCT_BUNDLE_IDENTIFIER = io.sentry.Sentry.tests; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; "PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = ""; + SWIFT_INCLUDE_PATHS = ""; SWIFT_OBJC_BRIDGING_HEADER = "Tests/SentryTests/SentryTests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_SWIFT3_OBJC_INFERENCE = Off; @@ -5119,6 +5132,7 @@ PRODUCT_BUNDLE_IDENTIFIER = io.sentry.Sentry; PRODUCT_NAME = Sentry; PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_INCLUDE_PATHS = "$(SRCROOT)/Sources/Sentry/include/"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; USE_HEADERMAP = YES; @@ -5145,10 +5159,12 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); + MODULEMAP_PRIVATE_FILE = ""; PRODUCT_BUNDLE_IDENTIFIER = io.sentry.Sentry.tests; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; "PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = ""; + SWIFT_INCLUDE_PATHS = ""; SWIFT_OBJC_BRIDGING_HEADER = "Tests/SentryTests/SentryTests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_SWIFT3_OBJC_INFERENCE = Off; @@ -5603,6 +5619,7 @@ PRODUCT_BUNDLE_IDENTIFIER = io.sentry.Sentry; PRODUCT_NAME = Sentry; PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_INCLUDE_PATHS = "$(SRCROOT)/Sources/Sentry/include/"; SWIFT_VERSION = 5.0; USE_HEADERMAP = YES; }; @@ -5628,11 +5645,13 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); + MODULEMAP_PRIVATE_FILE = ""; OTHER_SWIFT_FLAGS = "-DSENTRY_USE_UIKIT"; PRODUCT_BUNDLE_IDENTIFIER = io.sentry.Sentry.tests; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; "PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = ""; + SWIFT_INCLUDE_PATHS = ""; SWIFT_OBJC_BRIDGING_HEADER = "Tests/SentryTests/SentryTests-Bridging-Header.h"; SWIFT_SWIFT3_OBJC_INFERENCE = Off; SWIFT_VERSION = 5.0; @@ -5838,6 +5857,7 @@ PRODUCT_BUNDLE_IDENTIFIER = io.sentry.Sentry; PRODUCT_NAME = Sentry; PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_INCLUDE_PATHS = "$(SRCROOT)/Sources/Sentry/include/"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; USE_HEADERMAP = YES; @@ -5864,11 +5884,13 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); + MODULEMAP_PRIVATE_FILE = ""; OTHER_SWIFT_FLAGS = "-DSENTRY_USE_UIKIT"; PRODUCT_BUNDLE_IDENTIFIER = io.sentry.Sentry.tests; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; "PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = ""; + SWIFT_INCLUDE_PATHS = ""; SWIFT_OBJC_BRIDGING_HEADER = "Tests/SentryTests/SentryTests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_SWIFT3_OBJC_INFERENCE = Off; diff --git a/Sources/Sentry/include/SentryBaseIntegration.h b/Sources/Sentry/include/SentryBaseIntegration.h index c620ab20205..ff5267f2378 100644 --- a/Sources/Sentry/include/SentryBaseIntegration.h +++ b/Sources/Sentry/include/SentryBaseIntegration.h @@ -1,4 +1,3 @@ -#import "SentryOptions.h" #import NS_ASSUME_NONNULL_BEGIN @@ -25,6 +24,8 @@ typedef NS_OPTIONS(NSUInteger, SentryIntegrationOption) { kIntegrationOptionEnableMetricKit = 1 << 17, }; +@class SentryOptions; + @interface SentryBaseIntegration : NSObject - (NSString *)integrationName; diff --git a/Sources/Sentry/include/SentryInternal.h b/Sources/Sentry/include/SentryInternal.h new file mode 100644 index 00000000000..51e6f1713dc --- /dev/null +++ b/Sources/Sentry/include/SentryInternal.h @@ -0,0 +1,3 @@ +// Sentry internal headers that are needed for swift code + +#import "SentryBaseIntegration.h" diff --git a/Sources/Sentry/include/module.modulemap b/Sources/Sentry/include/module.modulemap new file mode 100644 index 00000000000..3328b59fece --- /dev/null +++ b/Sources/Sentry/include/module.modulemap @@ -0,0 +1,3 @@ +module _SentryPrivate { + header "SentryInternal.h" +} diff --git a/Sources/Swift/Sentry.swift b/Sources/Swift/Sentry.swift deleted file mode 100644 index 8196db2478a..00000000000 --- a/Sources/Swift/Sentry.swift +++ /dev/null @@ -1,3 +0,0 @@ -//For some reason Xcode needs a swift file in a objc only target to be able to use swift classes from another target. -//This file target membership must be 'Sentry'. -import Foundation diff --git a/Sources/Swift/SwiftDescriptor.swift b/Sources/Swift/SwiftDescriptor.swift index 9c292a2f111..0d345c9ced7 100644 --- a/Sources/Swift/SwiftDescriptor.swift +++ b/Sources/Swift/SwiftDescriptor.swift @@ -4,7 +4,7 @@ import Foundation class SwiftDescriptor: NSObject { @objc - static func getObjectClassName(_ object: AnyObject) -> String { + static func getObjectClassName(_ object: AnyObject) -> String { return String(describing: type(of: object)) } @@ -12,5 +12,4 @@ class SwiftDescriptor: NSObject { static func getSwiftErrorDescription(_ error: Error) -> String? { return String(describing: error) } - }