Skip to content

Commit 032cdcf

Browse files
authored
[xaprepare] Support Gentoo Linux for OS detection (#7442)
Fixes: #7441 `make prepare` fails during OS detection on Gentoo Linux: Failed to detect your Linux distribution. Additional info: name: $Gentoo; release: $2.8; id: $gentoo System.InvalidOperationException: Failed to detect your Linux distribution. Additional info: name: $Gentoo; release: $2.8; id: $gentoo at Xamarin.Android.Prepare.Linux.DetectAndCreate(Context context) at Xamarin.Android.Prepare.Context.InitOS() at Xamarin.Android.Prepare.Context.Init(String scenarioName) at Xamarin.Android.Prepare.App.Run(String[] args) Update build-tools/xaprepare to handle Gentoo Linux OS detection and package handling. Implementation is based on ArchLinux implementation.
1 parent 5044377 commit 032cdcf

File tree

4 files changed

+126
-2
lines changed

4 files changed

+126
-2
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
4+
namespace Xamarin.Android.Prepare
5+
{
6+
class GentooLinuxProgram : LinuxProgram
7+
{
8+
public GentooLinuxProgram (string packageName, string? executableName = null)
9+
: base (packageName, executableName)
10+
{}
11+
12+
protected override bool CheckWhetherInstalled ()
13+
{
14+
var output = Utilities.GetStringFromStdout ("equery", "--quiet", "list", PackageName).Replace ($"{PackageName.Split (':') [0]}-", "").Split ('-', '_');
15+
if (output.Length >= 1 && !String.IsNullOrEmpty (output [0])) {
16+
CurrentVersion = output [0];
17+
return true;
18+
}
19+
20+
return false;
21+
}
22+
23+
#pragma warning disable CS1998
24+
public override async Task<bool> Install ()
25+
{
26+
ProcessRunner runner;
27+
if (NeedsSudoToInstall) {
28+
runner = new ProcessRunner ("sudo", "emerge", "--oneshot", PackageName) {
29+
EchoStandardOutput = true,
30+
EchoStandardError = true,
31+
ProcessTimeout = TimeSpan.FromMinutes (60), // gcc most probably will not compile in 60 minutes...
32+
};
33+
}
34+
else
35+
{
36+
runner = new ProcessRunner ("emerge", "--oneshot", PackageName) {
37+
EchoStandardOutput = true,
38+
EchoStandardError = true,
39+
ProcessTimeout = TimeSpan.FromMinutes (60), // gcc most probably will not compile in 60 minutes...
40+
};
41+
}
42+
43+
bool failed = await Task.Run (() => !runner.Run ());
44+
if (failed) {
45+
Log.Error ($"Installation of {PackageName} timed out");
46+
failed = true;
47+
}
48+
49+
if (runner.ExitCode != 0) {
50+
Log.Error ($"Installation failed with error code {runner.ExitCode}");
51+
failed = true;
52+
}
53+
54+
return !failed;
55+
}
56+
#pragma warning restore CS1998
57+
58+
protected override bool DeterminePackageVersion()
59+
{
60+
return true;
61+
}
62+
}
63+
}

build-tools/xaprepare/xaprepare/Application/Utilities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ public static string GetStringFromStdout (ProcessRunner runner, bool throwOnErro
820820
LogError ($"failed with exit code {runner.ExitCode}");
821821
return String.Empty;
822822
}
823-
823+
824824
string ret = sw.ToString ();
825825
if (trimTrailingWhitespace)
826826
return ret.TrimEnd ();
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System.Collections.Generic;
2+
3+
namespace Xamarin.Android.Prepare
4+
{
5+
class LinuxGentoo : Linux
6+
{
7+
static readonly List<GentooLinuxProgram> packages = new List<GentooLinuxProgram> {
8+
new GentooLinuxProgram ("sys-devel/autoconf"),
9+
new GentooLinuxProgram ("sys-devel/automake"),
10+
new GentooLinuxProgram ("sys-devel/binutils"),
11+
new GentooLinuxProgram ("sys-devel/bison"),
12+
new GentooLinuxProgram ("net-misc/curl"),
13+
new GentooLinuxProgram ("sys-apps/fakeroot"),
14+
new GentooLinuxProgram ("sys-apps/file"),
15+
new GentooLinuxProgram ("sys-apps/findutils"),
16+
new GentooLinuxProgram ("sys-devel/flex"),
17+
new GentooLinuxProgram ("sys-apps/gawk"),
18+
new GentooLinuxProgram ("sys-devel/gcc"),
19+
new GentooLinuxProgram ("sys-devel/gettext"),
20+
new GentooLinuxProgram ("dev-vcs/git"),
21+
new GentooLinuxProgram ("sys-apps/grep"),
22+
new GentooLinuxProgram ("sys-apps/groff"),
23+
//new GentooLinuxProgram ("gtk-sharp-2"),
24+
new GentooLinuxProgram ("app-arch/gzip"),
25+
new GentooLinuxProgram ("dev-java/openjdk-bin:8"),
26+
new GentooLinuxProgram ("sys-devel/libtool"),
27+
new GentooLinuxProgram ("dev-libs/libzip"),
28+
new GentooLinuxProgram ("sys-devel/m4"),
29+
new GentooLinuxProgram ("sys-devel/make"),
30+
//new GentooLinuxProgram ("nuget"),
31+
new GentooLinuxProgram ("sys-devel/patch"),
32+
new GentooLinuxProgram ("dev-util/pkgconf"),
33+
//new GentooLinuxProgram ("referenceassemblies-pcl"),
34+
new GentooLinuxProgram ("sys-apps/sed"),
35+
new GentooLinuxProgram ("sys-apps/texinfo"),
36+
new GentooLinuxProgram ("app-arch/unzip"),
37+
new GentooLinuxProgram ("sys-apps/which"),
38+
new GentooLinuxProgram ("app-arch/zip"),
39+
new GentooLinuxProgram ("app-arch/p7zip"),
40+
};
41+
42+
public LinuxGentoo (Context context)
43+
: base (context)
44+
{
45+
Dependencies.AddRange (packages);
46+
}
47+
48+
protected override void InitializeDependencies ()
49+
{}
50+
51+
protected override bool InitOS ()
52+
{
53+
if (!base.InitOS ())
54+
return false;
55+
56+
return true;
57+
}
58+
};
59+
}

build-tools/xaprepare/xaprepare/OperatingSystems/Linux.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,16 @@ echo 1 > /proc/sys/fs/binfmt_misc/status
3636
{"LinuxMint", (ctx) => new LinuxMint (ctx)},
3737
{"Arch", (ctx) => new LinuxArch (ctx)},
3838
{"Fedora", (ctx) => new LinuxFedora (ctx)},
39+
{"Gentoo", (ctx) => new LinuxGentoo (ctx)},
3940
};
4041

4142
static readonly Dictionary<string, string> distroIdMap = new Dictionary<string, string> (StringComparer.OrdinalIgnoreCase) {
4243
{"debian", "Debian"},
4344
{"ubuntu", "Ubuntu"},
4445
{"arch", "Arch"},
4546
{"linuxmint", "LinuxMint"},
46-
{"fedora", "Fedora"}
47+
{"fedora", "Fedora"},
48+
{"gentoo", "Gentoo"},
4749
};
4850

4951
bool warnBinFmt;

0 commit comments

Comments
 (0)