Skip to content

Commit d38165b

Browse files
authored
ref: SentrySDKPackage in Swift (#5478)
1 parent 35c962f commit d38165b

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
FA67DD162DDBD4EA00896B02 /* SentryViewPhotographer.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA67DCE42DDBD4EA00896B02 /* SentryViewPhotographer.swift */; };
10671065
FA67DD182DDBD4EA00896B02 /* UIImageHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA67DCED2DDBD4EA00896B02 /* UIImageHelper.swift */; };
10681066
FA67DD192DDBD4EA00896B02 /* SwizzleClassNameExclude.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA67DCD52DDBD4EA00896B02 /* SwizzleClassNameExclude.swift */; };
1067+
FA6FC0A32E0B5ACE00ED2669 /* SentrySdkPackage.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA6FC0A22E0B5AC800ED2669 /* SentrySdkPackage.swift */; };
10691068
FA7206DF2E0B37850072FDD4 /* SentryProfileCollector.h in Headers */ = {isa = PBXBuildFile; fileRef = FA7206DE2E0B37780072FDD4 /* SentryProfileCollector.h */; };
10701069
FA7206E12E0B37C80072FDD4 /* SentryProfileCollector.mm in Sources */ = {isa = PBXBuildFile; fileRef = FA7206E02E0B37C60072FDD4 /* SentryProfileCollector.mm */; };
10711070
FA8A36182DEAA1EB0058D883 /* SentryThread+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = FA8A36172DEAA1EB0058D883 /* SentryThread+Private.h */; };
@@ -1223,8 +1222,6 @@
12231222
33042A0B29DAF5F400C60085 /* SentryExtraContextProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SentryExtraContextProvider.h; sourceTree = "<group>"; };
12241223
33042A0C29DAF79A00C60085 /* SentryExtraContextProvider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryExtraContextProvider.m; sourceTree = "<group>"; };
12251224
33042A1629DC2C4300C60085 /* SentryExtraContextProviderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryExtraContextProviderTests.swift; sourceTree = "<group>"; };
1226-
33C374BC2D104A31004598F1 /* SentrySdkPackage.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentrySdkPackage.m; sourceTree = "<group>"; };
1227-
33C374BE2D104A41004598F1 /* SentrySdkPackage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentrySdkPackage.h; path = include/SentrySdkPackage.h; sourceTree = "<group>"; };
12281225
33EB2A8F2C3411AE004FED3D /* SentryWithoutUIKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryWithoutUIKit.h; path = Public/SentryWithoutUIKit.h; sourceTree = "<group>"; };
12291226
51B15F7F2BE88D510026A2F2 /* URLSessionTaskHelperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLSessionTaskHelperTests.swift; sourceTree = "<group>"; };
12301227
620078712D38F00D0022CB67 /* SentryGeoCodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryGeoCodable.swift; sourceTree = "<group>"; };
@@ -2319,6 +2316,7 @@
23192316
FA67DCEE2DDBD4EA00896B02 /* UrlSanitized.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UrlSanitized.swift; sourceTree = "<group>"; };
23202317
FA67DCEF2DDBD4EA00896B02 /* URLSessionTaskHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLSessionTaskHelper.swift; sourceTree = "<group>"; };
23212318
FA67DCF22DDBD4EA00896B02 /* SwiftDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftDescriptor.swift; sourceTree = "<group>"; };
2319+
FA6FC0A22E0B5AC800ED2669 /* SentrySdkPackage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentrySdkPackage.swift; sourceTree = "<group>"; };
23222320
FA7206DE2E0B37780072FDD4 /* SentryProfileCollector.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SentryProfileCollector.h; sourceTree = "<group>"; };
23232321
FA7206E02E0B37C60072FDD4 /* SentryProfileCollector.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SentryProfileCollector.mm; sourceTree = "<group>"; };
23242322
FA8A36172DEAA1EB0058D883 /* SentryThread+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentryThread+Private.h"; path = "include/SentryThread+Private.h"; sourceTree = "<group>"; };
@@ -2460,6 +2458,7 @@
24602458
621D9F2D2B9B030E003D94DE /* Helper */ = {
24612459
isa = PBXGroup;
24622460
children = (
2461+
FA6FC0A22E0B5AC800ED2669 /* SentrySdkPackage.swift */,
24632462
84B0E0062CD963F9007FB332 /* SentryIconography.swift */,
24642463
621F61F02BEA073A005E654F /* SentryEnabledFeaturesBuilder.swift */,
24652464
);
@@ -2748,8 +2747,6 @@
27482747
639889D51EDF10BE00EA7442 /* Helper */ = {
27492748
isa = PBXGroup;
27502749
children = (
2751-
33C374BE2D104A41004598F1 /* SentrySdkPackage.h */,
2752-
33C374BC2D104A31004598F1 /* SentrySdkPackage.m */,
27532750
63AA76951EB9C1C200D153DE /* SentryDefines.h */,
27542751
627E7588299F6FE40085504D /* SentryInternalDefines.h */,
27552752
0A9E917028DC7E7000FB4182 /* SentryInternalCDefines.h */,
@@ -4748,7 +4745,6 @@
47484745
844EDC6F294143B900C86F34 /* SentryNSProcessInfoWrapper.h in Headers */,
47494746
D8479328278873A100BE8E99 /* SentryByteCountFormatter.h in Headers */,
47504747
63AA76981EB9C1C200D153DE /* SentryClient.h in Headers */,
4751-
33C374C12D104D9C004598F1 /* SentrySdkPackage.h in Headers */,
47524748
0A9E917128DC7E7000FB4182 /* SentryInternalCDefines.h in Headers */,
47534749
63FE711F20DA4C1000CDBAE8 /* SentryCrashObjC.h in Headers */,
47544750
7BC3936825B1AB3E004F03D3 /* SentryLevelMapper.h in Headers */,
@@ -5278,6 +5274,7 @@
52785274
631E6D341EBC679C00712345 /* SentryQueueableRequestManager.m in Sources */,
52795275
7B8713B426415BAA006D6004 /* SentryAppStartTracker.m in Sources */,
52805276
7BDB03BB2513652900BAE198 /* SentryDispatchQueueWrapper.m in Sources */,
5277+
FA6FC0A32E0B5ACE00ED2669 /* SentrySdkPackage.swift in Sources */,
52815278
D8739D142BEE5049007D2F66 /* SentryRRWebSpanEvent.swift in Sources */,
52825279
7B6C5EDE264E8DF00010D138 /* SentryFramesTracker.m in Sources */,
52835280
D84F833E2A1CC401005828E0 /* SentrySwiftAsyncIntegration.m in Sources */,
@@ -5576,7 +5573,6 @@
55765573
8ECC674925C23A20000E2BF6 /* SentrySpanId.m in Sources */,
55775574
6344DDB51EC309E000D9160D /* SentryCrashReportSink.m in Sources */,
55785575
D43B26D62D70964C007747FD /* SentrySpanOperation.m in Sources */,
5579-
33C374C22D104F60004598F1 /* SentrySdkPackage.m in Sources */,
55805576
8EAE9806261E87120073B6B3 /* SentryUIViewControllerPerformanceTracker.m in Sources */,
55815577
D81988C72BEC18E20020E36C /* SentryRRWebVideoEvent.swift in Sources */,
55825578
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)