internal void SetupSymbolsUpload(string unityProjectPath, string gradleProjectPath)
        {
            var options = _getOptions();
            var logger  = options?.DiagnosticLogger ?? new UnityLogger(new SentryUnityOptions());

            if (_scriptingImplementation != ScriptingImplementation.IL2CPP)
            {
                logger.LogDebug("Automated symbols upload requires the IL2CPP scripting backend.");
                return;
            }

            var sentryCliOptions = _getSentryCliOptions();

            if (sentryCliOptions is null)
            {
                logger.LogWarning("Failed to load sentry-cli options - Skipping symbols upload.");
                return;
            }

            if (!sentryCliOptions.IsValid(logger, _isDevelopmentBuild))
            {
                return;
            }

            try
            {
                var symbolsPath = DebugSymbolUpload.GetSymbolsPath(
                    unityProjectPath,
                    gradleProjectPath,
                    EditorUserBuildSettings.exportAsGoogleAndroidProject);

                var sentryCliPath = SentryCli.SetupSentryCli();
                SentryCli.CreateSentryProperties(gradleProjectPath, sentryCliOptions);

                DebugSymbolUpload.AppendUploadToGradleFile(sentryCliPath, gradleProjectPath, symbolsPath);
            }
            catch (Exception e)
            {
                logger.LogError("Failed to add the automatic symbols upload to the gradle project", e);
            }
        }
예제 #2
0
        private static void UploadDebugSymbols(IDiagnosticLogger logger, string projectDir, string executableName)
        {
            var cliOptions = SentryCliOptions.LoadCliOptions();

            if (!cliOptions.IsValid(logger))
            {
                return;
            }

            logger.LogInfo("Uploading debugging information using sentry-cli in {0}", projectDir);

            var paths = "";
            Func <string, bool> addPath = (string name) =>
            {
                var fullPath = Path.Combine(projectDir, name);
                if (Directory.Exists(fullPath) || File.Exists(fullPath))
                {
                    paths += $" \"{name}\"";
                    logger.LogDebug($"Adding '{name}' to the debug-info upload");
                    return(true);
                }
                else
                {
                    logger.LogWarning($"Coudn't find '{name}' - debug symbol upload will be incomplete");
                    return(false);
                }
            };

            addPath(executableName);
            addPath("GameAssembly.dll");
            addPath("UnityPlayer.dll");
            addPath(Path.GetFileNameWithoutExtension(executableName) + "_BackUpThisFolder_ButDontShipItWithYourGame");
            addPath(Path.GetFileNameWithoutExtension(executableName) + "_Data/Plugins/x86_64/sentry.dll");

            // Note: using Path.GetFullPath as suggested by https://docs.unity3d.com/Manual/upm-assets.html
            addPath(Path.GetFullPath($"Packages/{SentryPackageInfo.GetName()}/Plugins/Windows/Sentry/sentry.pdb"));

            // Configure the process using the StartInfo properties.
            var process = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName               = SentryCli.SetupSentryCli(),
                    WorkingDirectory       = projectDir,
                    Arguments              = "upload-dif " + paths,
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    CreateNoWindow         = true
                }
            };

            process.StartInfo.EnvironmentVariables["SENTRY_ORG"]        = cliOptions.Organization;
            process.StartInfo.EnvironmentVariables["SENTRY_PROJECT"]    = cliOptions.Project;
            process.StartInfo.EnvironmentVariables["SENTRY_AUTH_TOKEN"] = cliOptions.Auth;
            process.OutputDataReceived += (sender, args) => logger.LogDebug($"sentry-cli: {args.Data.ToString()}");
            process.ErrorDataReceived  += (sender, args) => logger.LogError($"sentry-cli: {args.Data.ToString()}");
            process.Start();
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();
            process.WaitForExit();
        }