Skip to content

Commit 731b965

Browse files
authored
[xaprepare] Fix for newer homebrew on macOS (#5302)
Context: Homebrew/brew#9033 Context: Homebrew/brew@5adb76a Homebrew as of Homebrew/brew@5adb76a5 no longer supports the use of `brew ls` with the `--versions` and `-1` parameters: $ brew ls --versions -1 automake Error: Invalid usage: Options --versions and -1 are mutually exclusive. This change in Homebrew breaks `xaprepare`, as `xaprepare` would use `brew ls --versions -1` to determine if a program was installed: $ make prepare … Error: Invalid usage: Options --versions and -1 are mutually exclusive. [MISSING] Checking automake Usage: brew list, ls [options] [formula|cask] The intention for our use of `xaprepare` was so that *if* a Homebrew package had multiple versions installed, the use of `brew ls --versions -1` would cause *only* the latest version to be printed, not every version. As `brew ls --versions -1` is no longer supported, update `xaprepare` so that `brew ls --versions` output is parsed, preserving only the first line of output. This avoids the invalid usage error, while preserving our desired semantics incase multiple versions are present.
1 parent 2dab2bc commit 731b965

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

build-tools/xaprepare/xaprepare/Application/HomebrewProgram.MacOS.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ namespace Xamarin.Android.Prepare
66
{
77
class HomebrewProgram : Program
88
{
9+
static readonly char[] lineSplit = new [] { '\n' };
10+
911
string cachedVersionOutput;
1012
bool brewNeedsSudo = false;
1113
bool multipleVersionsPickle = false;
@@ -204,13 +206,21 @@ protected override async Task AfterDetect (bool installed)
204206

205207
string GetPackageVersion ()
206208
{
207-
return Utilities.GetStringFromStdout (
209+
string output = Utilities.GetStringFromStdout (
208210
Context.Instance.Tools.BrewPath,
209211
false, // throwOnErrors
210212
true, // trimTrailingWhitespace
211213
true, // quietErrors
212-
"ls", "--versions", "-1", Name
214+
"ls", "--versions", Name
213215
);
216+
217+
if (String.IsNullOrEmpty (output))
218+
return output;
219+
220+
string[] lines = output.Split (lineSplit, StringSplitOptions.RemoveEmptyEntries);
221+
if (lines.Length == 0)
222+
return String.Empty;
223+
return lines [0];
214224
}
215225
}
216226
}

0 commit comments

Comments
 (0)