-
-
Notifications
You must be signed in to change notification settings - Fork 57
fix: Prevent appending uploadTask
more than once
#2300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ca19697
Append, Remove, Test
bitsandfoxes f45b2ef
.
bitsandfoxes 8037577
Format code
getsentry-bot b149120
Updated CHANGELOG.md
bitsandfoxes dd16024
Merge branch 'fix/android-upload-task' of https://github.com/getsentr…
bitsandfoxes 92828fe
Bump to setup-unity
bitsandfoxes 0bf7dbc
Bump to setup-unity
bitsandfoxes b2e5c6c
Fix Android debug symbol upload regex to handle newline after comment…
cursoragent d34d0db
Fix symbol upload task detection in Android gradle file
cursoragent 80e7272
Added sanity checks and issue prompt
bitsandfoxes f63e0fc
Updated CHANGELOG.md
bitsandfoxes 7e784eb
Updated CHANGELOG.md
bitsandfoxes d21434d
Non-greedy removal
bitsandfoxes 6f56182
Merge branch 'main' into fix/android-upload-task
bitsandfoxes 73437cc
Merge branch 'main' into fix/android-upload-task
bitsandfoxes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
|
@@ -30,12 +31,14 @@ internal class DebugSymbolUpload | |
private readonly List<string> _symbolUploadPaths; | ||
private readonly string _mappingFilePath; | ||
|
||
private const string SymbolUploadTaskStartComment = "// Autogenerated Sentry symbol upload task [start]"; | ||
private const string SymbolUploadTaskEndComment = "// Autogenerated Sentry symbol upload task [end]"; | ||
internal const string SymbolUploadTaskStartComment = "// Autogenerated Sentry symbol upload task [start]"; | ||
internal const string SymbolUploadTaskEndComment = "// Autogenerated Sentry symbol upload task [end]"; | ||
private const string SentryCliMarker = "SENTRY_CLI"; | ||
private const string UploadArgsMarker = "UPLOAD_ARGS"; | ||
private const string ProguardArgsMarker = "PROGUARD_ARGS"; | ||
|
||
private const string RaiseIssuePrompt = "\nPlease raise an issue over at https://github.com/getsentry/sentry-unity/issues"; | ||
|
||
private string SymbolUploadTaskFormat | ||
{ | ||
get | ||
|
@@ -102,14 +105,12 @@ public DebugSymbolUpload(IDiagnosticLogger logger, | |
|
||
public void AppendUploadToGradleFile(string sentryCliPath) | ||
{ | ||
RemoveUploadFromGradleFile(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This now happens outside and before calling this method. Added a sanity check before actually writing to disk. |
||
|
||
_logger.LogInfo("Appending debug symbols upload task to gradle file."); | ||
|
||
sentryCliPath = ConvertSlashes(sentryCliPath); | ||
if (!File.Exists(sentryCliPath)) | ||
{ | ||
throw new FileNotFoundException("Failed to find sentry-cli", sentryCliPath); | ||
throw new FileNotFoundException($"Failed to find sentry-cli{RaiseIssuePrompt}", sentryCliPath); | ||
} | ||
|
||
var uploadDifArguments = ", '--il2cpp-mapping'"; | ||
|
@@ -143,7 +144,7 @@ public void AppendUploadToGradleFile(string sentryCliPath) | |
} | ||
else | ||
{ | ||
throw new DirectoryNotFoundException($"Failed to find the symbols directory at {symbolUploadPath}"); | ||
throw new DirectoryNotFoundException($"Failed to find the symbols directory at {symbolUploadPath}{RaiseIssuePrompt}"); | ||
} | ||
} | ||
} | ||
|
@@ -162,17 +163,24 @@ public void AppendUploadToGradleFile(string sentryCliPath) | |
symbolUploadText = symbolUploadText.Replace(UploadArgsMarker, uploadDifArguments); | ||
symbolUploadText = symbolUploadText.Replace(ProguardArgsMarker, uploadProguardArguments); | ||
|
||
using var streamWriter = File.AppendText(_gradleScriptPath); | ||
streamWriter.WriteLine(SymbolUploadTaskStartComment); | ||
streamWriter.WriteLine(symbolUploadText); | ||
streamWriter.WriteLine(SymbolUploadTaskEndComment); | ||
var gradleBuildFile = LoadGradleScript(); | ||
if (gradleBuildFile.Contains(SymbolUploadTaskStartComment) || gradleBuildFile.Contains("task sentryUploadSymbols")) | ||
{ | ||
throw new InvalidOperationException($"Failed to create Debug Symbol Upload Task. Task already exists in gradle file. A clean build should resolve this.{RaiseIssuePrompt}"); | ||
} | ||
|
||
var stringBuilder = new StringBuilder(gradleBuildFile); | ||
stringBuilder.AppendLine(SymbolUploadTaskStartComment); | ||
stringBuilder.AppendLine(symbolUploadText); | ||
stringBuilder.AppendLine(SymbolUploadTaskEndComment); | ||
File.WriteAllText(_gradleScriptPath, stringBuilder.ToString()); | ||
} | ||
|
||
private string LoadGradleScript() | ||
{ | ||
if (!File.Exists(_gradleScriptPath)) | ||
{ | ||
throw new FileNotFoundException($"Failed to find the gradle config.", _gradleScriptPath); | ||
throw new FileNotFoundException($"Failed to find the gradle config.{RaiseIssuePrompt}", _gradleScriptPath); | ||
} | ||
|
||
return File.ReadAllText(_gradleScriptPath); | ||
|
@@ -182,15 +190,23 @@ public void RemoveUploadFromGradleFile() | |
{ | ||
_logger.LogDebug("Attempting to remove the previous upload task from the gradle project."); | ||
var gradleBuildFile = LoadGradleScript(); | ||
if (!gradleBuildFile.Contains("sentry.properties")) | ||
if (!gradleBuildFile.Contains(SymbolUploadTaskStartComment)) | ||
{ | ||
_logger.LogDebug("No previous upload task found."); | ||
return; | ||
} | ||
|
||
var regex = new Regex(Regex.Escape(SymbolUploadTaskStartComment) + ".*" + Regex.Escape(SymbolUploadTaskEndComment), RegexOptions.Singleline); | ||
var pattern = Regex.Escape(SymbolUploadTaskStartComment) + ".*?" + Regex.Escape(SymbolUploadTaskEndComment); | ||
var regex = new Regex(pattern, RegexOptions.Singleline); | ||
bitsandfoxes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
gradleBuildFile = regex.Replace(gradleBuildFile, ""); | ||
|
||
if (gradleBuildFile.Contains(SymbolUploadTaskStartComment) || | ||
gradleBuildFile.Contains("task sentryUploadSymbols") || | ||
gradleBuildFile.Contains(SymbolUploadTaskEndComment)) | ||
{ | ||
throw new InvalidOperationException($"Failed to remove Debug Symbol Upload Task from gradle file. A clean build should resolve this.{RaiseIssuePrompt}"); | ||
} | ||
|
||
using var streamWriter = File.CreateText(_gradleScriptPath); | ||
streamWriter.Write(gradleBuildFile); | ||
} | ||
|
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated but: To reduce logging noise when the SDK is disabled.