From 79aa0bc7a4893a2445fbcbc2ad2dde01672e630a Mon Sep 17 00:00:00 2001 From: Richard Elms Date: Sun, 8 Dec 2024 13:45:53 +0100 Subject: [PATCH] fix for legacy perf sdk versions (#863) --- ...ugsnagEditPerformanceAssemblyDefinition.cs | 81 +++++++++++++++++++ ...gEditPerformanceAssemblyDefinition.cs.meta | 11 +++ CHANGELOG.md | 6 ++ 3 files changed, 98 insertions(+) create mode 100644 Bugsnag/Assets/Bugsnag/Editor/BugsnagEditPerformanceAssemblyDefinition.cs create mode 100644 Bugsnag/Assets/Bugsnag/Editor/BugsnagEditPerformanceAssemblyDefinition.cs.meta diff --git a/Bugsnag/Assets/Bugsnag/Editor/BugsnagEditPerformanceAssemblyDefinition.cs b/Bugsnag/Assets/Bugsnag/Editor/BugsnagEditPerformanceAssemblyDefinition.cs new file mode 100644 index 00000000..9cbfa720 --- /dev/null +++ b/Bugsnag/Assets/Bugsnag/Editor/BugsnagEditPerformanceAssemblyDefinition.cs @@ -0,0 +1,81 @@ + +// This script fixes an issue in versions 1.7.0 and below of the BugSnag Performance package where the +// BugsnagPerformance.asmdef file was not correctly configured to reference the BugsnagUnity package +// (and therefore cannot access the version of the BugsnagUnityWebRequest class packaged inside it). +// This script adds the reference to the BugSnag Performance package assembly definition, if not +// present, for backwards compatibility with older versions (<=1.7.0). + +using System.IO; +using UnityEditor; +using UnityEngine; + +namespace BugsnagUnity.Editor +{ + [InitializeOnLoad] + public class BugsnagEditPerformanceAssemblyDefinition + { + static BugsnagEditPerformanceAssemblyDefinition() + { + FixBugsnagPerformanceAsmdef(); + } + + public static void FixBugsnagPerformanceAsmdef() + { + string projectRoot = Directory.GetParent(Application.dataPath).FullName; + string packageCachePath = Path.Combine(projectRoot, "Library", "PackageCache"); + + if (!Directory.Exists(packageCachePath)) + { + // Package cache not found, nothing to do + return; + } + + string[] matchingDirs = Directory.GetDirectories(packageCachePath, "com.bugsnag.performance.unity*"); + if (matchingDirs.Length == 0) + { + // Bugsnag Performance package not found, nothing to do + return; + } + + string bugsnagPackageDir = matchingDirs[0]; + string asmdefPath = Path.Combine(bugsnagPackageDir, "Runtime", "Scripts", "BugsnagPerformance.asmdef"); + + if (!File.Exists(asmdefPath)) + { + // BugsnagPerformance.asmdef not found, nothing to do + return; + } + + string originalJson = File.ReadAllText(asmdefPath).Trim(); + string strippedJson = originalJson.Replace(" ", "").Replace("\n", "").Replace("\r", ""); + + // Check if the "references":["BugsnagUnity"] entry already exists + if (strippedJson.Contains("\"references\":[\"BugsnagUnity\"]")) + { + // BugsnagUnity reference already present, nothing to do + return; + } + + string expandedJson = @"{ + ""name"": ""BugsnagPerformance"", + ""rootNamespace"": """", + ""references"": [ + ""BugsnagUnity"" + ], + ""includePlatforms"": [], + ""excludePlatforms"": [], + ""allowUnsafeCode"": false, + ""overrideReferences"": false, + ""precompiledReferences"": [], + ""autoReferenced"": true, + ""defineConstraints"": [], + ""versionDefines"": [], + ""noEngineReferences"": false +}"; + + File.WriteAllText(asmdefPath, expandedJson); + Debug.Log("Updated BugsnagPerformance.asmdef with a reference to BugsnagUnity. If you continue to see errors related to the BugsnagUnityWebRequest class after restarting Unity, please update your BugsnagPerformance package or add a reference in the .asmdef file manually."); + AssetDatabase.Refresh(); + } + } +} \ No newline at end of file diff --git a/Bugsnag/Assets/Bugsnag/Editor/BugsnagEditPerformanceAssemblyDefinition.cs.meta b/Bugsnag/Assets/Bugsnag/Editor/BugsnagEditPerformanceAssemblyDefinition.cs.meta new file mode 100644 index 00000000..3681270a --- /dev/null +++ b/Bugsnag/Assets/Bugsnag/Editor/BugsnagEditPerformanceAssemblyDefinition.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 626d8d7541b544aa1aefe6dc6eb22f99 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c5f6c53..9c0714dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## TBD + +### Bug Fixes + +- Fix a compiler error that occurs when using v8.3.0 of this SDK in conjunction with v1.7.0 and below of the BugSnag Unity Performance SDK. [#863](https://github.com/bugsnag/bugsnag-unity/pull/863) + ## 8.3.0 (2024-12-02) ### Enhancements