From d80d4105bd9c6a1d2271115383875a7c62c7aa33 Mon Sep 17 00:00:00 2001 From: Dhiogo Brustolin Date: Mon, 20 Mar 2023 13:24:22 +0100 Subject: [PATCH] chore: Remove private references from public headers (#2743) We made SentrySession private but we did not remove references from public headers. Also changing a few forward declarations to #import to help with .NET hybrid SDK. --- Sentry.xcodeproj/project.pbxproj | 2 +- Sources/Sentry/Public/SentryClient.h | 6 ++---- Sources/Sentry/Public/SentryHub.h | 9 ++------- Sources/Sentry/SentryHub.m | 1 + Sources/Sentry/SentryTraceContext.m | 1 + .../HybridPublic/PrivateSentrySDKOnly.h | 4 ++-- .../include/HybridPublic/SentryEnvelope.h | 20 +++++++++++++++---- Sources/Sentry/include/SentryClient+Private.h | 5 ++++- Sources/Sentry/include/SentrySdkInfo.h | 7 ++++++- Sources/Sentry/include/SentryTraceContext.h | 13 ++++++++++-- develop-docs/README.md | 4 ++++ 11 files changed, 50 insertions(+), 22 deletions(-) diff --git a/Sentry.xcodeproj/project.pbxproj b/Sentry.xcodeproj/project.pbxproj index d82952aa396..53fe837d691 100644 --- a/Sentry.xcodeproj/project.pbxproj +++ b/Sentry.xcodeproj/project.pbxproj @@ -748,7 +748,7 @@ D885266427739D01001269FC /* SentryFileIOTrackingIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D885266327739D01001269FC /* SentryFileIOTrackingIntegrationTests.swift */; }; D8853C842833EABC00700D64 /* SentryANRTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BCFA71427D0BAB7008C662C /* SentryANRTracker.h */; }; D88817D826D7149100BF2251 /* SentryTraceContext.m in Sources */ = {isa = PBXBuildFile; fileRef = D88817D626D7149100BF2251 /* SentryTraceContext.m */; }; - D88817DA26D72AB800BF2251 /* SentryTraceContext.h in Headers */ = {isa = PBXBuildFile; fileRef = D88817D926D72AB800BF2251 /* SentryTraceContext.h */; }; + D88817DA26D72AB800BF2251 /* SentryTraceContext.h in Headers */ = {isa = PBXBuildFile; fileRef = D88817D926D72AB800BF2251 /* SentryTraceContext.h */; settings = {ATTRIBUTES = (Private, ); }; }; D88817DD26D72BA500BF2251 /* SentryTraceStateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D88817DB26D72B7B00BF2251 /* SentryTraceStateTests.swift */; }; D8918B222849FA6D00701F9A /* SentrySDKIntegrationTestsBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8918B212849FA6D00701F9A /* SentrySDKIntegrationTestsBase.swift */; }; D8AB40DB2806EC1900E5E9F7 /* SentryScreenshotIntegration.h in Headers */ = {isa = PBXBuildFile; fileRef = D8AB40DA2806EC1900E5E9F7 /* SentryScreenshotIntegration.h */; }; diff --git a/Sources/Sentry/Public/SentryClient.h b/Sources/Sentry/Public/SentryClient.h index a7db0de3dbc..6584591a10c 100644 --- a/Sources/Sentry/Public/SentryClient.h +++ b/Sources/Sentry/Public/SentryClient.h @@ -1,7 +1,7 @@ #import "SentryDefines.h" -@class SentryOptions, SentrySession, SentryEvent, SentryScope, SentryFileManager, SentryId, - SentryUserFeedback, SentryTransaction; +@class SentryOptions, SentryEvent, SentryScope, SentryFileManager, SentryId, SentryUserFeedback, + SentryTransaction; NS_ASSUME_NONNULL_BEGIN @@ -108,8 +108,6 @@ SENTRY_NO_INIT - (void)captureUserFeedback:(SentryUserFeedback *)userFeedback NS_SWIFT_NAME(capture(userFeedback:)); -- (void)captureSession:(SentrySession *)session NS_SWIFT_NAME(capture(session:)); - /** * Waits synchronously for the SDK to flush out all queued and cached items for up to the specified * timeout in seconds. If there is no internet connection, the function returns immediately. The SDK diff --git a/Sources/Sentry/Public/SentryHub.h b/Sources/Sentry/Public/SentryHub.h index 9a94d6cb84e..02d4e2dd883 100644 --- a/Sources/Sentry/Public/SentryHub.h +++ b/Sources/Sentry/Public/SentryHub.h @@ -2,8 +2,8 @@ #import "SentryIntegrationProtocol.h" #import "SentrySpanProtocol.h" -@class SentryEvent, SentryClient, SentryScope, SentrySession, SentryUser, SentryBreadcrumb, - SentryId, SentryUserFeedback, SentryTransactionContext; +@class SentryEvent, SentryClient, SentryScope, SentryUser, SentryBreadcrumb, SentryId, + SentryUserFeedback, SentryTransactionContext; NS_ASSUME_NONNULL_BEGIN @interface SentryHub : NSObject @@ -12,11 +12,6 @@ SENTRY_NO_INIT - (instancetype)initWithClient:(SentryClient *_Nullable)client andScope:(SentryScope *_Nullable)scope; -/** - * Since there's no scope stack, single hub instance, we keep the session here. - */ -@property (nonatomic, readonly, strong) SentrySession *_Nullable session; - /** * Starts a new SentrySession. If there's a running SentrySession, it ends it before starting the * new one. You can use this method in combination with endSession to manually track SentrySessions. diff --git a/Sources/Sentry/SentryHub.m b/Sources/Sentry/SentryHub.m index 57383ba5895..0abe5bdefd3 100644 --- a/Sources/Sentry/SentryHub.m +++ b/Sources/Sentry/SentryHub.m @@ -28,6 +28,7 @@ SentryHub () @property (nullable, nonatomic, strong) SentryClient *client; +@property (nullable, nonatomic, strong) SentrySession *session; @property (nullable, nonatomic, strong) SentryScope *scope; @property (nonatomic, strong) SentryCrashWrapper *crashWrapper; @property (nonatomic, strong) SentryTracesSampler *tracesSampler; diff --git a/Sources/Sentry/SentryTraceContext.m b/Sources/Sentry/SentryTraceContext.m index c6a95b6eed6..c6bf9360858 100644 --- a/Sources/Sentry/SentryTraceContext.m +++ b/Sources/Sentry/SentryTraceContext.m @@ -1,6 +1,7 @@ #import "SentryTraceContext.h" #import "SentryBaggage.h" #import "SentryDsn.h" +#import "SentryId.h" #import "SentryLog.h" #import "SentryOptions+Private.h" #import "SentryScope+Private.h" diff --git a/Sources/Sentry/include/HybridPublic/PrivateSentrySDKOnly.h b/Sources/Sentry/include/HybridPublic/PrivateSentrySDKOnly.h index c09e5d000a9..f788ce59813 100644 --- a/Sources/Sentry/include/HybridPublic/PrivateSentrySDKOnly.h +++ b/Sources/Sentry/include/HybridPublic/PrivateSentrySDKOnly.h @@ -1,10 +1,10 @@ #import "PrivatesHeader.h" #import "SentryAppStartMeasurement.h" +#import "SentryEnvelope.h" #import "SentryEnvelopeItemType.h" #import "SentryScreenFrames.h" -@class SentryEnvelope, SentryDebugMeta, SentryAppStartMeasurement, SentryScreenFrames, - SentryOptions; +@class SentryDebugMeta, SentryAppStartMeasurement, SentryScreenFrames, SentryOptions; NS_ASSUME_NONNULL_BEGIN diff --git a/Sources/Sentry/include/HybridPublic/SentryEnvelope.h b/Sources/Sentry/include/HybridPublic/SentryEnvelope.h index c304cf0b69b..a7edf941dc2 100644 --- a/Sources/Sentry/include/HybridPublic/SentryEnvelope.h +++ b/Sources/Sentry/include/HybridPublic/SentryEnvelope.h @@ -1,8 +1,20 @@ #import "PrivatesHeader.h" -#import "SentryEnvelopeItemHeader.h" - -@class SentryEvent, SentrySession, SentrySdkInfo, SentryId, SentryUserFeedback, SentryAttachment, - SentryTransaction, SentryTraceContext, SentryClientReport, SentryEnvelopeItemHeader; +#if __has_include() +# import +#else +# import "SentryEnvelopeItemHeader.h" +#endif + +#if COCOAPODS +@class SentrySdkInfo, SentryTraceContext; +#else +# import "SentrySdkInfo.h" +# import "SentryTraceContext.h" + +#endif + +@class SentryEvent, SentrySession, SentryId, SentryUserFeedback, SentryAttachment, + SentryTransaction, SentryClientReport, SentryEnvelopeItemHeader; NS_ASSUME_NONNULL_BEGIN diff --git a/Sources/Sentry/include/SentryClient+Private.h b/Sources/Sentry/include/SentryClient+Private.h index 30a891a0f35..a9bcd469818 100644 --- a/Sources/Sentry/include/SentryClient+Private.h +++ b/Sources/Sentry/include/SentryClient+Private.h @@ -2,7 +2,8 @@ #import "SentryDataCategory.h" #import "SentryDiscardReason.h" -@class SentryEnvelopeItem, SentryId, SentryAttachment, SentryThreadInspector, SentryEnvelope; +@class SentrySession, SentryEnvelopeItem, SentryId, SentryAttachment, SentryThreadInspector, + SentryEnvelope; NS_ASSUME_NONNULL_BEGIN @@ -41,6 +42,8 @@ SentryClient () additionalEnvelopeItems:(NSArray *)additionalEnvelopeItems NS_SWIFT_NAME(capture(event:scope:additionalEnvelopeItems:)); +- (void)captureSession:(SentrySession *)session NS_SWIFT_NAME(capture(session:)); + /** * Needed by hybrid SDKs as react-native to synchronously store an envelope to disk. */ diff --git a/Sources/Sentry/include/SentrySdkInfo.h b/Sources/Sentry/include/SentrySdkInfo.h index ef80f2cabc1..d3799c13266 100644 --- a/Sources/Sentry/include/SentrySdkInfo.h +++ b/Sources/Sentry/include/SentrySdkInfo.h @@ -1,6 +1,11 @@ -#import "SentrySerializable.h" #import +#if __has_include() +# import +#else +# import "SentrySerializable.h" +#endif + NS_ASSUME_NONNULL_BEGIN /** diff --git a/Sources/Sentry/include/SentryTraceContext.h b/Sources/Sentry/include/SentryTraceContext.h index 0958e406ac6..3fd1b491928 100644 --- a/Sources/Sentry/include/SentryTraceContext.h +++ b/Sources/Sentry/include/SentryTraceContext.h @@ -1,5 +1,14 @@ -#import "SentryId.h" -#import "SentrySerializable.h" +#if __has_include() +# import +#else +# import "SentrySerializable.h" +#endif + +#if __has_include() +# import +#else +# import "SentryId.h" +#endif NS_ASSUME_NONNULL_BEGIN diff --git a/develop-docs/README.md b/develop-docs/README.md index ad817bf73a1..651278ff8c2 100644 --- a/develop-docs/README.md +++ b/develop-docs/README.md @@ -196,3 +196,7 @@ Date: January 18th, 2023 Contributors: @brustolin and @philipphofmann We release experimental SentrySwiftUI cocoa package with the version 8.0.0 because all podspecs file in a repo need to have the same version. + +## Usage of `__has_include` + +Some private headers add a dependency of a public header, when those private headers are used in a sample project, or referenced from a hybrid SDK, it is treated as part of the project using it, therefore, if it points to a header that is not part of said project, a compilation error will occur. To solve this we make use of `__has_include` to try to point to the SDK version of the header, or to fallback to the direct reference when compiling the SDK.