Skip to content

Commit d0f9518

Browse files
committed
SentrySDKPackage in Swift
1 parent d3d54f4 commit d0f9518

File tree

6 files changed

+72
-110
lines changed

6 files changed

+72
-110
lines changed

Sentry.xcodeproj/project.pbxproj

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@
6969
15E0A8F22411A45A00F044E3 /* SentrySession.m in Sources */ = {isa = PBXBuildFile; fileRef = 15E0A8F12411A45A00F044E3 /* SentrySession.m */; };
7070
33042A0D29DAF79A00C60085 /* SentryExtraContextProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 33042A0C29DAF79A00C60085 /* SentryExtraContextProvider.m */; };
7171
33042A1729DC2C4300C60085 /* SentryExtraContextProviderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33042A1629DC2C4300C60085 /* SentryExtraContextProviderTests.swift */; };
72-
33C374C12D104D9C004598F1 /* SentrySdkPackage.h in Headers */ = {isa = PBXBuildFile; fileRef = 33C374BE2D104A41004598F1 /* SentrySdkPackage.h */; settings = {ATTRIBUTES = (Private, ); }; };
73-
33C374C22D104F60004598F1 /* SentrySdkPackage.m in Sources */ = {isa = PBXBuildFile; fileRef = 33C374BC2D104A31004598F1 /* SentrySdkPackage.m */; };
7472
33EB2A912C3412E4004FED3D /* SentryWithoutUIKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 33EB2A8F2C3411AE004FED3D /* SentryWithoutUIKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
7573
33EB2A922C341300004FED3D /* Sentry.h in Headers */ = {isa = PBXBuildFile; fileRef = 63AA76931EB9C1C200D153DE /* Sentry.h */; settings = {ATTRIBUTES = (Public, ); }; };
7674
51B15F802BE88D510026A2F2 /* URLSessionTaskHelperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51B15F7F2BE88D510026A2F2 /* URLSessionTaskHelperTests.swift */; };
@@ -1066,6 +1064,7 @@
10661064
FA67DD192DDBD4EA00896B02 /* SwizzleClassNameExclude.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA67DCD52DDBD4EA00896B02 /* SwizzleClassNameExclude.swift */; };
10671065
FA8A36182DEAA1EB0058D883 /* SentryThread+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = FA8A36172DEAA1EB0058D883 /* SentryThread+Private.h */; };
10681066
FA90FAA82E06614E008CAAE8 /* SentryExtraPackages.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA90FAA72E06614B008CAAE8 /* SentryExtraPackages.swift */; };
1067+
FA90FAF72E06E427008CAAE8 /* SentrySdkPackage.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA90FAF62E06E427008CAAE8 /* SentrySdkPackage.swift */; };
10691068
FAEC270E2DF3526000878871 /* SentryUserFeedback.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAEC270D2DF3526000878871 /* SentryUserFeedback.swift */; };
10701069
FAEC273D2DF3933A00878871 /* NSData+Unzip.m in Sources */ = {isa = PBXBuildFile; fileRef = FAEC273C2DF3933200878871 /* NSData+Unzip.m */; };
10711070
/* End PBXBuildFile section */
@@ -1216,8 +1215,6 @@
12161215
33042A0B29DAF5F400C60085 /* SentryExtraContextProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SentryExtraContextProvider.h; sourceTree = "<group>"; };
12171216
33042A0C29DAF79A00C60085 /* SentryExtraContextProvider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryExtraContextProvider.m; sourceTree = "<group>"; };
12181217
33042A1629DC2C4300C60085 /* SentryExtraContextProviderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryExtraContextProviderTests.swift; sourceTree = "<group>"; };
1219-
33C374BC2D104A31004598F1 /* SentrySdkPackage.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentrySdkPackage.m; sourceTree = "<group>"; };
1220-
33C374BE2D104A41004598F1 /* SentrySdkPackage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentrySdkPackage.h; path = include/SentrySdkPackage.h; sourceTree = "<group>"; };
12211218
33EB2A8F2C3411AE004FED3D /* SentryWithoutUIKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryWithoutUIKit.h; path = Public/SentryWithoutUIKit.h; sourceTree = "<group>"; };
12221219
51B15F7F2BE88D510026A2F2 /* URLSessionTaskHelperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLSessionTaskHelperTests.swift; sourceTree = "<group>"; };
12231220
620078712D38F00D0022CB67 /* SentryGeoCodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryGeoCodable.swift; sourceTree = "<group>"; };
@@ -2312,6 +2309,7 @@
23122309
FA67DCF22DDBD4EA00896B02 /* SwiftDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftDescriptor.swift; sourceTree = "<group>"; };
23132310
FA8A36172DEAA1EB0058D883 /* SentryThread+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentryThread+Private.h"; path = "include/SentryThread+Private.h"; sourceTree = "<group>"; };
23142311
FA90FAA72E06614B008CAAE8 /* SentryExtraPackages.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryExtraPackages.swift; sourceTree = "<group>"; };
2312+
FA90FAF62E06E427008CAAE8 /* SentrySdkPackage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentrySdkPackage.swift; sourceTree = "<group>"; };
23152313
FAEC270D2DF3526000878871 /* SentryUserFeedback.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryUserFeedback.swift; sourceTree = "<group>"; };
23162314
FAEC273C2DF3933200878871 /* NSData+Unzip.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSData+Unzip.m"; sourceTree = "<group>"; };
23172315
FAEC273E2DF393E000878871 /* NSData+Unzip.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSData+Unzip.h"; sourceTree = "<group>"; };
@@ -2446,6 +2444,7 @@
24462444
621D9F2D2B9B030E003D94DE /* Helper */ = {
24472445
isa = PBXGroup;
24482446
children = (
2447+
FA90FAF62E06E427008CAAE8 /* SentrySdkPackage.swift */,
24492448
84B0E0062CD963F9007FB332 /* SentryIconography.swift */,
24502449
621F61F02BEA073A005E654F /* SentryEnabledFeaturesBuilder.swift */,
24512450
);
@@ -2736,8 +2735,6 @@
27362735
639889D51EDF10BE00EA7442 /* Helper */ = {
27372736
isa = PBXGroup;
27382737
children = (
2739-
33C374BE2D104A41004598F1 /* SentrySdkPackage.h */,
2740-
33C374BC2D104A31004598F1 /* SentrySdkPackage.m */,
27412738
63AA76951EB9C1C200D153DE /* SentryDefines.h */,
27422739
627E7588299F6FE40085504D /* SentryInternalDefines.h */,
27432740
0A9E917028DC7E7000FB4182 /* SentryInternalCDefines.h */,
@@ -4726,7 +4723,6 @@
47264723
844EDC6F294143B900C86F34 /* SentryNSProcessInfoWrapper.h in Headers */,
47274724
D8479328278873A100BE8E99 /* SentryByteCountFormatter.h in Headers */,
47284725
63AA76981EB9C1C200D153DE /* SentryClient.h in Headers */,
4729-
33C374C12D104D9C004598F1 /* SentrySdkPackage.h in Headers */,
47304726
0A9E917128DC7E7000FB4182 /* SentryInternalCDefines.h in Headers */,
47314727
63FE711F20DA4C1000CDBAE8 /* SentryCrashObjC.h in Headers */,
47324728
7BC3936825B1AB3E004F03D3 /* SentryLevelMapper.h in Headers */,
@@ -5246,6 +5242,7 @@
52465242
84A903712D39F66F00690CE4 /* SentryUserFeedbackFormViewModel.swift in Sources */,
52475243
7B3398652459C15200BD9C96 /* SentryEnvelopeRateLimit.m in Sources */,
52485244
D81988C92BEC19200020E36C /* SentryRRWebBreadcrumbEvent.swift in Sources */,
5245+
FA90FAF72E06E427008CAAE8 /* SentrySdkPackage.swift in Sources */,
52495246
0A2D8D9628997845008720F6 /* NSLocale+Sentry.m in Sources */,
52505247
7B0DC730288698F70039995F /* NSMutableDictionary+Sentry.m in Sources */,
52515248
628094742D39584C00B3F18B /* SentryUserCodable.swift in Sources */,
@@ -5550,7 +5547,6 @@
55505547
8ECC674925C23A20000E2BF6 /* SentrySpanId.m in Sources */,
55515548
6344DDB51EC309E000D9160D /* SentryCrashReportSink.m in Sources */,
55525549
D43B26D62D70964C007747FD /* SentrySpanOperation.m in Sources */,
5553-
33C374C22D104F60004598F1 /* SentrySdkPackage.m in Sources */,
55545550
8EAE9806261E87120073B6B3 /* SentryUIViewControllerPerformanceTracker.m in Sources */,
55555551
D81988C72BEC18E20020E36C /* SentryRRWebVideoEvent.swift in Sources */,
55565552
621F61F12BEA073A005E654F /* SentryEnabledFeaturesBuilder.swift in Sources */,

Sources/Resources/Sentry.modulemap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ framework module Sentry {
2727
header "SentrySessionReplayIntegration-Hybrid.h"
2828

2929
header "SentrySdkInfo.h"
30-
header "SentrySdkPackage.h"
3130
header "SentryInternalSerializable.h"
3231

3332
export *

Sources/Sentry/SentrySdkInfo.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#import "SentryMeta.h"
55
#import "SentryOptions.h"
66
#import "SentrySDK+Private.h"
7-
#import "SentrySdkPackage.h"
87
#import "SentrySwift.h"
98

109
NS_ASSUME_NONNULL_BEGIN

Sources/Sentry/SentrySdkPackage.m

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

Sources/Sentry/include/SentrySdkPackage.h

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
@_implementationOnly import _SentryPrivate
2+
import Foundation
3+
4+
/// This is required to identify the package manager used when installing sentry.
5+
private enum SentryPackageManagerOption: UInt {
6+
case swiftPackageManager = 0
7+
case cocoaPods = 1
8+
case carthage = 2
9+
case unknown = 3
10+
}
11+
12+
#if SWIFT_PACKAGE
13+
private var SENTRY_PACKAGE_INFO: SentryPackageManagerOption = .swiftPackageManager
14+
#elseif COCOAPODS
15+
private var SENTRY_PACKAGE_INFO: SentryPackageManagerOption = .cocoaPods
16+
#elseif CARTHAGE_YES
17+
// CARTHAGE is a xcodebuild build setting with value `YES`, we need to convert it into a compiler
18+
// definition to be able to use it.
19+
private var SENTRY_PACKAGE_INFO: SentryPackageManagerOption = .carthage
20+
#else
21+
private var SENTRY_PACKAGE_INFO: SentryPackageManagerOption = .unknown
22+
#endif
23+
24+
@objc
25+
@_spi(Private) public final class SentrySdkPackage: NSObject {
26+
27+
private static func getSentrySDKPackageName(_ packageManager: SentryPackageManagerOption) -> String? {
28+
switch packageManager {
29+
case .swiftPackageManager:
30+
return "spm:getsentry/\(SentryMeta.sdkName)"
31+
case .cocoaPods:
32+
return "cocoapods:getsentry/\(SentryMeta.sdkName)"
33+
case .carthage:
34+
return "carthage:getsentry/\(SentryMeta.sdkName)"
35+
case .unknown:
36+
return nil
37+
}
38+
}
39+
40+
private static func getSentrySDKPackage(_ packageManager: SentryPackageManagerOption) -> [String: String]? {
41+
if packageManager == .unknown {
42+
return nil
43+
}
44+
45+
guard let name = getSentrySDKPackageName(packageManager) else {
46+
return nil
47+
}
48+
49+
return ["name": name, "version": SentryMeta.versionString]
50+
}
51+
52+
@objc
53+
public static func global() -> [String: String]? {
54+
return getSentrySDKPackage(SENTRY_PACKAGE_INFO)
55+
}
56+
57+
#if SENTRY_TEST || SENTRY_TEST_CI
58+
@objc
59+
public static func setPackageManager(_ manager: UInt) {
60+
SENTRY_PACKAGE_INFO = SentryPackageManagerOption(rawValue: manager) ?? .unknown
61+
}
62+
63+
@objc
64+
public static func resetPackageManager() {
65+
SENTRY_PACKAGE_INFO = .unknown
66+
}
67+
#endif
68+
}

0 commit comments

Comments
 (0)