Skip to content

Commit 134fbdf

Browse files
authored
feat(spm): Remove swift imports from objc++ (#5522)
1 parent 63a3afd commit 134fbdf

File tree

9 files changed

+120
-106
lines changed

9 files changed

+120
-106
lines changed

Sentry.xcodeproj/project.pbxproj

Lines changed: 20 additions & 20 deletions
Large diffs are not rendered by default.

Sources/Sentry/Profiling/SentryProfiledTracerConcurrency.mm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
# import "SentryLogC.h"
88
# import "SentryOptions+Private.h"
99
# import "SentryProfiler+Private.h"
10-
# import "SentrySwift.h"
1110
# include <mutex>
1211

1312
# import "SentryDependencyContainer.h"

Sources/Sentry/Profiling/SentryProfilerSerialization.mm renamed to Sources/Sentry/Profiling/SentryProfilerSerialization.m

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939

4040
# pragma mark - Private
4141

42-
namespace {
43-
4442
/**
4543
* Given an array of samples with absolute timestamps, return the serialized JSON mapping with
4644
* their data, with timestamps normalized relative to the provided transaction's start time.
@@ -49,7 +47,7 @@
4947
_sentry_serializedTraceProfileSamplesWithRelativeTimestamps(
5048
NSArray<SentrySample *> *samples, uint64_t startSystemTime)
5149
{
52-
const auto result = [NSMutableArray<NSDictionary *> array];
50+
NSMutableArray<NSDictionary *> *result = [NSMutableArray<NSDictionary *> array];
5351
[samples enumerateObjectsUsingBlock:^(
5452
SentrySample *_Nonnull sample, NSUInteger idx, BOOL *_Nonnull stop) {
5553
// This shouldn't happen as we would've filtered out any such samples, but we should still
@@ -58,8 +56,8 @@
5856
SENTRY_LOG_WARN(@"Filtering sample as it came before start time to begin slicing.");
5957
return;
6058
}
61-
const auto dict = [NSMutableDictionary dictionary];
62-
const auto durationNs = getDurationNs(startSystemTime, sample.absoluteTimestamp);
59+
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
60+
uint64_t durationNs = getDurationNs(startSystemTime, sample.absoluteTimestamp);
6361
dict[@"elapsed_since_start_ns"] = sentry_stringForUInt64(durationNs);
6462

6563
dict[@"thread_id"] = sentry_stringForUInt64(sample.threadID);
@@ -81,10 +79,10 @@
8179
NSArray<NSDictionary *> *
8280
_sentry_serializedContinuousProfileSamples(NSArray<SentrySample *> *samples)
8381
{
84-
const auto result = [NSMutableArray<NSDictionary *> array];
82+
NSMutableArray<NSDictionary *> *result = [NSMutableArray<NSDictionary *> array];
8583
[samples enumerateObjectsUsingBlock:^(
8684
SentrySample *_Nonnull sample, NSUInteger idx, BOOL *_Nonnull stop) {
87-
const auto dict = [NSMutableDictionary dictionary];
85+
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
8886
dict[@"timestamp"] = @(sample.absoluteNSDateInterval);
8987
dict[@"thread_id"] = sentry_stringForUInt64(sample.threadID);
9088
dict[@"stack_id"] = sample.stackIndex;
@@ -96,8 +94,6 @@
9694
return result;
9795
}
9896

99-
} // namespace
100-
10197
# pragma mark - Exported for tests
10298

10399
NSString *
@@ -136,21 +132,23 @@
136132
}
137133

138134
// slice the profile data to only include the samples/metrics within the transaction
139-
const auto slicedSamples = sentry_slicedProfileSamples(samples, startSystemTime, endSystemTime);
135+
NSArray<SentrySample *> *slicedSamples
136+
= sentry_slicedProfileSamples(samples, startSystemTime, endSystemTime);
140137
if (slicedSamples.count < 2) {
141138
SENTRY_LOG_DEBUG(@"Not enough samples in profile during the transaction");
142139
[hub.getClient recordLostEvent:kSentryDataCategoryProfile
143140
reason:kSentryDiscardReasonEventProcessor];
144141
return nil;
145142
}
146-
const auto payload = [NSMutableDictionary<NSString *, id> dictionary];
143+
NSMutableDictionary<NSString *, id> *payload = [NSMutableDictionary<NSString *, id> dictionary];
147144
NSMutableDictionary<NSString *, id> *const profile = [profileData[@"profile"] mutableCopy];
148145
profile[@"samples"] = _sentry_serializedTraceProfileSamplesWithRelativeTimestamps(
149146
slicedSamples, startSystemTime);
150147
payload[@"profile"] = profile;
151148

152149
payload[@"version"] = @"1";
153-
const auto debugImages = [NSMutableArray<NSDictionary<NSString *, id> *> new];
150+
NSMutableArray<NSDictionary<NSString *, id> *> *debugImages =
151+
[NSMutableArray<NSDictionary<NSString *, id> *> new];
154152
for (SentryDebugMeta *debugImage in debugMeta) {
155153
[debugImages addObject:[debugImage serialize]];
156154
}
@@ -164,7 +162,7 @@
164162
@"build_number" : sentry_getOSBuildNumber()
165163
};
166164

167-
const auto isEmulated = sentry_isSimulatorBuild();
165+
bool isEmulated = sentry_isSimulatorBuild();
168166
payload[@"device"] = @{
169167
@"architecture" : sentry_getCPUArchitecture(),
170168
@"is_emulator" : @(isEmulated),
@@ -179,29 +177,30 @@
179177
payload[@"release"] = hub.getClient.options.releaseName;
180178

181179
// add the gathered metrics
182-
auto metrics = serializedMetrics;
180+
NSDictionary<NSString *, id> *metrics = serializedMetrics;
183181

184182
# if SENTRY_HAS_UIKIT
185-
const auto mutableMetrics =
183+
NSMutableDictionary<NSString *, id> *mutableMetrics =
186184
[NSMutableDictionary<NSString *, id> dictionaryWithDictionary:metrics];
187-
const auto slowFrames = sentry_sliceTraceProfileGPUData(gpuData.slowFrameTimestamps,
188-
startSystemTime, endSystemTime, /*useMostRecentFrameRate */ NO);
185+
NSArray<SentrySerializedMetricEntry *> *slowFrames
186+
= sentry_sliceTraceProfileGPUData(gpuData.slowFrameTimestamps, startSystemTime,
187+
endSystemTime, /*useMostRecentFrameRate */ NO);
189188
if (slowFrames.count > 0) {
190189
mutableMetrics[kSentryProfilerSerializationKeySlowFrameRenders] =
191190
@ { @"unit" : @"nanosecond", @"values" : slowFrames };
192191
}
193192

194-
const auto frozenFrames = sentry_sliceTraceProfileGPUData(gpuData.frozenFrameTimestamps,
195-
startSystemTime, endSystemTime,
193+
NSArray<SentrySerializedMetricEntry *> *frozenFrames = sentry_sliceTraceProfileGPUData(
194+
gpuData.frozenFrameTimestamps, startSystemTime, endSystemTime,
196195
/*useMostRecentFrameRate */ NO);
197196
if (frozenFrames.count > 0) {
198197
mutableMetrics[kSentryProfilerSerializationKeyFrozenFrameRenders] =
199198
@ { @"unit" : @"nanosecond", @"values" : frozenFrames };
200199
}
201200

202201
if (slowFrames.count > 0 || frozenFrames.count > 0) {
203-
const auto frameRates = sentry_sliceTraceProfileGPUData(gpuData.frameRateTimestamps,
204-
startSystemTime, endSystemTime,
202+
NSArray<SentrySerializedMetricEntry *> *frameRates = sentry_sliceTraceProfileGPUData(
203+
gpuData.frameRateTimestamps, startSystemTime, endSystemTime,
205204
/*useMostRecentFrameRate */ YES);
206205
if (frameRates.count > 0) {
207206
mutableMetrics[kSentryProfilerSerializationKeyFrameRates] =
@@ -236,14 +235,15 @@
236235
// profiling session, to count the number of total samples sent so far, to decide whether or not
237236
// a 1-sample chunk is acceptable.
238237

239-
const auto payload = [NSMutableDictionary<NSString *, id> dictionary];
238+
NSMutableDictionary<NSString *, id> *payload = [NSMutableDictionary<NSString *, id> dictionary];
240239
NSMutableDictionary<NSString *, id> *const profile = [profileData[@"profile"] mutableCopy];
241240
profile[@"samples"] = _sentry_serializedContinuousProfileSamples(samples);
242241

243242
payload[@"profile"] = profile;
244243

245244
payload[@"version"] = @"2";
246-
const auto debugImages = [NSMutableArray<NSDictionary<NSString *, id> *> new];
245+
NSMutableArray<NSDictionary<NSString *, id> *> *debugImages =
246+
[NSMutableArray<NSDictionary<NSString *, id> *> new];
247247
for (SentryDebugMeta *debugImage in debugMeta) {
248248
[debugImages addObject:[debugImage serialize]];
249249
}
@@ -257,34 +257,34 @@
257257
payload[@"release"] = hub.getClient.options.releaseName;
258258
payload[@"platform"] = SentryPlatformName;
259259

260-
const auto clientInfo = [NSMutableDictionary dictionary];
260+
NSMutableDictionary *clientInfo = [NSMutableDictionary dictionary];
261261
clientInfo[@"name"] = SentryMeta.sdkName;
262262
clientInfo[@"version"] = SentryMeta.versionString;
263263
payload[@"client_sdk"] = clientInfo;
264264

265265
// add the gathered metrics
266-
auto metrics = serializedMetrics;
266+
NSDictionary<NSString *, id> *metrics = serializedMetrics;
267267

268268
# if SENTRY_HAS_UIKIT
269-
const auto mutableMetrics =
269+
NSMutableDictionary<NSString *, id> *mutableMetrics =
270270
[NSMutableDictionary<NSString *, id> dictionaryWithDictionary:metrics];
271271
if (gpuData.slowFrameTimestamps.count > 0) {
272-
const auto values = [NSMutableDictionary dictionary];
272+
NSMutableDictionary *values = [NSMutableDictionary dictionary];
273273
values[@"unit"] = @"nanosecond";
274274
values[@"values"] = gpuData.slowFrameTimestamps;
275275
mutableMetrics[kSentryProfilerSerializationKeySlowFrameRenders] = values;
276276
}
277277

278278
if (gpuData.frozenFrameTimestamps.count > 0) {
279-
const auto values = [NSMutableDictionary dictionary];
279+
NSMutableDictionary *values = [NSMutableDictionary dictionary];
280280
values[@"unit"] = @"nanosecond";
281281
values[@"values"] = gpuData.frozenFrameTimestamps;
282282
mutableMetrics[kSentryProfilerSerializationKeyFrozenFrameRenders] = values;
283283
}
284284

285285
if (gpuData.slowFrameTimestamps.count > 0 || gpuData.frozenFrameTimestamps.count > 0) {
286286
if (gpuData.frameRateTimestamps.count > 0) {
287-
const auto values = [NSMutableDictionary dictionary];
287+
NSMutableDictionary *values = [NSMutableDictionary dictionary];
288288
values[@"unit"] = @"hz";
289289
values[@"values"] = gpuData.frameRateTimestamps;
290290
mutableMetrics[kSentryProfilerSerializationKeyFrameRates] = values;
@@ -310,8 +310,8 @@
310310
# endif // SENTRY_HAS_UIKIT
311311
)
312312
{
313-
const auto chunkID = [[SentryId alloc] init];
314-
const auto payload = sentry_serializedContinuousProfileChunk(
313+
SentryId *chunkID = [[SentryId alloc] init];
314+
NSMutableDictionary<NSString *, id> *payload = sentry_serializedContinuousProfileChunk(
315315
profileID, chunkID, profileState, metricProfilerState,
316316
[SentryDependencyContainer.sharedInstance.debugImageProvider getDebugImagesFromCache],
317317
SentrySDK.currentHub
@@ -326,7 +326,7 @@
326326
return nil;
327327
}
328328

329-
const auto JSONData = [SentrySerialization dataWithJSONObject:payload];
329+
NSData *JSONData = [SentrySerialization dataWithJSONObject:payload];
330330
if (JSONData == nil) {
331331
SENTRY_LOG_DEBUG(@"Failed to encode profile to JSON.");
332332
return nil;
@@ -343,11 +343,12 @@
343343
}
344344
# endif // defined(SENTRY_TEST) || defined(SENTRY_TEST_CI)
345345

346-
const auto header =
346+
SentryEnvelopeItemHeader *header =
347347
[[SentryEnvelopeItemHeader alloc] initWithType:SentryEnvelopeItemTypeProfileChunk
348348
length:JSONData.length];
349349
header.platform = @"cocoa";
350-
const auto envelopeItem = [[SentryEnvelopeItem alloc] initWithHeader:header data:JSONData];
350+
SentryEnvelopeItem *envelopeItem = [[SentryEnvelopeItem alloc] initWithHeader:header
351+
data:JSONData];
351352

352353
return [[SentryEnvelope alloc] initWithId:chunkID singleItem:envelopeItem];
353354
}
@@ -356,9 +357,9 @@
356357
SentryProfiler *profiler, NSDictionary<NSString *, id> *profilingData,
357358
SentryTransaction *transaction, NSDate *startTimestamp)
358359
{
359-
const auto images =
360+
NSArray<SentryDebugMeta *> *images =
360361
[SentryDependencyContainer.sharedInstance.debugImageProvider getDebugImagesFromCache];
361-
const auto payload = sentry_serializedTraceProfileData(
362+
NSMutableDictionary<NSString *, id> *payload = sentry_serializedTraceProfileData(
362363
profilingData, transaction.startSystemTime, transaction.endSystemTime,
363364
sentry_profilerTruncationReasonName(profiler.truncationReason),
364365
[profiler.metricProfiler serializeTraceProfileMetricsBetween:transaction.startSystemTime
@@ -384,7 +385,7 @@
384385
};
385386
payload[@"timestamp"] = sentry_toIso8601String(startTimestamp);
386387

387-
const auto JSONData = [SentrySerialization dataWithJSONObject:payload];
388+
NSData *JSONData = [SentrySerialization dataWithJSONObject:payload];
388389
if (JSONData == nil) {
389390
SENTRY_LOG_DEBUG(@"Failed to encode profile to JSON.");
390391
return nil;
@@ -394,15 +395,16 @@
394395
sentry_writeProfileFile(JSONData, false /*continuous*/);
395396
# endif // defined(SENTRY_TEST) || defined(SENTRY_TEST_CI)
396397

397-
const auto header = [[SentryEnvelopeItemHeader alloc] initWithType:SentryEnvelopeItemTypeProfile
398-
length:JSONData.length];
398+
SentryEnvelopeItemHeader *header =
399+
[[SentryEnvelopeItemHeader alloc] initWithType:SentryEnvelopeItemTypeProfile
400+
length:JSONData.length];
399401
return [[SentryEnvelopeItem alloc] initWithHeader:header data:JSONData];
400402
}
401403

402404
NSMutableDictionary<NSString *, id> *_Nullable sentry_collectProfileDataHybridSDK(
403405
uint64_t startSystemTime, uint64_t endSystemTime, SentryId *traceId, SentryHub *hub)
404406
{
405-
const auto profiler = sentry_profilerForFinishedTracer(traceId);
407+
SentryProfiler *profiler = sentry_profilerForFinishedTracer(traceId);
406408
if (!profiler) {
407409
return nil;
408410
}

Sources/Sentry/SentryDevice.mm renamed to Sources/Sentry/SentryDevice.m

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
# import <UIKit/UIKit.h>
2525
#endif // SENTRY_HAS_UIKIT
2626

27-
namespace {
2827
/**
2928
* @brief Get an iOS hardware model name, or for mac devices, either the hardware model name or CPU
3029
* architecture of the device, depending on the option provided.
@@ -64,7 +63,7 @@
6463
return @"";
6564
}
6665

67-
const auto nameNSString = [NSString stringWithUTF8String:name];
66+
NSString *nameNSString = [NSString stringWithUTF8String:name];
6867

6968
NSString *argName;
7069
switch (type) {
@@ -132,7 +131,6 @@
132131
return @"arm64_32";
133132
}
134133
}
135-
} // namespace
136134

137135
NSString *
138136
sentry_getCPUArchitecture(void)
@@ -187,7 +185,7 @@
187185
#elif SENTRY_HAS_UIKIT
188186
return [UIDevice currentDevice].systemVersion;
189187
#else
190-
const auto version = [[NSProcessInfo processInfo] operatingSystemVersion];
188+
NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion];
191189
return [NSString stringWithFormat:@"%ld.%ld.%ld", (long)version.majorVersion,
192190
(long)version.minorVersion, (long)version.patchVersion];
193191
#endif // SENTRY_HAS_UIKIT
@@ -198,14 +196,14 @@
198196
{
199197
#if TARGET_OS_SIMULATOR
200198
// iPhone/iPad, Watch and TV simulators
201-
const auto simulatedDeviceModelName = sentry_getSimulatorDeviceModel();
199+
NSString *simulatedDeviceModelName = sentry_getSimulatorDeviceModel();
202200
SENTRY_LOG_DEBUG(@"Got simulated device model name %@ (running on %@)",
203201
simulatedDeviceModelName, getHardwareDescription(HW_MODEL));
204202
return simulatedDeviceModelName;
205203
#else
206204
# if defined(HW_PRODUCT)
207205
if (@available(iOS 14, macOS 11, *)) {
208-
const auto model = getHardwareDescription(HW_PRODUCT);
206+
NSString *model = getHardwareDescription(HW_PRODUCT);
209207
if (model.length > 0) {
210208
SENTRY_LOG_DEBUG(@"Model name using HW_PRODUCT: %@", model);
211209
return model;

0 commit comments

Comments
 (0)