Skip to content

fix: Append builds for iOS respect CLI option changes #2146

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 5 commits into from
May 12, 2025

Conversation

bitsandfoxes
Copy link
Contributor

Fixes #1973

There are a couple of limitations with the PBXProject API, namely the ability to remove or overwrite an existing shell script in the build phase. When building via append this caused CLI options to not get copied over and respected by Xcode.

Instead of hardcoding arguments the shell script is now controlled by build settings that can be modified when building.

Screenshot 2025-05-07 at 16 32 48

@bitsandfoxes bitsandfoxes requested a review from bruno-garcia May 12, 2025 09:08
Comment on lines -141 to -152
if (cliOptions != null && cliOptions.IsValid(logger, EditorUserBuildSettings.development))
{
logger.LogInfo("Automatic symbol upload enabled. Adding script to build phase.");

SentryCli.CreateSentryProperties(pathToProject, cliOptions, options);
SentryCli.SetupSentryCli(pathToProject, RuntimePlatform.OSXEditor);
sentryXcodeProject.AddBuildPhaseSymbolUpload(cliOptions);
}
else if (options.Il2CppLineNumberSupportEnabled)
{
logger.LogWarning("The IL2CPP line number support requires the debug symbol upload to be enabled.");
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved this out of SetupSentry into SetupSentryCli.
SetupSentry is responsible for adding the framework and modifying the Xcode project to have the options and bridge set.
SetupSentryCli adds the executable, writes the .properties and adds the script to invoke the symbol upload.

Comment on lines +162 to +165
if (options.Il2CppLineNumberSupportEnabled && cliOptions.IsValid(logger, EditorUserBuildSettings.development))
{
logger.LogWarning("The IL2CPP line number support requires the debug symbol upload to be enabled.");
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We want to log configuration that is allowed but that we already know might not yield the expected result. I.e. the user has LineNumberSupport enabled but skips the symbol upload.

Comment on lines +188 to +203
_pbxProjectType.GetMethod("SetBuildProperty", new[] { typeof(string), typeof(string), typeof(string) })
.Invoke(_project, new object[] { _mainTargetGuid, IncludeSourcesPropertyName, sentryCliOptions.UploadSources ? "YES" : "NO" });

_pbxProjectType.GetMethod("SetBuildProperty", new[] { typeof(string), typeof(string), typeof(string) })
.Invoke(_project, new object[] { _mainTargetGuid, AllowFailurePropertyName, sentryCliOptions.IgnoreCliErrors ? "YES" : "NO" });

if (sentryCliOptions.IgnoreCliErrors)
_pbxProjectType.GetMethod("SetBuildProperty", new[] { typeof(string), typeof(string), typeof(string) })
.Invoke(_project, new object[] { _mainTargetGuid, PrintLogsPropertyName, sentryCliOptions.IgnoreCliErrors ? "NO" : "YES" });

if (MainTargetContainsSymbolUploadBuildPhase())
{
uploadDifArguments += " --allow-failure";
_logger?.LogInfo("Success. Build phase '{0}' was already added.", SymbolUploadPhaseName);
return;
}

var uploadScript = string.Format(_uploadScript,
SentryCli.SentryCliMacOS,
uploadDifArguments,
// Xcode parses the log-messages for 'error:', causing the phase to error with
// 'Command PhaseScriptExecution emitted errors but did not return a nonzero exit code to indicate failure'
// even with the '--allow-failure' arg. In that case, we're just logging to file instead.
sentryCliOptions.IgnoreCliErrors ? LogOnlyArg : LogAndPrintArg);
_logger?.LogDebug("Adding the upload script to {0}.", SymbolUploadPhaseName);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These properties can get overwritten via Unity's PBXProject. The shellscript itself cannot. Attempting to overwrite the script causes unexpected behaviour like adding it twice.

Instead, the properties get set (and overwritten) during the Unity export and read by the script during the Xcode build

@bitsandfoxes bitsandfoxes requested review from vaind and Flash0ver May 12, 2025 09:14
Co-authored-by: Ivan Dlugos <6349682+vaind@users.noreply.github.com>
@bitsandfoxes bitsandfoxes merged commit 21c9d56 into main May 12, 2025
6 checks passed
@bitsandfoxes bitsandfoxes deleted the fix/ios-cli-options-iteration branch May 12, 2025 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Xcode SymbolUpload BuildPhase run whether SentryCliOptions.UploadSymbols is true or not
2 participants