Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions Editor/BacktraceXcodePostBuild.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#if UNITY_IOS
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
using UnityEditor.iOS.Xcode.Extensions;
using UnityEngine;

namespace Backtrace.Unity.Editor.iOS
{
/// <summary>
/// Links Backtrace.xcframework and CrashReporter.xcframework
/// embeds, signs Backtrace and sets Swift/iOS settings.
/// </summary>
public static class BacktraceXcodePostBuild
{
// Runs late after post-processors
private const int PostBuildOrder = 500;

[PostProcessBuild(PostBuildOrder)]
public static void OnPostProcessBuild(BuildTarget buildTarget, string buildPath)
{
if (buildTarget != BuildTarget.iOS) {
return;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad formatting


var projectPath = PBXProject.GetPBXProjectPath(buildPath);
var project = new PBXProject();
project.ReadFromFile(projectPath);

#if UNITY_2019_3_OR_NEWER
string appTargetGuid = project.GetUnityMainTargetGuid();
string unityFrameworkTargetGuid = project.GetUnityFrameworkTargetGuid();
#else
string appTargetGuid = project.TargetGuidByName("Unity-iPhone");
string unityFrameworkTargetGuid = appTargetGuid;
#endif
Comment on lines +32 to +38
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit:

what do you think about?

Suggested change
#if UNITY_2019_3_OR_NEWER
string appTargetGuid = project.GetUnityMainTargetGuid();
string unityFrameworkTargetGuid = project.GetUnityFrameworkTargetGuid();
#else
string appTargetGuid = project.TargetGuidByName("Unity-iPhone");
string unityFrameworkTargetGuid = appTargetGuid;
#endif
string appTargetGuid =
#if UNITY_2019_3_OR_NEWER
project.GetUnityMainTargetGuid();
#else
project.TargetGuidByName("Unity-iPhone");
#endif
string unityFrameworkTargetGuid =
#if UNITY_2019_3_OR_NEWER
project.GetUnityFrameworkTargetGuid();
#else
appTargetGuid;
#endif

if (string.IsNullOrEmpty(appTargetGuid) || string.IsNullOrEmpty(unityFrameworkTargetGuid))
{
Debug.LogError("[Backtrace] iOS post-build: could not resolve Xcode targets.");
return;
}

// Locate exported xcframeworks
string FindXCFramework(string folderName)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move it to class instance? It's not popular in C# to have a function declaration inside another function. its also inconsistent with the rest of the library code

{
var matches = Directory.GetDirectories(buildPath, folderName, SearchOption.AllDirectories);
return matches.FirstOrDefault();
}

var backtraceXCPath = FindXCFramework("Backtrace.xcframework");
var crashReporterXCPath = FindXCFramework("CrashReporter.xcframework");

if (string.IsNullOrEmpty(backtraceXCPath))
{
Debug.LogError($"[Backtrace] Could not locate Backtrace.xcframework under: {buildPath}");
return;
}
if (string.IsNullOrEmpty(crashReporterXCPath))
{
Debug.LogError($"[Backtrace] Could not locate CrashReporter.xcframework under: {buildPath}");
return;
}
Comment on lines +52 to +64
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small nit:

Suggested change
var backtraceXCPath = FindXCFramework("Backtrace.xcframework");
var crashReporterXCPath = FindXCFramework("CrashReporter.xcframework");
if (string.IsNullOrEmpty(backtraceXCPath))
{
Debug.LogError($"[Backtrace] Could not locate Backtrace.xcframework under: {buildPath}");
return;
}
if (string.IsNullOrEmpty(crashReporterXCPath))
{
Debug.LogError($"[Backtrace] Could not locate CrashReporter.xcframework under: {buildPath}");
return;
}
var backtraceXCPath = FindXCFramework("Backtrace.xcframework");
if (string.IsNullOrEmpty(backtraceXCPath))
{
Debug.LogError($"[Backtrace] Could not locate Backtrace.xcframework under: {buildPath}");
return;
}
var crashReporterXCPath = FindXCFramework("CrashReporter.xcframework");
if (string.IsNullOrEmpty(crashReporterXCPath))
{
Debug.LogError($"[Backtrace] Could not locate CrashReporter.xcframework under: {buildPath}");
return;
}


// Project-relative paths
string relBacktraceXC = ToProjectRelative(buildPath, backtraceXCPath);
string relCrashReporterXC = ToProjectRelative(buildPath, crashReporterXCPath);

// Add file references
string backtraceFileGuid = project.FindFileGuidByProjectPath(relBacktraceXC);
if (string.IsNullOrEmpty(backtraceFileGuid)) {
backtraceFileGuid = project.AddFile(relBacktraceXC, relBacktraceXC, PBXSourceTree.Source);
}

string crashReporterFileGuid = project.FindFileGuidByProjectPath(relCrashReporterXC);
if (string.IsNullOrEmpty(crashReporterFileGuid)) {
crashReporterFileGuid = project.AddFile(relCrashReporterXC, relCrashReporterXC, PBXSourceTree.Source);
}
Comment on lines +68 to +79
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small nit:

Suggested change
string relCrashReporterXC = ToProjectRelative(buildPath, crashReporterXCPath);
// Add file references
string backtraceFileGuid = project.FindFileGuidByProjectPath(relBacktraceXC);
if (string.IsNullOrEmpty(backtraceFileGuid)) {
backtraceFileGuid = project.AddFile(relBacktraceXC, relBacktraceXC, PBXSourceTree.Source);
}
string crashReporterFileGuid = project.FindFileGuidByProjectPath(relCrashReporterXC);
if (string.IsNullOrEmpty(crashReporterFileGuid)) {
crashReporterFileGuid = project.AddFile(relCrashReporterXC, relCrashReporterXC, PBXSourceTree.Source);
}
// Add file references
var backtraceFileGuid = project.FindFileGuidByProjectPath(relBacktraceXC);
if (string.IsNullOrEmpty(backtraceFileGuid)) {
backtraceFileGuid = project.AddFile(relBacktraceXC, relBacktraceXC, PBXSourceTree.Source);
}
var relCrashReporterXC = ToProjectRelative(buildPath, crashReporterXCPath);
var crashReporterFileGuid = project.FindFileGuidByProjectPath(relCrashReporterXC);
if (string.IsNullOrEmpty(crashReporterFileGuid)) {
crashReporterFileGuid = project.AddFile(relCrashReporterXC, relCrashReporterXC, PBXSourceTree.Source);
}


// Linking
project.AddFileToBuild(unityFrameworkTargetGuid, backtraceFileGuid);
project.AddFileToBuild(unityFrameworkTargetGuid, crashReporterFileGuid);

// Embedding
PBXProjectExtensions.AddFileToEmbedFrameworks(project, appTargetGuid, backtraceFileGuid);
AddBuildPropertyUnique(project, appTargetGuid, "LD_RUNPATH_SEARCH_PATHS", "$(inherited)");
AddBuildPropertyUnique(project, appTargetGuid, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/Frameworks");

// Swift std
project.SetBuildProperty(appTargetGuid, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "YES");

// Obj-C Linker Flag
AddBuildPropertyUnique(project, unityFrameworkTargetGuid, "OTHER_LDFLAGS", "-ObjC");

project.WriteToFile(projectPath);
Debug.Log("[Backtrace] iOS post-build: frameworks linked/embedded. Swift stdlib enabled.");
}

private static string ToProjectRelative(string buildPath, string absolutePath)
{
var rel = absolutePath.Replace('\\', '/');
var root = (buildPath + "/").Replace('\\', '/');
return rel.StartsWith(root) ? rel.Substring(root.Length) : rel;
}

private static void AddBuildPropertyUnique(PBXProject proj, string targetGuid, string key, string value)
{
var current = proj.GetBuildPropertyForAnyConfig(targetGuid, key);
if (current == null || !current.Split(' ').Contains(value))
{
proj.AddBuildProperty(targetGuid, key, value);
}
}
}
}
#endif
11 changes: 11 additions & 0 deletions Editor/BacktraceXcodePostBuild.cs.meta

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

8 changes: 0 additions & 8 deletions Mac/Backtrace-Unity-Mac-bundle.bundle/Contents.meta

This file was deleted.

This file was deleted.

8 changes: 0 additions & 8 deletions Mac/Backtrace-Unity-Mac-bundle.bundle/Contents/MacOS.meta

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

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

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>24B83</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleIdentifier</key>
<string>Backtrace.io.BacktraceResources</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>BacktraceResources</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>2.1.0</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>24B75</string>
<key>DTPlatformName</key>
<string>macosx</string>
<key>DTPlatformVersion</key>
<string>15.1</string>
<key>DTSDKBuild</key>
<string>24B75</string>
<key>DTSDKName</key>
<string>macosx15.1</string>
<key>DTXcode</key>
<string>1610</string>
<key>DTXcodeBuild</key>
<string>16B40</string>
<key>LSMinimumSystemVersion</key>
<string>12.4</string>
</dict>
</plist>
Binary file not shown.
Binary file not shown.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,56 @@
<plist version="1.0">
<dict>
<key>files</key>
<dict/>
<dict>
<key>Resources/Model.momd/Model.mom</key>
<data>
oY715RjH8RLsZ62wNkTu/4CAgzE=
</data>
<key>Resources/Model.momd/VersionInfo.plist</key>
<data>
VDsrXY+tpRztPEAvUKkp1SRzKWI=
</data>
<key>Resources/PrivacyInfo.xcprivacy</key>
<data>
fZU0MKIt8Fnd2qnYWmCR+ZWPjK0=
</data>
</dict>
<key>files2</key>
<dict/>
<dict>
<key>Resources/Model.momd/Model.mom</key>
<dict>
<key>hash</key>
<data>
oY715RjH8RLsZ62wNkTu/4CAgzE=
</data>
<key>hash2</key>
<data>
sl5S//BxBIQpdRCEXAyH5OINmZhBDvENxjX0kOJ6pj4=
</data>
</dict>
<key>Resources/Model.momd/VersionInfo.plist</key>
<dict>
<key>hash</key>
<data>
VDsrXY+tpRztPEAvUKkp1SRzKWI=
</data>
<key>hash2</key>
<data>
r43Lc4T3JNmt6+aF/bm0VbyDiy1gmLEa4tQkcGuIyTw=
</data>
</dict>
<key>Resources/PrivacyInfo.xcprivacy</key>
<dict>
<key>hash</key>
<data>
fZU0MKIt8Fnd2qnYWmCR+ZWPjK0=
</data>
<key>hash2</key>
<data>
W4GYx3E/DJBKJ4aViszvqnv3rCzspeT5hG4vJvQa8hk=
</data>
</dict>
</dict>
<key>rules</key>
<dict>
<key>^Resources/</key>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>24B83</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>Backtrace</string>
<key>CFBundleExecutable</key>
<string>Backtrace</string>
<key>CFBundleIdentifier</key>
<string>Backtrace.io.Backtrace</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Backtrace</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.1.0</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>24B75</string>
<key>DTPlatformName</key>
<string>macosx</string>
<key>DTPlatformVersion</key>
<string>15.1</string>
<key>DTSDKBuild</key>
<string>24B75</string>
<key>DTSDKName</key>
<string>macosx15.1</string>
<key>DTXcode</key>
<string>1610</string>
<key>DTXcodeBuild</key>
<string>16B40</string>
<key>LSMinimumSystemVersion</key>
<string>12.4</string>
</dict>
</plist>
Loading
Loading