@@ -25,51 +25,55 @@ public static void OnPostProcessBuild(BuildTarget target, string executablePath)
2525
2626 var ( options , cliOptions ) = SentryScriptableObject . ConfiguredBuildTimeOptions ( ) ;
2727 var logger = options ? . DiagnosticLogger ?? new UnityLogger ( options ?? new SentryUnityOptions ( ) ) ;
28+
29+ if ( options is null )
30+ {
31+ logger . LogWarning ( "Native support disabled because Sentry has not been configured. " +
32+ "You can do that through the editor: {0}" , SentryWindow . EditorMenuPath ) ;
33+ return ;
34+ }
35+
36+ if ( ! options . IsValid ( ) )
37+ {
38+ logger . LogDebug ( "Skipping native post build process." ) ;
39+ return ;
40+ }
41+
2842#pragma warning disable CS0618
2943 var isMono = PlayerSettings . GetScriptingBackend ( targetGroup ) == ScriptingImplementation . Mono2x ;
3044#pragma warning restore CS0618
3145
32- var buildOutputDir = Path . GetDirectoryName ( executablePath ) ;
3346 var executableName = Path . GetFileName ( executablePath ) ;
34-
35- try
47+ var buildOutputDir = Path . GetDirectoryName ( executablePath ) ;
48+ if ( string . IsNullOrEmpty ( buildOutputDir ) )
3649 {
37- if ( options is null )
38- {
39- logger . LogWarning ( "Native support disabled because Sentry has not been configured. " +
40- "You can do that through the editor: {0}" , SentryWindow . EditorMenuPath ) ;
41- return ;
42- }
43-
44- if ( ! options . IsValid ( ) )
45- {
46- logger . LogDebug ( "Native support disabled." ) ;
47- return ;
48- }
50+ logger . LogError ( "Failed to find build output directory based on the executable path '{0}'." +
51+ "\n Skipping adding crash-handler and uploading debug symbols." , executablePath ) ;
52+ return ;
53+ }
4954
50- if ( ! IsEnabledForPlatform ( target , options ) )
51- {
52- logger . LogDebug ( "Native support for the current platform is disabled in the configuration." ) ;
53- return ;
54- }
55+ UploadDebugSymbols ( logger , target , buildOutputDir , executableName , options , cliOptions , isMono ) ;
5556
56- logger . LogDebug ( "Adding native support." ) ;
57+ if ( ! IsEnabledForPlatform ( target , options ) )
58+ {
59+ logger . LogDebug ( "Skipping adding the crash-handler. Native support for the current platform is disabled in the configuration." ) ;
60+ return ;
61+ }
5762
63+ try
64+ {
5865 AddCrashHandler ( logger , target , buildOutputDir , executableName ) ;
5966 }
6067 catch ( Exception e )
6168 {
62- logger . LogError ( e , "Failed to add the Sentry native integration to the built application" ) ;
69+ logger . LogError ( e , "Failed to add the crash-handler to the built application. " ) ;
6370 throw new BuildFailedException ( "Sentry Native BuildPostProcess failed" ) ;
6471 }
65- finally
66- {
67- UploadDebugSymbols ( logger , target , buildOutputDir , executableName , options , cliOptions , isMono ) ;
68- }
6972 }
7073
7174 private static bool IsEnabledForPlatform ( BuildTarget target , SentryUnityOptions options ) => target switch
7275 {
76+ BuildTarget . StandaloneWindows => options . WindowsNativeSupportEnabled ,
7377 BuildTarget . StandaloneWindows64 => options . WindowsNativeSupportEnabled ,
7478 BuildTarget . StandaloneOSX => options . MacosNativeSupportEnabled ,
7579 BuildTarget . StandaloneLinux64 => options . LinuxNativeSupportEnabled ,
@@ -80,7 +84,9 @@ private static void AddCrashHandler(IDiagnosticLogger logger, BuildTarget target
8084 {
8185 switch ( target )
8286 {
87+ case BuildTarget . StandaloneWindows :
8388 case BuildTarget . StandaloneWindows64 :
89+ logger . LogDebug ( "Adding crashpad." ) ;
8490 CopyHandler ( logger , buildOutputDir , Path . Combine ( "Windows" , "Sentry" , "crashpad_handler.exe" ) ) ;
8591 CopyHandler ( logger , buildOutputDir , Path . Combine ( "Windows" , "Sentry" , "crashpad_wer.dll" ) ) ;
8692 break ;
@@ -197,7 +203,7 @@ private static void UploadDebugSymbols(IDiagnosticLogger logger, BuildTarget tar
197203 addPath ( Path . GetFullPath ( $ "Packages/{ SentryPackageInfo . GetName ( ) } /Plugins/macOS/Sentry/Sentry.dylib.dSYM") ) ;
198204
199205 if ( isMono )
200- {
206+ {
201207 addFilesMatching ( buildOutputDir , new [ ] { "*.pdb" } ) ;
202208
203209 // Unity stores the .pdb files in './Library/ScriptAssemblies/' and starting with 2020 in
0 commit comments