Skip to content

Commit

Permalink
Merge branch 'main' into tune-runtime-cpp
Browse files Browse the repository at this point in the history
* main:
  [xaprepare] Support Gentoo Linux for OS detection (xamarin#7442)
  [Xamarin.Android.Build.Tasks] Avoid XA5207 for design-time builds (xamarin#7434)
  • Loading branch information
grendello committed Oct 10, 2022
2 parents c4485cd + 032cdcf commit 12f8bd3
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 10 deletions.
63 changes: 63 additions & 0 deletions build-tools/xaprepare/xaprepare/Application/Program.GentooLinux.cs
@@ -0,0 +1,63 @@
using System;
using System.Threading.Tasks;

namespace Xamarin.Android.Prepare
{
class GentooLinuxProgram : LinuxProgram
{
public GentooLinuxProgram (string packageName, string? executableName = null)
: base (packageName, executableName)
{}

protected override bool CheckWhetherInstalled ()
{
var output = Utilities.GetStringFromStdout ("equery", "--quiet", "list", PackageName).Replace ($"{PackageName.Split (':') [0]}-", "").Split ('-', '_');
if (output.Length >= 1 && !String.IsNullOrEmpty (output [0])) {
CurrentVersion = output [0];
return true;
}

return false;
}

#pragma warning disable CS1998
public override async Task<bool> Install ()
{
ProcessRunner runner;
if (NeedsSudoToInstall) {
runner = new ProcessRunner ("sudo", "emerge", "--oneshot", PackageName) {
EchoStandardOutput = true,
EchoStandardError = true,
ProcessTimeout = TimeSpan.FromMinutes (60), // gcc most probably will not compile in 60 minutes...
};
}
else
{
runner = new ProcessRunner ("emerge", "--oneshot", PackageName) {
EchoStandardOutput = true,
EchoStandardError = true,
ProcessTimeout = TimeSpan.FromMinutes (60), // gcc most probably will not compile in 60 minutes...
};
}

bool failed = await Task.Run (() => !runner.Run ());
if (failed) {
Log.Error ($"Installation of {PackageName} timed out");
failed = true;
}

if (runner.ExitCode != 0) {
Log.Error ($"Installation failed with error code {runner.ExitCode}");
failed = true;
}

return !failed;
}
#pragma warning restore CS1998

protected override bool DeterminePackageVersion()
{
return true;
}
}
}
2 changes: 1 addition & 1 deletion build-tools/xaprepare/xaprepare/Application/Utilities.cs
Expand Up @@ -820,7 +820,7 @@ public static string GetStringFromStdout (ProcessRunner runner, bool throwOnErro
LogError ($"failed with exit code {runner.ExitCode}");
return String.Empty;
}

string ret = sw.ToString ();
if (trimTrailingWhitespace)
return ret.TrimEnd ();
Expand Down
@@ -0,0 +1,59 @@
using System.Collections.Generic;

namespace Xamarin.Android.Prepare
{
class LinuxGentoo : Linux
{
static readonly List<GentooLinuxProgram> packages = new List<GentooLinuxProgram> {
new GentooLinuxProgram ("sys-devel/autoconf"),
new GentooLinuxProgram ("sys-devel/automake"),
new GentooLinuxProgram ("sys-devel/binutils"),
new GentooLinuxProgram ("sys-devel/bison"),
new GentooLinuxProgram ("net-misc/curl"),
new GentooLinuxProgram ("sys-apps/fakeroot"),
new GentooLinuxProgram ("sys-apps/file"),
new GentooLinuxProgram ("sys-apps/findutils"),
new GentooLinuxProgram ("sys-devel/flex"),
new GentooLinuxProgram ("sys-apps/gawk"),
new GentooLinuxProgram ("sys-devel/gcc"),
new GentooLinuxProgram ("sys-devel/gettext"),
new GentooLinuxProgram ("dev-vcs/git"),
new GentooLinuxProgram ("sys-apps/grep"),
new GentooLinuxProgram ("sys-apps/groff"),
//new GentooLinuxProgram ("gtk-sharp-2"),
new GentooLinuxProgram ("app-arch/gzip"),
new GentooLinuxProgram ("dev-java/openjdk-bin:8"),
new GentooLinuxProgram ("sys-devel/libtool"),
new GentooLinuxProgram ("dev-libs/libzip"),
new GentooLinuxProgram ("sys-devel/m4"),
new GentooLinuxProgram ("sys-devel/make"),
//new GentooLinuxProgram ("nuget"),
new GentooLinuxProgram ("sys-devel/patch"),
new GentooLinuxProgram ("dev-util/pkgconf"),
//new GentooLinuxProgram ("referenceassemblies-pcl"),
new GentooLinuxProgram ("sys-apps/sed"),
new GentooLinuxProgram ("sys-apps/texinfo"),
new GentooLinuxProgram ("app-arch/unzip"),
new GentooLinuxProgram ("sys-apps/which"),
new GentooLinuxProgram ("app-arch/zip"),
new GentooLinuxProgram ("app-arch/p7zip"),
};

public LinuxGentoo (Context context)
: base (context)
{
Dependencies.AddRange (packages);
}

protected override void InitializeDependencies ()
{}

protected override bool InitOS ()
{
if (!base.InitOS ())
return false;

return true;
}
};
}
4 changes: 3 additions & 1 deletion build-tools/xaprepare/xaprepare/OperatingSystems/Linux.cs
Expand Up @@ -36,14 +36,16 @@ abstract partial class Linux : Unix
{"LinuxMint", (ctx) => new LinuxMint (ctx)},
{"Arch", (ctx) => new LinuxArch (ctx)},
{"Fedora", (ctx) => new LinuxFedora (ctx)},
{"Gentoo", (ctx) => new LinuxGentoo (ctx)},
};

static readonly Dictionary<string, string> distroIdMap = new Dictionary<string, string> (StringComparer.OrdinalIgnoreCase) {
{"debian", "Debian"},
{"ubuntu", "Ubuntu"},
{"arch", "Arch"},
{"linuxmint", "LinuxMint"},
{"fedora", "Fedora"}
{"fedora", "Fedora"},
{"gentoo", "Gentoo"},
};

bool warnBinFmt;
Expand Down
7 changes: 4 additions & 3 deletions src/Xamarin.Android.Build.Tasks/Tasks/GetJavaPlatformJar.cs
Expand Up @@ -23,6 +23,8 @@ public class GetJavaPlatformJar : AndroidTask

public string AndroidManifest { get; set; }

public bool DesignTimeBuild { get; set; }

[Output]
public string JavaPlatformJarPath { get; set; }

Expand Down Expand Up @@ -84,12 +86,11 @@ public override bool RunTask ()
}

