Exemplo n.º 1
0
        public void GetSentryPlatformName_RecognizedPlatform_SetsSentryCliName(RuntimePlatform platform, string expectedName)
        {
            var application = new TestApplication(platform: platform);

            var actualName = SentryCli.GetSentryCliPlatformName(application);

            Assert.AreEqual(expectedName, actualName);
        }
Exemplo n.º 2
0
        public void SetExecutePermission_FileDoesNotExist_ThrowsUnauthorizedAccessException()
        {
            if (Application.platform == RuntimePlatform.WindowsEditor)
            {
                Assert.Inconclusive("Skipping chmod on Windows.");
                return;
            }

            Assert.Throws <UnauthorizedAccessException>(() => SentryCli.SetExecutePermission("non-existent-file"));
        }
Exemplo n.º 3
0
        public void GetSentryCliPath_ValidFileName_ReturnsPath()
        {
            var sentryCliPlatformName = SentryCli.GetSentryCliPlatformName(new TestApplication(platform: Application.platform));
            var expectedPath          = Path.GetFullPath(
                Path.Combine("Packages", SentryPackageInfo.GetName(), "Editor", "sentry-cli", sentryCliPlatformName));

            var actualPath = SentryCli.GetSentryCliPath(sentryCliPlatformName);

            Assert.AreEqual(expectedPath, actualPath);
        }
Exemplo n.º 4
0
        public void AddExecutableToXcodeProject_ProjectPathExists_CopiesSentryCliForMacOS()
        {
            var fakeXcodeProjectDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

            Directory.CreateDirectory(fakeXcodeProjectDirectory);

            SentryCli.AddExecutableToXcodeProject(fakeXcodeProjectDirectory, new UnityLogger(new SentryUnityOptions()));

            Assert.IsTrue(File.Exists(Path.Combine(fakeXcodeProjectDirectory, SentryCli.SentryCliMacOS)));

            Directory.Delete(fakeXcodeProjectDirectory, true);
        }
Exemplo n.º 5
0
        public static void OnPostProcessBuild(BuildTarget target, string pathToProject)
        {
            if (target != BuildTarget.iOS)
            {
                return;
            }

            var options = ScriptableSentryUnityOptions.LoadSentryUnityOptions(BuildPipeline.isBuildingPlayer);
            var logger  = options?.DiagnosticLogger ?? new UnityLogger(new SentryUnityOptions());

            try
            {
                // Unity doesn't allow an appending builds when switching iOS SDK versions and this will make sure we always copy the correct version of the Sentry.framework
                var frameworkDirectory = PlayerSettings.iOS.sdkVersion == iOSSdkVersion.DeviceSDK ? "Device" : "Simulator";
                var frameworkPath      = Path.GetFullPath(Path.Combine("Packages", SentryPackageInfo.GetName(), "Plugins", "iOS", frameworkDirectory, "Sentry.framework"));
                CopyFramework(frameworkPath, Path.Combine(pathToProject, "Frameworks", "Sentry.framework"), options?.DiagnosticLogger);

                var nativeBridgePath = Path.GetFullPath(Path.Combine("Packages", SentryPackageInfo.GetName(), "Plugins", "iOS", "SentryNativeBridge.m"));
                CopyFile(nativeBridgePath, Path.Combine(pathToProject, "Libraries", SentryPackageInfo.GetName(), "SentryNativeBridge.m"), options?.DiagnosticLogger);

                using var sentryXcodeProject = SentryXcodeProject.Open(pathToProject);
                sentryXcodeProject.AddSentryFramework();
                sentryXcodeProject.AddSentryNativeBridge();

                if (options?.IsValid() is not true)
                {
                    logger.LogWarning("Failed to validate Sentry Options. Native support disabled.");
                    return;
                }

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

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

                var sentryCliOptions = SentryCliOptions.LoadCliOptions();
                if (sentryCliOptions.IsValid(logger))
                {
                    SentryCli.CreateSentryProperties(pathToProject, sentryCliOptions);
                    SentryCli.AddExecutableToXcodeProject(pathToProject, logger);
                    sentryXcodeProject.AddBuildPhaseSymbolUpload(logger);
                }
            }
            catch (Exception e)
            {
                logger.LogError("Failed to add the Sentry framework to the generated Xcode project", e);
            }
        }
Exemplo n.º 6
0
        public void AddExecutableToXcodeProject_ExecutableAlreadyExists_LogsAndReturns()
        {
            var logger = new TestLogger();
            var fakeXcodeProjectDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

            Directory.CreateDirectory(fakeXcodeProjectDirectory);

            SentryCli.AddExecutableToXcodeProject(fakeXcodeProjectDirectory, logger);
            SentryCli.AddExecutableToXcodeProject(fakeXcodeProjectDirectory, logger);

            Assert.IsTrue(File.Exists(Path.Combine(fakeXcodeProjectDirectory, SentryCli.SentryCliMacOS)));
            Assert.AreEqual(1, logger.Logs.Count);

            Directory.Delete(fakeXcodeProjectDirectory, true);
        }
        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);
            }
        }
Exemplo n.º 8
0
        public void CreateSentryProperties_PropertyFileCreatedAndContainsSentryCliOptions()
        {
            var propertiesDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

            Directory.CreateDirectory(propertiesDirectory);

            var sentryCliTestOptions = ScriptableObject.CreateInstance <SentryCliOptions>();

            sentryCliTestOptions.Auth         = Guid.NewGuid().ToString();
            sentryCliTestOptions.Organization = Guid.NewGuid().ToString();
            sentryCliTestOptions.Project      = Guid.NewGuid().ToString();

            SentryCli.CreateSentryProperties(propertiesDirectory, sentryCliTestOptions);

            var properties = File.ReadAllText(Path.Combine(propertiesDirectory, "sentry.properties"));

            StringAssert.Contains(sentryCliTestOptions.Auth, properties);
            StringAssert.Contains(sentryCliTestOptions.Organization, properties);
            StringAssert.Contains(sentryCliTestOptions.Project, properties);

            Directory.Delete(propertiesDirectory, true);
        }
Exemplo n.º 9
0
 public void AddExecutableToXcodeProject_ProjectPathDoesNotExist_ThrowsDirectoryNotFoundException()
 {
     Assert.Throws <DirectoryNotFoundException>(() => SentryCli.AddExecutableToXcodeProject("non-existent-path", new UnityLogger(new SentryUnityOptions())));
 }
Exemplo n.º 10
0
 public void GetSentryCliPath_InvalidFileName_ThrowsFileNotFoundException()
 {
     Assert.Throws <FileNotFoundException>(() => SentryCli.GetSentryCliPath("InvalidName"));
 }
Exemplo n.º 11
0
        public void GetSentryCliPlatformName_UnrecognizedPlatform_ThrowsInvalidOperationException()
        {
            var application = new TestApplication(platform: RuntimePlatform.CloudRendering);

            Assert.Throws <InvalidOperationException>(() => SentryCli.GetSentryCliPlatformName(application));
        }
Exemplo n.º 12
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();
        }