-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix for legacy perf sdk versions (#863)
- Loading branch information
1 parent
6342793
commit 79aa0bc
Showing
3 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
Bugsnag/Assets/Bugsnag/Editor/BugsnagEditPerformanceAssemblyDefinition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Bugsnag/Assets/Bugsnag/Editor/BugsnagEditPerformanceAssemblyDefinition.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters