Skip to content

Commit 42c400e

Browse files
jpnurmialexsohn1126
authored andcommitted
build: allow local modules/sentry-cocoa clone for development (#4551)
1 parent 5b45016 commit 42c400e

File tree

4 files changed

+70
-12
lines changed

4 files changed

+70
-12
lines changed

CONTRIBUTING.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,26 @@ Once changes to Ben.Demystifier have been merged into the main branch then, the
171171
should be updated from the main branch and the `modules/make-internal.sh` script run again (if necessary). This repo
172172
should reference the most recent commit on the `internal` branch of Ben.Demystifier then (functionally identical to the
173173
main branch - the only difference being the changes to member visibility).
174+
175+
## Local Sentry Cocoa SDK checkout
176+
177+
By default, `Sentry.Bindings.Cocoa` downloads a pre-built Sentry Cocoa SDK from
178+
GitHub Releases. The version is specified in `modules/sentry-cocoa.properties`.
179+
180+
If you want to build an unreleased Sentry Cocoa SDK version from source instead,
181+
replace the pre-built SDK with [getsentry/sentry-cocoa](https://github.com/getsentry/sentry-cocoa/)
182+
by cloning it into the `modules/sentry-cocoa` directory:
183+
184+
```sh
185+
$ rm -rf modules/sentry-cocoa
186+
$ gh repo clone getsentry/sentry-cocoa modules/sentry-cocoa
187+
$ dotnet build ... # uses modules/sentry-cocoa as is
188+
```
189+
190+
To switch back to the pre-built SDK, delete the `modules/sentry-cocoa` directory
191+
and let the next build download the pre-built SDK again:
192+
193+
```sh
194+
$ rm -rf modules/sentry-cocoa
195+
$ dotnet build ... # downloads pre-built Cocoa SDK into modules/sentry-cocoa
196+
```

scripts/build-sentry-cocoa.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ xcodebuild archive -project Sentry.xcodeproj \
2525
-archivePath ./Carthage/output-ios.xcarchive \
2626
SKIP_INSTALL=NO \
2727
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
28+
./scripts/remove-architectures.sh ./Carthage/output-ios.xcarchive arm64e
2829
xcodebuild archive -project Sentry.xcodeproj \
2930
-scheme Sentry \
3031
-configuration Release \
@@ -47,6 +48,7 @@ xcodebuild archive -project Sentry.xcodeproj \
4748
-archivePath ./Carthage/output-maccatalyst.xcarchive \
4849
SKIP_INSTALL=NO \
4950
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
51+
./scripts/remove-architectures.sh ./Carthage/output-maccatalyst.xcarchive arm64e
5052
xcodebuild -create-xcframework \
5153
-framework ./Carthage/output-maccatalyst.xcarchive/Products/Library/Frameworks/Sentry.framework \
5254
-output ./Carthage/Build-maccatalyst/Sentry.xcframework
@@ -60,7 +62,7 @@ find Carthage/Build-ios/Sentry.xcframework/ios-arm64 -name '*.h' -exec cp {} Car
6062
find Carthage/Build* \( -name Headers -o -name PrivateHeaders -o -name Modules \) -exec rm -rf {} +
6163
rm -rf Carthage/output-*
6264

63-
cp ../../.git/modules/modules/sentry-cocoa/HEAD Carthage/.built-from-sha
65+
cp .git/HEAD Carthage/.built-from-sha
6466
echo ""
6567

6668
popd >/dev/null

scripts/generate-cocoa-bindings.ps1

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,19 @@ Set-StrictMode -Version Latest
44
$ErrorActionPreference = 'Stop'
55

66
$RootPath = (Get-Item $PSScriptRoot).Parent.FullName
7-
$CocoaSdkPath = "$RootPath/modules/sentry-cocoa/Sentry.framework"
7+
$CocoaSdkPath = "$RootPath/modules/sentry-cocoa"
8+
if (Test-Path "$CocoaSdkPath/.git")
9+
{
10+
# Cocoa SDK cloned to modules/sentry-cocoa for local development
11+
$HeadersPath = "$CocoaSdkPath/Carthage/Headers"
12+
$PrivateHeadersPath = "$CocoaSdkPath/Carthage/Headers"
13+
}
14+
else
15+
{
16+
# Cocoa SDK downloaded from GitHub releases and extracted into modules/sentry-cocoa
17+
$HeadersPath = "$CocoaSdkPath/Sentry.framework/Headers"
18+
$PrivateHeadersPath = "$CocoaSdkPath/Sentry.framework/PrivateHeaders"
19+
}
820
$BindingsPath = "$RootPath/src/Sentry.Bindings.Cocoa"
921
$BackupPath = "$BindingsPath/obj/_unpatched"
1022

@@ -101,7 +113,7 @@ Write-Output "iPhoneSdkVersion: $iPhoneSdkVersion"
101113
# ...instead of:
102114
# `#import "SomeHeader.h"`
103115
# This causes sharpie to fail resolve those headers
104-
$filesToPatch = Get-ChildItem -Path "$CocoaSdkPath/Headers" -Filter *.h -Recurse | Select-Object -ExpandProperty FullName
116+
$filesToPatch = Get-ChildItem -Path "$HeadersPath" -Filter *.h -Recurse | Select-Object -ExpandProperty FullName
105117
foreach ($file in $filesToPatch)
106118
{
107119
if (Test-Path $file)
@@ -116,7 +128,7 @@ foreach ($file in $filesToPatch)
116128
Write-Host "File not found: $file"
117129
}
118130
}
119-
$privateHeaderFile = "$CocoaSdkPath/PrivateHeaders/PrivatesHeader.h"
131+
$privateHeaderFile = "$PrivateHeadersPath/PrivatesHeader.h"
120132
if (Test-Path $privateHeaderFile)
121133
{
122134
$content = Get-Content -Path $privateHeaderFile -Raw
@@ -134,8 +146,8 @@ else
134146
Write-Output 'Generating bindings with Objective Sharpie.'
135147
sharpie bind -sdk $iPhoneSdkVersion `
136148
-scope "$CocoaSdkPath" `
137-
"$CocoaSdkPath/Headers/Sentry.h" `
138-
"$CocoaSdkPath/PrivateHeaders/PrivateSentrySDKOnly.h" `
149+
"$HeadersPath/Sentry.h" `
150+
"$PrivateHeadersPath/PrivateSentrySDKOnly.h" `
139151
-o $BindingsPath `
140152
-c -Wno-objc-property-no-attribute
141153

src/Sentry.Bindings.Cocoa/Sentry.Bindings.Cocoa.csproj

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,17 @@
1212
<SentryCocoaProperties>$([System.IO.File]::ReadAllText("$(MSBuildThisFileDirectory)../../modules/sentry-cocoa.properties"))</SentryCocoaProperties>
1313
<SentryCocoaVersion>$([System.Text.RegularExpressions.Regex]::Match($(SentryCocoaProperties), 'version\s*=\s*([^\s]+)').Groups[1].Value)</SentryCocoaVersion>
1414
<SentryCocoaFramework>$(SentryCocoaCache)Sentry-$(SentryCocoaVersion).xcframework</SentryCocoaFramework>
15+
<SentryCocoaBindingInputs>../../modules/sentry-cocoa.properties;../../scripts/generate-cocoa-bindings.ps1</SentryCocoaBindingInputs>
1516
<!-- SentrySpan.g.cs: error CS0108: 'ISentrySpan.Serialize()' hides inherited member 'ISentrySerializable.Serialize()'. Use the new keyword if hiding was intended -->
1617
<NoWarn>$(NoWarn);CS0108</NoWarn>
1718
</PropertyGroup>
1819

20+
<!-- Override values for local Cocoa SDK builds -->
21+
<PropertyGroup Condition="Exists('$(SentryCocoaCache).git')">
22+
<SentryCocoaFramework>$(SentryCocoaCache)Carthage\Build-$(TargetPlatformIdentifier)\Sentry.xcframework</SentryCocoaFramework>
23+
<SentryCocoaBindingInputs>../../scripts/generate-cocoa-bindings.ps1;../../modules/sentry-cocoa/Carthage/.built-from-sha</SentryCocoaBindingInputs>
24+
</PropertyGroup>
25+
1926
<!-- Build empty assemblies when not on macOS, to pass the solution build. -->
2027
<ItemGroup Condition="!$([MSBuild]::IsOSPlatform('OSX'))">
2128
<Compile Remove="*" />
@@ -52,8 +59,8 @@
5259
</ItemGroup>
5360

5461
<!-- Downloads and sets up the Cocoa SDK: dotnet msbuild /t:setupCocoaSDK src/Sentry.Bindings.Cocoa/Sentry.Bindings.Cocoa.csproj -->
55-
<Target Name="_SetupCocoaSDK"
56-
Condition="$([MSBuild]::IsOSPlatform('OSX')) And !Exists('$(SentryCocoaFramework)')">
62+
<Target Name="_DownloadCocoaSDK"
63+
Condition="$([MSBuild]::IsOSPlatform('OSX')) And !Exists('$(SentryCocoaCache).git') And !Exists('$(SentryCocoaFramework)')">
5764

5865
<Message Importance="High" Text="Setting up the Cocoa SDK version '$(SentryCocoaVersion)'." />
5966

@@ -84,14 +91,28 @@
8491
SkipUnchangedFiles="true" />
8592
</Target>
8693

94+
<!-- Build the Sentry Cocoa SDK from source -->
95+
<Target Name="_BuildCocoaSDK"
96+
Condition="$([MSBuild]::IsOSPlatform('OSX')) And Exists('$(SentryCocoaCache).git')"
97+
Inputs="..\..\modules\sentry-cocoa\.git\HEAD;..\..\scripts\build-sentry-cocoa.sh" Outputs="..\..\modules\sentry-cocoa\Carthage\.built-from-sha">
98+
99+
<Message Importance="High" Text="Building the Cocoa SDK from source." />
100+
<Exec Command="bash ../../scripts/build-sentry-cocoa.sh" IgnoreStandardErrorWarningFormat="true" />
101+
</Target>
102+
103+
<!-- Choose between download and build -->
104+
<Target Name="_SetupCocoaSDK"
105+
DependsOnTargets="_DownloadCocoaSDK;_BuildCocoaSDK"
106+
Condition="$([MSBuild]::IsOSPlatform('OSX'))" />
107+
87108
<!-- Setup exactly once: https://learn.microsoft.com/visualstudio/msbuild/run-target-exactly-once -->
88109
<Target Name="SetupCocoaSDKBeforeOuterBuild" DependsOnTargets="_SetupCocoaSDK"
89-
Condition="$([MSBuild]::IsOSPlatform('OSX')) And !Exists('$(SentryCocoaFramework)')"
110+
Condition="$([MSBuild]::IsOSPlatform('OSX'))"
90111
BeforeTargets="DispatchToInnerBuilds" />
91112

92113
<Target Name="SetupCocoaSDK"
93114
BeforeTargets="BeforeBuild"
94-
Condition="$([MSBuild]::IsOSPlatform('OSX')) And !Exists('$(SentryCocoaFramework)')">
115+
Condition="$([MSBuild]::IsOSPlatform('OSX'))">
95116
<!-- Setup exactly once: https://learn.microsoft.com/visualstudio/msbuild/run-target-exactly-once -->
96117
<MSBuild Projects="$(MSBuildProjectFullPath)" Targets="_SetupCocoaSDK" RemoveProperties="TargetFramework" />
97118
</Target>
@@ -102,8 +123,8 @@
102123

103124
<!-- Generate bindings -->
104125
<Target Name="_GenerateSentryCocoaBindings" AfterTargets="SetupCocoaSDK"
105-
Condition="$([MSBuild]::IsOSPlatform('OSX')) and Exists('$(SentryCocoaFrameworkHeaders)')"
106-
Inputs="../../modules/sentry-cocoa.properties;../../scripts/generate-cocoa-bindings.ps1"
126+
Condition="$([MSBuild]::IsOSPlatform('OSX'))"
127+
Inputs="$(SentryCocoaBindingInputs)"
107128
Outputs="ApiDefinitions.cs;StructsAndEnums.cs">
108129
<MSBuild Projects="$(MSBuildProjectFile)" Targets="_InnerGenerateSentryCocoaBindings" Properties="TargetFramework=once" />
109130
</Target>

0 commit comments

Comments
 (0)