-
-
Notifications
You must be signed in to change notification settings - Fork 57
iOS: native support #254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
iOS: native support #254
Changes from all commits
1ca5f10
e7e8479
88ef4d5
0908f67
61e7737
1bbc257
ef0fa15
c01b417
75326d3
64f6b30
20c4fbd
f929999
e2d6653
1996527
dd91db5
65c0381
5d716e9
644ba52
62884dd
3849c0f
9a99d5c
45af472
fc025b2
db2d3bb
718108a
bd2d0e2
1fa6170
9359b58
79cc104
de78c19
c4a3ae2
bb2f52d
bd663e8
5cd5353
54e1e5d
dbef5f6
7ba5cb0
875fa0e
d380e9b
3db5ce8
a8a5ac5
ca080e7
0d16af3
867fec3
edd6ec7
67382e8
7c45a87
f9896b2
253484a
a206db2
dc822a9
484fd99
75b5d44
5a07dec
1d8fbde
801f50f
36b135c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "src/sentry-dotnet"] | ||
path = src/sentry-dotnet | ||
url = https://github.com/getsentry/sentry-dotnet.git | ||
[submodule "src/sentry-cocoa"] | ||
path = src/sentry-cocoa | ||
url = https://github.com/getsentry/sentry-cocoa |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
<Project InitialTargets="RestoreSubmodule"> | ||
<Project InitialTargets="RestoreSubmodules"> | ||
<!-- If sentry-dotnet is not found, restore git submodules --> | ||
<Target Name="RestoreSubmodule" | ||
Condition="!Exists('src/sentry-dotnet/src/Sentry/Sentry.csproj')"> | ||
<Message Importance="High" Text="sentry-dotnet not found. Restoring git submodules."></Message> | ||
<Target Name="RestoreSubmodules" | ||
Condition="!Exists('src/sentry-dotnet/src/Sentry/Sentry.csproj') | ||
OR !Exists('src/sentry-cocoa/Sentry.xcodeproj')"> | ||
<Message Importance="High" Text="Restoring git submodules."></Message> | ||
<Exec Command="git submodule update --init --recursive"></Exec> | ||
</Target> | ||
</Project> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,9 +27,10 @@ MonoBehaviour: | |
<IsEnvironmentUser>k__BackingField: 0 | ||
<EnableOfflineCaching>k__BackingField: 1 | ||
<MaxCacheItems>k__BackingField: 30 | ||
<InitCacheFlushTimeout>k__BackingField: 1000 | ||
<InitCacheFlushTimeout>k__BackingField: 2000 | ||
<ShutdownTimeout>k__BackingField: 2000 | ||
<MaxQueueItems>k__BackingField: 30 | ||
<IOSNativeSupportEnabled>k__BackingField: 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to consider the upgrade path. Where this field doesn't exist and will default to |
||
<Debug>k__BackingField: 1 | ||
<DebugOnlyInEditor>k__BackingField: 1 | ||
<DiagnosticLevel>k__BackingField: 2 | ||
<DiagnosticLevel>k__BackingField: 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using Sentry.Extensibility; | ||
using UnityEditor; | ||
using UnityEditor.Callbacks; | ||
|
||
namespace Sentry.Unity.Editor.iOS | ||
{ | ||
public static class BuildPostProcess | ||
{ | ||
[PostProcessBuild(1)] | ||
public static void OnPostProcessBuild(BuildTarget target, string pathToProject) | ||
{ | ||
if (target != BuildTarget.iOS) | ||
{ | ||
return; | ||
} | ||
|
||
var options = ScriptableSentryUnityOptions.LoadSentryUnityOptions(); | ||
if (!options.ShouldInitializeSdk()) | ||
{ | ||
return; | ||
} | ||
bruno-garcia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (!options!.IOSNativeSupportEnabled) | ||
{ | ||
options.DiagnosticLogger?.LogDebug("iOS Native support disabled. Won't modify the xcode project"); | ||
return; | ||
bruno-garcia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
try | ||
{ | ||
using var sentryXcodeProject = SentryXcodeProject.Open(pathToProject, options); | ||
sentryXcodeProject.AddSentryFramework(); | ||
sentryXcodeProject.AddNativeOptions(); | ||
sentryXcodeProject.AddSentryToMain(); | ||
} | ||
catch (Exception e) | ||
{ | ||
options.DiagnosticLogger?.LogError("Failed to add Sentry to the xcode project", e); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using System.IO; | ||
using System.Text.RegularExpressions; | ||
using Sentry.Extensibility; | ||
|
||
namespace Sentry.Unity.Editor.iOS | ||
{ | ||
internal interface INativeMain | ||
{ | ||
public void AddSentry(string pathToMain, IDiagnosticLogger? logger); | ||
} | ||
|
||
internal class NativeMain : INativeMain | ||
{ | ||
private const string Include = @"#include <Sentry/Sentry.h> | ||
#include ""SentryOptions.m"" | ||
"; | ||
private const string Init = @" | ||
[SentrySDK startWithOptions:getSentryOptions()]; | ||
"; | ||
|
||
public void AddSentry(string pathToMain, IDiagnosticLogger? logger) | ||
{ | ||
if (!File.Exists(pathToMain)) | ||
{ | ||
throw new FileNotFoundException("Could not find main.", pathToMain); | ||
} | ||
|
||
var main = File.ReadAllText(pathToMain); | ||
if (ContainsSentry(main, logger)) | ||
{ | ||
return; | ||
} | ||
|
||
var sentryMain = AddSentryToMain(main); | ||
File.WriteAllText(pathToMain, sentryMain); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are 3 exit conditions before we add Sentry. It could be useful when troubleshooting to log Debug (or error on |
||
} | ||
|
||
internal bool ContainsSentry(string main, IDiagnosticLogger? logger) | ||
{ | ||
if (main.Contains(Include)) | ||
{ | ||
logger?.LogInfo("'main.mm' already contains Sentry."); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
internal string AddSentryToMain(string main) | ||
{ | ||
main = main.Insert(0, Include); | ||
|
||
var initRegex = new Regex(@"int main\(int argc, char\* argv\[\]\)\s+{\s+@autoreleasepool\s+{"); | ||
var match = initRegex.Match(main); | ||
if (match.Success) | ||
{ | ||
return main.Insert(match.Index + match.Length, Init); | ||
} | ||
|
||
throw new ArgumentException($"Failed to add Sentry to main.\n{main}", nameof(main)); | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.