platform = GetTargetSdkVersion (platform, target_sdk);
JavaPlatformJarPath = MonoAndroidHelper.TryGetAndroidJarPath (Log, platform);
JavaPlatformJarPath = MonoAndroidHelper.TryGetAndroidJarPath (Log, platform, designTimeBuild: DesignTimeBuild);
TargetSdkVersion = MonoAndroidHelper.SupportedVersions.GetApiLevelFromId (platform).ToString ();
if (JavaPlatformJarPath == null)
return !Log.HasLoggedErrors;

TargetSdkVersion = MonoAndroidHelper.SupportedVersions.GetApiLevelFromId (platform).ToString ();

return !Log.HasLoggedErrors;
}

Expand Down
Expand Up @@ -1365,6 +1365,8 @@ public void IfAndroidJarDoesNotExistThrowXA5207 ()
if (!Builder.UseDotNet)
proj.TargetFrameworkVersion = builder.LatestTargetFrameworkVersion ();
builder.ThrowOnBuildFailure = false;
Assert.IsTrue (builder.DesignTimeBuild (proj), "DesignTime build should succeed.");
Assert.IsFalse (builder.LastBuildOutput.ContainsText ("error XA5207:"), "XA5207 should not have been raised.");
builder.Target = "AndroidPrepareForBuild";
Assert.IsFalse (builder.Build (proj, parameters: new string [] {
$"AndroidSdkBuildToolsVersion=24.0.1",
Expand Down
10 changes: 6 additions & 4 deletions src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs
Expand Up @@ -443,13 +443,15 @@ public static IEnumerable<string> Executables (string executable)
yield return executable;
}

public static string TryGetAndroidJarPath (TaskLoggingHelper log, string platform)
public static string TryGetAndroidJarPath (TaskLoggingHelper log, string platform, bool designTimeBuild = false)
{
var platformPath = MonoAndroidHelper.AndroidSdk.TryGetPlatformDirectoryFromApiLevel (platform, MonoAndroidHelper.SupportedVersions);
if (platformPath == null) {
var expectedPath = MonoAndroidHelper.AndroidSdk.GetPlatformDirectoryFromId (platform);
var sdkManagerMenuPath = OS.IsWindows ? Properties.Resources.XA5207_SDK_Manager_Windows : Properties.Resources.XA5207_SDK_Manager_macOS;
log.LogCodedError ("XA5207", Properties.Resources.XA5207, platform, Path.Combine (expectedPath, "android.jar"), sdkManagerMenuPath);
if (!designTimeBuild) {
var expectedPath = MonoAndroidHelper.AndroidSdk.GetPlatformDirectoryFromId (platform);
var sdkManagerMenuPath = OS.IsWindows ? Properties.Resources.XA5207_SDK_Manager_Windows : Properties.Resources.XA5207_SDK_Manager_macOS;
log.LogCodedError ("XA5207", Properties.Resources.XA5207, platform, Path.Combine (expectedPath, "android.jar"), sdkManagerMenuPath);
}
return null;
}
return Path.Combine (platformPath, "android.jar");
Expand Down
Expand Up @@ -99,7 +99,9 @@ projects.
<Target Name="_GetJavaPlatformJar">
<GetJavaPlatformJar
AndroidSdkPlatform="$(_AndroidApiLevel)"
AndroidManifest="$(_AndroidManifestAbs)">
AndroidManifest="$(_AndroidManifestAbs)"
DesignTimeBuild="$(DesignTimeBuild)"
>
<Output TaskParameter="JavaPlatformJarPath" PropertyName="JavaPlatformJarPath" />
<Output TaskParameter="TargetSdkVersion" PropertyName="_AndroidTargetSdkVersion" />
</GetJavaPlatformJar>
Expand Down

0 comments on commit 12f8bd3

Please sign in to comment.