Skip to content

Commit

Permalink
fix: Added a file exists check for sentry-cli exec (#457)
Browse files Browse the repository at this point in the history
* file exists check for sentry-cli

* Format code

* updated CHANGELOG.md

* Update SentryOptions.asset

Co-authored-by: Sentry Github Bot <bot+github-bot@sentry.io>
  • Loading branch information
bitsandfoxes and getsentry-bot authored Dec 13, 2021
1 parent d2ed681 commit 1486e05
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixes

- Xcode exports no longer break with sentry-cli already added ([#457](https://github.com/getsentry/sentry-unity/pull/457))

## 0.8.0

### Features
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry.Unity.Editor.iOS/BuildPostProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static void OnPostProcessBuild(BuildTarget target, string pathToProject)
}

SentryCli.CreateSentryProperties(pathToProject, sentryCliOptions);
SentryCli.AddExecutableToXcodeProject(pathToProject);
SentryCli.AddExecutableToXcodeProject(pathToProject, logger);

sentryXcodeProject.AddBuildPhaseSymbolUpload(logger);
}
Expand Down
9 changes: 8 additions & 1 deletion src/Sentry.Unity.Editor/SentryCli.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using Sentry.Extensibility;
using Sentry.Unity.Integrations;
using UnityEngine;

Expand Down Expand Up @@ -74,7 +75,7 @@ internal static void SetExecutePermission(string? filePath = null, IApplication?
}
}

internal static void AddExecutableToXcodeProject(string projectPath)
internal static void AddExecutableToXcodeProject(string projectPath, IDiagnosticLogger? logger)
{
var executableSource = GetSentryCliPath(SentryCliMacOS);
var executableDestination = Path.Combine(projectPath, SentryCliMacOS);
Expand All @@ -84,6 +85,12 @@ internal static void AddExecutableToXcodeProject(string projectPath)
throw new DirectoryNotFoundException($"Xcode project directory not found at {executableDestination}");
}

if (File.Exists(executableDestination))
{
logger?.LogDebug("sentry-cli executable already found at {0}", executableDestination);
return;
}

File.Copy(executableSource, executableDestination);
SetExecutePermission(executableDestination);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@
<Folder Include="TestFiles\SymbolsUploadProject\GradleProject\unityLibrary\src\main" />
<Folder Include="TestFiles\SymbolsUploadProject\UnityProject\Temp\StagingArea\symbols" />
</ItemGroup>

<ItemGroup>
<Compile Include="../SharedClasses/*.cs">
<Link>%(RecursiveDir)/%(Filename)%(Extension)</Link>
</Compile>
</ItemGroup>

</Project>
21 changes: 19 additions & 2 deletions test/Sentry.Unity.Editor.Tests/SentryCliTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using NUnit.Framework;
using Sentry.Unity.Tests.SharedClasses;
using Sentry.Unity.Tests.Stubs;
using UnityEngine;

Expand Down Expand Up @@ -84,7 +85,7 @@ public void CreateSentryProperties_PropertyFileCreatedAndContainsSentryCliOption
[Test]
public void AddExecutableToXcodeProject_ProjectPathDoesNotExist_ThrowsDirectoryNotFoundException()
{
Assert.Throws<DirectoryNotFoundException>(() => SentryCli.AddExecutableToXcodeProject("non-existent-path"));
Assert.Throws<DirectoryNotFoundException>(() => SentryCli.AddExecutableToXcodeProject("non-existent-path", new UnityLogger(new SentryUnityOptions())));
}

[Test]
Expand All @@ -93,11 +94,27 @@ public void AddExecutableToXcodeProject_ProjectPathExists_CopiesSentryCliForMacO
var fakeXcodeProjectDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(fakeXcodeProjectDirectory);

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

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

Directory.Delete(fakeXcodeProjectDirectory, true);
}

[Test]
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);
}
}
}

0 comments on commit 1486e05

Please sign in to comment.