Skip to content

Commit

Permalink
fix for legacy perf sdk versions (#863)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardelms authored Dec 8, 2024
1 parent 6342793 commit 79aa0bc
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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();
}
}
}

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

6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 79aa0bc

Please sign in to comment.