Skip to content

Commit 076b0f1

Browse files
authored
Chore: minor improvements (#2769)
1 parent 3ebfcb0 commit 076b0f1

File tree

5 files changed

+83
-97
lines changed

5 files changed

+83
-97
lines changed

.github/actions/buildcocoasdk/action.yml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,16 @@ runs:
44
using: composite
55

66
steps:
7-
8-
- name: Fetch version tags for Sentry Cocoa SDK
9-
shell: bash
10-
run: git fetch --tags --quiet
11-
working-directory: modules/sentry-cocoa
12-
13-
- name: Get Sentry Cocoa SHA
7+
- name: Get submodule status
148
shell: bash
15-
run: echo "SENTRY_COCOA_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV
16-
working-directory: modules/sentry-cocoa
9+
run: cat .git/modules/modules/sentry-cocoa/HEAD
1710

1811
- name: Cache Sentry Cocoa SDK
1912
id: cache-sentry-cocoa
2013
uses: actions/cache@v3
2114
with:
2215
path: modules/sentry-cocoa/Carthage
23-
key: sentry-cocoa-${{ env.SENTRY_COCOA_SHA }}
16+
key: sentry-cocoa-${{ hashFiles('scripts/build-sentry-cocoa.sh', '.git/modules/modules/sentry-cocoa/HEAD') }}
2417

2518
- name: Build Sentry Cocoa SDK
2619
if: ${{ steps.cache-sentry-cocoa.outputs.cache-hit != 'true' }}

.github/actions/environment/action.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ runs:
2525
with:
2626
dotnet-version: |
2727
3.1.x
28-
6.0.x
28+
6.0.x
2929
7.0.x
3030
8.0.x
31-
31+
3232
- name: Dependency Caching
3333
uses: actions/cache@v3
3434
# Cache is too slow on Windows to be useful. See https://github.com/actions/cache/issues/752
@@ -47,4 +47,4 @@ runs:
4747
maui-android \
4848
${{ runner.os == 'macOS' && 'maui-ios maui-maccatalyst maui-windows' || '' }} \
4949
${{ runner.os == 'Windows' && 'maui-windows' || '' }} \
50-
--temp-dir "${{ runner.temp }}"
50+
--temp-dir "${{ runner.temp }}"

scripts/build-sentry-cocoa.sh

Lines changed: 57 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,61 @@
11
#!/bin/bash
2+
set -euo pipefail
23

3-
pushd "$(dirname "$0")" > /dev/null
4+
pushd "$(dirname "$0")" >/dev/null
45
cd ../modules/sentry-cocoa
56

6-
if [ $? -eq 0 ]
7-
then
8-
SHA=$(git rev-parse HEAD)
9-
SHAFILE=./Carthage/.built-from-sha
10-
[ -f $SHAFILE ] && SHAFROMFILE=$(<$SHAFILE)
11-
VERSION="$(git describe --tags) ($(git rev-parse --short HEAD))"
12-
13-
if [ "$SHA" == "$SHAFROMFILE" ]; then
14-
echo "Sentry Cocoa SDK $VERSION was already built"
15-
else
16-
echo "Building Sentry Cocoa SDK $VERSION"
17-
rm -rf Carthage
18-
19-
# Grabbing the first SDK versions
20-
sdks=$(xcodebuild -showsdks)
21-
ios_sdk=$(echo "$sdks" | awk '/iOS SDKs/{getline; print $NF}')
22-
ios_simulator_sdk=$(echo "$sdks" | awk '/iOS Simulator SDKs/{getline; print $NF}')
23-
24-
# Note - We keep the build output in separate directories so that .NET
25-
# bundles iOS with net6.0-ios and Mac Catalyst with net6.0-maccatalyst.
26-
# The lack of symlinks in the ios builds, means we should also be able
27-
# to use the package on Windows with "Pair to Mac".
28-
29-
# Build for iOS and iOS simulator.
30-
xcodebuild -project Sentry.xcodeproj \
31-
-scheme Sentry \
32-
-configuration Release \
33-
-sdk "$ios_sdk" \
34-
-derivedDataPath ./Carthage/output-ios
35-
xcodebuild -project Sentry.xcodeproj \
36-
-scheme Sentry \
37-
-configuration Release \
38-
-sdk "$ios_simulator_sdk" \
39-
-derivedDataPath ./Carthage/output-ios
40-
xcodebuild -create-xcframework \
41-
-framework ./Carthage/output-ios/Build/Products/Release-iphoneos/Sentry.framework \
42-
-framework ./Carthage/output-ios/Build/Products/Release-iphonesimulator/Sentry.framework \
43-
-output ./Carthage/Build-ios/Sentry.xcframework
44-
45-
# Separately, build for Mac Catalyst
46-
xcodebuild -project Sentry.xcodeproj \
47-
-scheme Sentry \
48-
-configuration Release \
49-
-destination 'platform=macOS,variant=Mac Catalyst' \
50-
-derivedDataPath ./Carthage/output-maccatalyst
51-
xcodebuild -create-xcframework \
52-
-framework ./Carthage/output-maccatalyst/Build/Products/Release-maccatalyst/Sentry.framework \
53-
-output ./Carthage/Build-maccatalyst/Sentry.xcframework
54-
55-
# Copy headers - used for generating bindings
56-
mkdir Carthage/Headers
57-
find Carthage/Build-ios/Sentry.xcframework/ios-arm64 -name '*.h' -exec cp {} Carthage/Headers \;
58-
59-
echo "$SHA" > "$SHAFILE"
60-
echo ""
61-
fi
62-
63-
# Remove anything we don't want to bundle in the nuget package.
64-
find Carthage/Build* \( -name Headers -o -name PrivateHeaders -o -name Modules \) -exec rm -rf {} +
65-
fi
66-
67-
popd > /dev/null
7+
rm -rf Carthage
8+
9+
# Grabbing the first SDK versions
10+
sdks=$(xcodebuild -showsdks)
11+
ios_sdk=$(echo "$sdks" | awk '/iOS SDKs/{getline; print $NF}')
12+
ios_simulator_sdk=$(echo "$sdks" | awk '/iOS Simulator SDKs/{getline; print $NF}')
13+
macos_sdk=$(echo "$sdks" | awk '/macOS SDKs/{getline; print $NF}')
14+
15+
# Note - We keep the build output in separate directories so that .NET
16+
# bundles iOS with net6.0-ios and Mac Catalyst with net6.0-maccatalyst.
17+
# The lack of symlinks in the ios builds, means we should also be able
18+
# to use the package on Windows with "Pair to Mac".
19+
20+
# Build for iOS and iOS simulator.
21+
echo "::group::Building sentry-cocoa for iOS and iOS simulator"
22+
xcodebuild -project Sentry.xcodeproj \
23+
-scheme Sentry \
24+
-configuration Release \
25+
-sdk "$ios_sdk" \
26+
-derivedDataPath ./Carthage/output-ios
27+
xcodebuild -project Sentry.xcodeproj \
28+
-scheme Sentry \
29+
-configuration Release \
30+
-sdk "$ios_simulator_sdk" \
31+
-derivedDataPath ./Carthage/output-ios
32+
xcodebuild -create-xcframework \
33+
-framework ./Carthage/output-ios/Build/Products/Release-iphoneos/Sentry.framework \
34+
-framework ./Carthage/output-ios/Build/Products/Release-iphonesimulator/Sentry.framework \
35+
-output ./Carthage/Build-ios/Sentry.xcframework
36+
echo "::endgroup::"
37+
38+
# Separately, build for Mac Catalyst
39+
echo "::group::Building sentry-cocoa for Mac Catalyst"
40+
xcodebuild -project Sentry.xcodeproj \
41+
-scheme Sentry \
42+
-configuration Release \
43+
-destination 'platform=macOS,variant=Mac Catalyst' \
44+
-derivedDataPath ./Carthage/output-maccatalyst
45+
xcodebuild -create-xcframework \
46+
-framework ./Carthage/output-maccatalyst/Build/Products/Release-maccatalyst/Sentry.framework \
47+
-output ./Carthage/Build-maccatalyst/Sentry.xcframework
48+
echo "::endgroup::"
49+
50+
# Copy headers - used for generating bindings
51+
mkdir Carthage/Headers
52+
find Carthage/Build-ios/Sentry.xcframework/ios-arm64 -name '*.h' -exec cp {} Carthage/Headers \;
53+
54+
# Remove anything we don't want to bundle in the nuget package.
55+
find Carthage/Build* \( -name Headers -o -name PrivateHeaders -o -name Modules \) -exec rm -rf {} +
56+
rm -rf Carthage/output-*
57+
58+
cp ../../.git/modules/modules/sentry-cocoa/HEAD Carthage/.built-from-sha
59+
echo ""
60+
61+
popd >/dev/null

src/Sentry/Internal/Extensions/StringExtensions.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,19 @@ public static string ToSnakeCase(this string str) =>
1111
/// Otherwise, returns <paramref name="str"/>.
1212
/// </summary>
1313
public static string? NullIfWhitespace(this string? str) => string.IsNullOrWhiteSpace(str) ? null : str;
14+
15+
public static long ParseHexAsLong(this string str)
16+
{
17+
// It should be in hex format, such as "0x7fff5bf346c0"
18+
if (str.StartsWith("0x") &&
19+
long.TryParse(str[2..], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var result))
20+
{
21+
return result;
22+
}
23+
else if (long.TryParse(str, NumberStyles.Number, CultureInfo.InvariantCulture, out result))
24+
{
25+
return result;
26+
}
27+
throw new FormatException($"ParseHexAsLong() cannot parse '{str}'");
28+
}
1429
}

