Skip to content

Commit

Permalink
[Linux] Properly parse single-digit Ubuntu version (#5463)
Browse files Browse the repository at this point in the history
Fixes: #4929

Some releases of Ubuntu use only a single digit for their version:

	   OS type: Linux
	   OS name: Linux Mint
	OS release: 20
	   OS bits: x86_64
	 CPU count: 2

This would cause `xaprepare` to error out on these platforms:

	$ make prepare
	…
	  Error: Unable to parse string '20' as a valid Ubuntu release version

	Failed to initialize operating system support
	System.InvalidOperationException: Failed to initialize operating system support
	  at Xamarin.Android.Prepare.OS.Init () [0x00024] in /home/zola/Desktop/xamarin-android/build-tools/xaprepare/xaprepare/OperatingSystems/OS.cs:243 
	  at Xamarin.Android.Prepare.Context.Init (System.String scenarioName) [0x0022d] in /home/zola/Desktop/xamarin-android/build-tools/xaprepare/xaprepare/Application/Context.cs:766 
	  at Xamarin.Android.Prepare.App.Run (System.String[] args) [0x00793] in /home/zola/Desktop/xamarin-android/build-tools/xaprepare/xaprepare/Main.cs:153

	make: *** [Makefile:204: prepare] Error 1

If `Version.TryParse()` fails to parse `OS release`, add a fallback
which uses `Int32.TryParse()`.  This should allow `make prepare` to
run on these Linux platforms.

Additionally, don't hardcode `Ubuntu` into the error message, use the
actual (derived) distro name instead.
  • Loading branch information
grendello authored Jan 7, 2021
1 parent 291a43e commit bb3a9dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions build-tools/xaprepare/xaprepare/Application/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,7 @@ public async Task<bool> Init (string? scenarioName = null)

Log.StatusLine ();
Log.StatusLine (" OS type: ", OS.Type, tailColor: Log.InfoColor);
Log.StatusLine (" OS flavor: ", OS.Flavor, tailColor: Log.InfoColor);
Log.StatusLine (" OS name: ", OS.Name, tailColor: Log.InfoColor);
Log.StatusLine ("OS release: ", OS.Release, tailColor: Log.InfoColor);
Log.StatusLine (" OS bits: ", OS.Architecture, tailColor: Log.InfoColor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ protected override bool InitOS ()
{
Version ubuntuRelease;
if (!Version.TryParse (Release, out ubuntuRelease)) {
Log.ErrorLine ($"Unable to parse string '{Release}' as a valid Ubuntu release version");
return false;
if (Int32.TryParse (Release, out int singleNumberVersion)) {
ubuntuRelease = new Version (singleNumberVersion, 0);
} else {
Log.ErrorLine ($"Unable to parse string '{Release}' as a valid {Name} release version");
return false;
}
}
UbuntuRelease = ubuntuRelease;

Expand Down

0 comments on commit bb3a9dc

Please sign in to comment.