Skip to content

Commit

Permalink
feat: seperate build & runtime scriptable options configure() (#1046)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind committed Nov 10, 2022
1 parent 2500487 commit b37e981
Show file tree
Hide file tree
Showing 47 changed files with 555 additions and 367 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ jobs:
disk-size: 4096M # Some runs have out of storage error when installing the smoke test.
emulator-options: -no-snapshot-save -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -accel on
disable-animations: true
script: pwsh ./scripts/smoke-test-droid.ps1 -IsIntegrationTest
script: pwsh ./scripts/smoke-test-droid.ps1 -IsIntegrationTest -WarnIfFlaky

- name: Kill emulator if AVD failed.
if: ${{ steps.smoke-test.outputs.status != 'success' }}
Expand Down Expand Up @@ -527,7 +527,7 @@ jobs:
path: samples/IntegrationTest/Build

- name: Build iOS package
run: ./Scripts/smoke-test-ios.ps1 Build -IsIntegrationTest -UnityVersion "${{ matrix.unity-version }}"
run: ./scripts/smoke-test-ios.ps1 Build -IsIntegrationTest -UnityVersion "${{ matrix.unity-version }}"

- name: Upload iOS test app for smoke test.
uses: actions/upload-artifact@v3
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
### Features

- Added Unity version to event context ([#1072](https://github.com/getsentry/sentry-unity/pull/1072))
- Add build-time `ScriptableOptionsConfiguration` scripting interface to support changing settings for native integrations and CLI ([#1046](https://github.com/getsentry/sentry-unity/pull/1046))

### Fixes

- Auto Instrumentation now correctly resolves prebuilt assemblies ([#1066](https://github.com/getsentry/sentry-unity/pull/1066))
- Newly created `ScriptableOptionsConfiguration` script not being set in editor window UI ([#1046](https://github.com/getsentry/sentry-unity/pull/1046))

### Dependencies

Expand Down
8 changes: 8 additions & 0 deletions samples/unity-of-bugs/Assets/Editor.meta

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
@@ -0,0 +1,16 @@
using System;
using UnityEngine;
using Sentry.Unity;
using Sentry.Unity.Editor;

[CreateAssetMenu(fileName = "Assets/Plugins/Sentry/SentryBuildtimeOptionsConfiguration.asset", menuName = "Sentry/Assets/Plugins/Sentry/SentryBuildtimeOptionsConfiguration.asset", order = 999)]
public class SentryBuildtimeOptionsConfiguration : Sentry.Unity.Editor.ScriptableOptionsConfiguration
{
/// See base class for documentation.
/// Learn more at https://docs.sentry.io/platforms/unity/configuration/options/#programmatic-configuration
public override void Configure(SentryUnityOptions options, SentryCliOptions cliOptions)
{
Debug.Log("SentryBuildtimeOptionsConfiguration::Configure() called");
Debug.Log("SentryBuildtimeOptionsConfiguration::Configure() finished");
}
}

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
@@ -0,0 +1,14 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 59bc41c2bf823704a9122d2a5995ffcf, type: 3}
m_Name: SentryBuildtimeOptionsConfiguration
m_EditorClassIdentifier:

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
Expand Up @@ -17,7 +17,7 @@ MonoBehaviour:
<CaptureInEditor>k__BackingField: 1
<EnableLogDebouncing>k__BackingField: 0
<TracesSampleRate>k__BackingField: 0
<AutoInstrumentPerformance>k__BackingField: 0
<PerformanceAutoInstrumentationEnabled>k__BackingField: 1
<AutoSessionTracking>k__BackingField: 1
<AutoSessionTrackingInterval>k__BackingField: 30000
<ReleaseOverride>k__BackingField:
Expand Down Expand Up @@ -47,7 +47,9 @@ MonoBehaviour:
<MacosNativeSupportEnabled>k__BackingField: 1
<LinuxNativeSupportEnabled>k__BackingField: 1
<Il2CppLineNumberSupportEnabled>k__BackingField: 1
<OptionsConfiguration>k__BackingField: {fileID: 11400000, guid: bda1a724b0875436aade31393b0129c0,
<OptionsConfiguration>k__BackingField: {fileID: 11400000, guid: 407b4d5f2fef2c845bf2a3dcdf6b00fb,
type: 2}
<BuildtimeOptionsConfiguration>k__BackingField: {fileID: 11400000, guid: 6bcc81a646c08ce439ab03805d477458,
type: 2}
<Debug>k__BackingField: 1
<DebugOnlyInEditor>k__BackingField: 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 91e386628575c034e89d0f7632eb69b8, type: 3}
m_Name: SentryRuntimeOptionsConfiguration
m_EditorClassIdentifier:

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 0 additions & 25 deletions samples/unity-of-bugs/Assets/Scripts/CustomOptionsConfiguration.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using UnityEngine;
using Sentry.Unity;

[CreateAssetMenu(fileName = "Assets/Resources/Sentry/SentryRuntimeOptionsConfiguration.asset", menuName = "Sentry/Assets/Resources/Sentry/SentryRuntimeOptionsConfiguration.asset", order = 999)]
public class SentryRuntimeOptionsConfiguration : Sentry.Unity.ScriptableOptionsConfiguration
{
/// See base class for documentation.
/// Learn more at https://docs.sentry.io/platforms/unity/configuration/options/#programmatic-configuration
public override void Configure(SentryUnityOptions options)
{
Debug.Log("SentryRuntimeOptionsConfiguration::Configure() called");

/// BeforeSend is only relevant at runtime. It wouldn't hurt to be set at build time, just wouldn't do anything.
options.BeforeSend = sentryEvent =>
{
if (sentryEvent.Tags.ContainsKey("SomeTag"))
{
// Don't send events with a tag SomeTag to Sentry
return null;
}
return sentryEvent;
};

Debug.Log("SentryRuntimeOptionsConfiguration::Configure() finished");
}
}

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
Expand Up @@ -34,7 +34,6 @@ GraphicsSettings:
- {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 16001, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 16003, guid: 0000000000000000f000000000000000, type: 0}
m_PreloadedShaders: []
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
type: 0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ PlayerSettings:
incrementalIl2cppBuild: {}
suppressCommonWarnings: 1
allowUnsafeCode: 0
additionalIl2CppArgs:
additionalIl2CppArgs: ' --emit-source-mapping'
scriptingRuntimeVersion: 1
gcIncremental: 0
assemblyVersionValidation: 1
Expand Down
8 changes: 4 additions & 4 deletions scripts/pack.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Remove-Item "package-release" -Recurse -ErrorAction SilentlyContinue
Remove-Item "package-release" -Recurse -ErrorAction SilentlyContinue
New-Item "package-release" -ItemType Directory

$exclude = @(
Expand All @@ -22,9 +22,9 @@ Copy-Item "CHANGELOG.md" -Destination "package-release/CHANGELOG.md"
Copy-Item "LICENSE.md" -Destination "package-release/LICENSE.md"

# Copy samples
Copy-Item "samples/unity-of-bugs/Assets/Scenes" -Destination "package-release/Samples~/unity-of-bugs/Scenes" -Recurse
Copy-Item "samples/unity-of-bugs/Assets/Scripts" -Destination "package-release/Samples~/unity-of-bugs/Scripts" -Recurse `
-Exclude "SmokeTestOptions.cs*"
Copy-Item "samples/unity-of-bugs/Assets/Scenes*" -Destination "package-release/Samples~/unity-of-bugs/" -Recurse
Copy-Item "samples/unity-of-bugs/Assets/Editor*" -Destination "package-release/Samples~/unity-of-bugs/" -Recurse
Copy-Item "samples/unity-of-bugs/Assets/Scripts*" -Destination "package-release/Samples~/unity-of-bugs/" -Recurse

# Create zip
Compress-Archive "package-release/*" -DestinationPath "package-release.zip" -Force
20 changes: 13 additions & 7 deletions scripts/smoke-test-droid.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
param (
[Parameter(Position = 0)]
[Switch] $IsIntegrationTest
[Switch] $IsIntegrationTest,
[Switch] $WarnIfFlaky
)

. $PSScriptRoot/../test/Scripts.Integration.Test/common.ps1
Expand Down Expand Up @@ -216,7 +217,7 @@ function ExitNow([string] $status, [string] $message)
{
Write-Host $message -ForegroundColor Green
}
elseif ($status -ieq "flaky")
elseif ($status -ieq "flaky" -and $WarnIfFlaky)
{
Write-Warning $message
}
Expand Down Expand Up @@ -259,6 +260,8 @@ If (-not (Test-Path -Path "$ApkPath/$ApkFileName" ))
# Test
foreach ($device in $DeviceList)
{
adb -s $device logcat -c

$deviceApi = "$(adb -s $device shell getprop ro.build.version.sdk)".Trim()
$deviceSdk = "$(adb -s $device shell getprop ro.build.version.release)".Trim()
Write-Host "`nChecking device $device with SDK '$deviceSdk' and API '$deviceApi'"
Expand All @@ -283,7 +286,7 @@ foreach ($device in $DeviceList)
do
{
Write-Host "Installing test app..."
$stdout = (adb -s $device install -r $ApkPath/$ApkFileName)
$stdout = (adb -s $device install -r $ApkPath/$ApkFileName 2>&1)

if ($stdout.Contains("Broken pipe"))
{
Expand All @@ -299,12 +302,15 @@ foreach ($device in $DeviceList)
ExitNow "failed" "Failed to Install APK: $stdout."
}

function RunTest([string] $Name, [string] $SuccessString, [string] $FailureString)
function RunTest([string] $Name, [string] $SuccessString, [string] $FailureString, [switch] $PreserveLogcat)
{
Write-Host "::group::Test: '$name'"

Write-Host "Clearing logcat from $device."
adb -s $device logcat -c
if (!$PreserveLogcat)
{
Write-Host "Clearing logcat from $device."
adb -s $device logcat -c
}

adb -s $device shell am start -n $TestActivityName -e test $Name
#despite calling start, the app might not be started yet.
Expand Down Expand Up @@ -411,7 +417,7 @@ foreach ($device in $DeviceList)
# Note: mobile apps post the crash on the second app launch, so we must run both as part of the "CrashTestWithServer"
CrashTestWithServer -SuccessString "POST /api/12345/envelope/ HTTP/1.1`" 200 -b'1f8b08000000000000" -CrashTestCallback {
RunTest -Name "crash" -SuccessString "CRASH TEST: Issuing a native crash" -FailureString "CRASH TEST: FAIL"
RunTest -Name "has-crashed"
RunTest -Name "has-crashed" -PreserveLogcat
}
}
catch
Expand Down
20 changes: 9 additions & 11 deletions src/Sentry.Unity.Editor.iOS/BuildPostProcess.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using Sentry.Extensibility;
using Sentry.Unity.Editor.ConfigurationWindow;
using UnityEditor;
using UnityEditor.Callbacks;

Expand All @@ -16,9 +17,7 @@ public static void OnPostProcessBuild(BuildTarget target, string pathToProject)
return;
}

var options = SentryScriptableObject
.Load<ScriptableSentryUnityOptions>(ScriptableSentryUnityOptions.GetConfigPath())
?.ToSentryUnityOptions(BuildPipeline.isBuildingPlayer);
var (options, cliOptions) = SentryScriptableObject.ConfiguredBuildtimeOptions();
var logger = options?.DiagnosticLogger ?? new UnityLogger(new SentryUnityOptions());

try
Expand All @@ -37,32 +36,31 @@ public static void OnPostProcessBuild(BuildTarget target, string pathToProject)

if (options is null)
{
logger.LogWarning("Native support disabled. " +
"Sentry has not been configured. You can do that through the editor: Tools -> Sentry");
logger.LogWarning("iOS native support disabled because Sentry has not been configured. " +
"You can do that through the editor: {0}", SentryWindow.EditorMenuPath);
return;
}

if (!options.IsValid())
{
logger.LogWarning("Native support disabled.");
logger.LogWarning("iOS native support disabled.");
return;
}

if (!options.IosNativeSupportEnabled)
{
logger.LogDebug("iOS Native support disabled through the options.");
logger.LogDebug("iOS native support disabled through the options.");
return;
}

sentryXcodeProject.AddNativeOptions(options);
sentryXcodeProject.AddSentryToMain(options);

var sentryCliOptions = SentryScriptableObject.CreateOrLoad<SentryCliOptions>(SentryCliOptions.GetConfigPath());
if (sentryCliOptions.IsValid(logger))
if (cliOptions?.IsValid(logger, EditorUserBuildSettings.development) is true)
{
SentryCli.CreateSentryProperties(pathToProject, sentryCliOptions, options);
SentryCli.CreateSentryProperties(pathToProject, cliOptions, options);
SentryCli.AddExecutableToXcodeProject(pathToProject, logger);
sentryXcodeProject.AddBuildPhaseSymbolUpload(logger, sentryCliOptions);
sentryXcodeProject.AddBuildPhaseSymbolUpload(logger, cliOptions);
}
else if (options.Il2CppLineNumberSupportEnabled)
{
Expand Down
Loading

0 comments on commit b37e981

Please sign in to comment.