Skip to content

Commit 63695c5

Browse files
AlmostMattchkuang-g
authored andcommitted
Add an option to add "export LANG=..." to pod commands when execution via shell is enabled on ios
1 parent 6bd5645 commit 63695c5

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

source/AndroidResolver/src/CommandLine.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ public static Result RunViaShell(
541541
string toolPath, string arguments, string workingDirectory = null,
542542
Dictionary<string, string> envVars = null,
543543
IOHandler ioHandler = null, bool useShellExecution = false,
544-
bool stdoutRedirectionInShellMode = true) {
544+
bool stdoutRedirectionInShellMode = true, bool setLangInShellMode = false) {
545545
bool consoleConfigurationWarning = false;
546546
Encoding inputEncoding = Console.InputEncoding;
547547
Encoding outputEncoding = Console.OutputEncoding;
@@ -591,6 +591,7 @@ public static Result RunViaShell(
591591
string shellArgPrefix;
592592
string shellArgPostfix;
593593
string escapedToolPath = toolPath;
594+
string additionalCommands = "";
594595
if (UnityEngine.RuntimePlatform.WindowsEditor == UnityEngine.Application.platform) {
595596
shellCmd = "cmd.exe";
596597
shellArgPrefix = "/c \"";
@@ -600,9 +601,13 @@ public static Result RunViaShell(
600601
shellArgPrefix = "-l -c '";
601602
shellArgPostfix = "'";
602603
escapedToolPath = toolPath.Replace("'", "'\\''");
604+
if (UnityEngine.RuntimePlatform.OSXEditor == UnityEngine.Application.platform
605+
&& envVars != null && envVars.ContainsKey("LANG") && setLangInShellMode) {
606+
additionalCommands = String.Format("export {0}={1}; ", "LANG", envVars["LANG"]);
607+
}
603608
}
604-
arguments = String.Format("{0}\"{1}\" {2} 1> {3} 2> {4}{5}", shellArgPrefix,
605-
escapedToolPath, arguments, stdoutFileName,
609+
arguments = String.Format("{0}{1}\"{2}\" {3} 1> {4} 2> {5}{6}", shellArgPrefix,
610+
additionalCommands, escapedToolPath, arguments, stdoutFileName,
606611
stderrFileName, shellArgPostfix);
607612
toolPath = shellCmd;
608613
}

source/IOSResolver/src/IOSResolver.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,9 @@ protected override bool Read(string filename, Logger logger) {
462462
// Whether execution of the pod tool is performed via the shell.
463463
private const string PREFERENCE_POD_TOOL_EXECUTION_VIA_SHELL_ENABLED =
464464
PREFERENCE_NAMESPACE + "PodToolExecutionViaShellEnabled";
465+
// Whether environment variables should be set when execution is performed via the shell.
466+
private const string PREFERENCE_POD_TOOL_SHELL_EXECUTION_SET_LANG =
467+
PREFERENCE_NAMESPACE + "PodToolShellExecutionSetLang";
465468
// Whether to try to install Cocoapods tools when iOS is selected as the target platform.
466469
private const string PREFERENCE_AUTO_POD_TOOL_INSTALL_IN_EDITOR =
467470
PREFERENCE_NAMESPACE + "AutoPodToolInstallInEditor";
@@ -955,10 +958,19 @@ private static void SetEnablePollTargetSdk(bool enable) {
955958
/// </summary>
956959
public static bool PodToolExecutionViaShellEnabled {
957960
get { return settings.GetBool(PREFERENCE_POD_TOOL_EXECUTION_VIA_SHELL_ENABLED,
958-
defaultValue: false); }
961+
defaultValue: true); }
959962
set { settings.SetBool(PREFERENCE_POD_TOOL_EXECUTION_VIA_SHELL_ENABLED, value); }
960963
}
961964

965+
/// <summary>
966+
/// Enable / disable setting of environment variables when executing pod tool via the shell.
967+
/// </summary>
968+
public static bool PodToolShellExecutionSetLang {
969+
get { return settings.GetBool(PREFERENCE_POD_TOOL_SHELL_EXECUTION_SET_LANG,
970+
defaultValue: true); }
971+
set { settings.SetBool(PREFERENCE_POD_TOOL_SHELL_EXECUTION_SET_LANG, value); }
972+
}
973+
962974
/// <summary>
963975
/// Enable automated pod tool installation in the editor. This is only performed when the
964976
/// editor isn't launched in batch mode.
@@ -2383,7 +2395,8 @@ private static void RunCommandsAsync(CommandItem[] commands,
23832395
Log(command.ToString(), verbose: true);
23842396
var result = CommandLine.RunViaShell(
23852397
command.Command, command.Arguments, workingDirectory: command.WorkingDirectory,
2386-
envVars: envVars, useShellExecution: PodToolExecutionViaShellEnabled);
2398+
envVars: envVars, useShellExecution: PodToolExecutionViaShellEnabled,
2399+
setLangInShellMode: PodToolShellExecutionSetLang);
23872400
LogCommandLineResult(command.ToString(), result);
23882401
index = completionDelegate(index, commands, result, null);
23892402
}

source/IOSResolver/src/IOSResolverSettingsDialog.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class IOSResolverSettingsDialog : EditorWindow
3333
private class Settings {
3434
internal bool podfileGenerationEnabled;
3535
internal bool podToolExecutionViaShellEnabled;
36+
internal bool podToolShellExecutionSetLang;
3637
internal bool autoPodToolInstallInEditorEnabled;
3738
internal bool verboseLoggingEnabled;
3839
internal int cocoapodsIntegrationMenuIndex;
@@ -49,6 +50,7 @@ private class Settings {
4950
internal Settings() {
5051
podfileGenerationEnabled = IOSResolver.PodfileGenerationEnabled;
5152
podToolExecutionViaShellEnabled = IOSResolver.PodToolExecutionViaShellEnabled;
53+
podToolShellExecutionSetLang = IOSResolver.PodToolShellExecutionSetLang;
5254
autoPodToolInstallInEditorEnabled = IOSResolver.AutoPodToolInstallInEditorEnabled;
5355
verboseLoggingEnabled = IOSResolver.VerboseLoggingEnabled;
5456
cocoapodsIntegrationMenuIndex = FindIndexFromCocoapodsIntegrationMethod(
@@ -67,6 +69,7 @@ internal Settings() {
6769
internal void Save() {
6870
IOSResolver.PodfileGenerationEnabled = podfileGenerationEnabled;
6971
IOSResolver.PodToolExecutionViaShellEnabled = podToolExecutionViaShellEnabled;
72+
IOSResolver.PodToolShellExecutionSetLang = podToolShellExecutionSetLang;
7073
IOSResolver.AutoPodToolInstallInEditorEnabled = autoPodToolInstallInEditorEnabled;
7174
IOSResolver.VerboseLoggingEnabled = verboseLoggingEnabled;
7275
IOSResolver.CocoapodsIntegrationMethodPref =
@@ -107,7 +110,7 @@ private static int FindIndexFromCocoapodsIntegrationMethod(
107110
}
108111

109112
public void Initialize() {
110-
minSize = new Vector2(400, 700);
113+
minSize = new Vector2(400, 715);
111114
position = new Rect(UnityEngine.Screen.width / 3, UnityEngine.Screen.height / 3,
112115
minSize.x, minSize.y);
113116
}
@@ -168,9 +171,16 @@ public void OnGUI() {
168171
settings.podToolExecutionViaShellEnabled =
169172
EditorGUILayout.Toggle(settings.podToolExecutionViaShellEnabled);
170173
GUILayout.EndHorizontal();
174+
GUILayout.Label("Shell execution is useful when configuration in the shell " +
175+
"environment (e.g ~/.profile) is required to execute Cocoapods tools.");
176+
171177
if (settings.podToolExecutionViaShellEnabled) {
172-
GUILayout.Label("Shell execution is useful when configuration in the shell " +
173-
"environment (e.g ~/.profile) is required to execute Cocoapods tools.");
178+
GUILayout.BeginHorizontal();
179+
GUILayout.Label("Set LANG When Using Shell to Execute Cocoapod Tool", EditorStyles.boldLabel);
180+
settings.podToolShellExecutionSetLang =
181+
EditorGUILayout.Toggle(settings.podToolShellExecutionSetLang);
182+
GUILayout.EndHorizontal();
183+
GUILayout.Label("Useful for versions of cocoapods that depend on the value of LANG.");
174184
}
175185

176186
GUILayout.BeginHorizontal();
@@ -280,6 +290,9 @@ public void OnGUI() {
280290
new KeyValuePair<string, string>(
281291
"podToolExecutionViaShellEnabled",
282292
IOSResolver.PodToolExecutionViaShellEnabled.ToString()),
293+
new KeyValuePair<string, string>(
294+
"podToolShellExecutionSetLang",
295+
IOSResolver.PodToolShellExecutionSetLang.ToString()),
283296
new KeyValuePair<string, string>(
284297
"autoPodToolInstallInEditorEnabled",
285298
IOSResolver.AutoPodToolInstallInEditorEnabled.ToString()),

0 commit comments

Comments
 (0)