Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java.Interop.BootstrapTasks] Filter out invalid JDKs #1278

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<LangVersion>11.0</LangVersion>
</PropertyGroup>

<Import Project="..\..\TargetFrameworkDependentValues.props" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml.Linq;
Expand Down Expand Up @@ -46,6 +47,7 @@ public override bool Execute ()
.Where (j => maxVersion != null ? j.Version <= maxVersion : true)
.Where (j => j.IncludePath.Any ());
var jdk = explicitJdks.Concat (defaultJdks)
.Where (j => JdkRunsOnHost (j))
.FirstOrDefault ();

if (jdk == null) {
Expand All @@ -71,6 +73,19 @@ public override bool Execute ()
return !Log.HasLoggedErrors;
}

static bool JdkRunsOnHost (XATInfo jdk)
{
var cputype = RuntimeInformation.ProcessArchitecture;
if (jdk.ReleaseProperties.TryGetValue ("OS_ARCH", out var arch)) {
return (cputype, arch) switch {
(Architecture.Arm64, "aarch64") => true,
(Architecture.X64, "x86_64") => true,
_ => false,
};
}
return true;
}

XATInfo[] GetJdkRoots ()
{
XATInfo jdk = null;
Expand Down