src/Sentry/Platforms/Native/CFunctions.cs

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Sentry.Extensibility;
2+
using Sentry.Internal.Extensions;
23

34
namespace Sentry.Native;
45

@@ -44,25 +45,6 @@ internal static void SetValueIfNotNull(sentry_value_t obj, string key, double? v
4445
return sentry_value_is_null(cValue) == 0 ? cValue : null;
4546
}
4647

47-
internal static long? GetValueHex(sentry_value_t obj, string key)
48-
{
49-
if (GetValueString(obj, key) is { } s && s.Length > 0)
50-
{
51-
// It should be in hex format, such as "0x7fff5bf346c0"
52-
if (s.StartsWith("0x") &&
53-
long.TryParse(s[2..], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var result))
54-
{
55-
return result;
56-
}
57-
else if (long.TryParse(s, NumberStyles.Number, CultureInfo.InvariantCulture, out result))
58-
{
59-
return result;
60-
}
61-
throw new FormatException($"GetValueHex() cannot parse '{s}'");
62-
}
63-
return null;
64-
}
65-
6648
internal static string? GetValueString(sentry_value_t obj, string key)
6749
{
6850
if (GetValueOrNul(obj, key) is { } cValue)
@@ -167,6 +149,7 @@ internal static void SetValueIfNotNull(sentry_value_t obj, string key, double? v
167149

168150
internal static Dictionary<long, DebugImage> LoadDebugImages(IDiagnosticLogger? logger)
169151
{
152+
logger?.LogDebug("Collecting a list of native debug images.");
170153
var result = new Dictionary<long, DebugImage>();
171154
try
172155
{
@@ -176,6 +159,7 @@ internal static Dictionary<long, DebugImage> LoadDebugImages(IDiagnosticLogger?
176159
if (!IsNull(cList))
177160
{
178161
var len = sentry_value_get_length(cList).ToUInt32();
162+
logger?.LogDebug("There are {0} native debug images, parsing the information.", len);
179163
for (uint i = 0; i < len; i++)
180164
{
181165
var cItem = sentry_value_get_by_index(cList, (UIntPtr)i);
@@ -185,8 +169,9 @@ internal static Dictionary<long, DebugImage> LoadDebugImages(IDiagnosticLogger?
185169
// * https://github.com/getsentry/sentry-native/blob/8faa78298da68d68043f0c3bd694f756c0e95dfa/src/modulefinder/sentry_modulefinder_windows.c#L81
186170
// * https://github.com/getsentry/sentry-native/blob/8faa78298da68d68043f0c3bd694f756c0e95dfa/src/modulefinder/sentry_modulefinder_windows.c#L24
187171
// * https://github.com/getsentry/sentry-native/blob/c5c31e56d36bed37fa5422750a591f44502edb41/src/modulefinder/sentry_modulefinder_linux.c#L465
188-
if (GetValueHex(cItem, "image_addr") is { } imageAddress)
172+
if (GetValueString(cItem, "image_addr") is { } imageAddr && imageAddr.Length > 0)
189173
{
174+
var imageAddress = imageAddr.ParseHexAsLong();
190175
result.Add(imageAddress, new DebugImage()
191176
{
192177
CodeFile = GetValueString(cItem, "code_file"),
@@ -209,7 +194,6 @@ internal static Dictionary<long, DebugImage> LoadDebugImages(IDiagnosticLogger?
209194
}
210195
catch (Exception e)
211196
{
212-
// Adding the Sentry logger tag ensures we don't send this error to Sentry.
213197
logger?.LogWarning("Error loading the list of debug images", e);
214198
}
215199
return result;

0 commit comments

Comments
 (0)