Improve Linux .NET runtime identifier detection
Use the runtime identifier detected during runtime instead of calling the dotnet tool in order to query it.
This commit is contained in:
@@ -4,6 +4,7 @@ using System;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
|
|
||||||
namespace Flax.Build
|
namespace Flax.Build
|
||||||
@@ -187,7 +188,7 @@ namespace Flax.Build
|
|||||||
|
|
||||||
// Find system-installed SDK
|
// Find system-installed SDK
|
||||||
string dotnetPath = Environment.GetEnvironmentVariable("DOTNET_ROOT");
|
string dotnetPath = Environment.GetEnvironmentVariable("DOTNET_ROOT");
|
||||||
string rid, ridFallback, arch;
|
string arch;
|
||||||
IEnumerable<string> dotnetSdkVersions = null, dotnetRuntimeVersions = null;
|
IEnumerable<string> dotnetSdkVersions = null, dotnetRuntimeVersions = null;
|
||||||
switch (architecture)
|
switch (architecture)
|
||||||
{
|
{
|
||||||
@@ -209,8 +210,6 @@ namespace Flax.Build
|
|||||||
{
|
{
|
||||||
case TargetPlatform.Windows:
|
case TargetPlatform.Windows:
|
||||||
{
|
{
|
||||||
rid = $"win-{arch}";
|
|
||||||
ridFallback = "";
|
|
||||||
#pragma warning disable CA1416
|
#pragma warning disable CA1416
|
||||||
if (string.IsNullOrEmpty(dotnetPath))
|
if (string.IsNullOrEmpty(dotnetPath))
|
||||||
{
|
{
|
||||||
@@ -235,16 +234,12 @@ namespace Flax.Build
|
|||||||
}
|
}
|
||||||
case TargetPlatform.Linux:
|
case TargetPlatform.Linux:
|
||||||
{
|
{
|
||||||
rid = $"linux-{arch}";
|
|
||||||
ridFallback = Utilities.ReadProcessOutput("dotnet", "--info").Split('\n').FirstOrDefault(x => x.StartsWith(" RID:"), "").Replace("RID:", "").Trim();
|
|
||||||
if (string.IsNullOrEmpty(dotnetPath))
|
if (string.IsNullOrEmpty(dotnetPath))
|
||||||
dotnetPath ??= SearchForDotnetLocationLinux();
|
dotnetPath ??= SearchForDotnetLocationLinux();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TargetPlatform.Mac:
|
case TargetPlatform.Mac:
|
||||||
{
|
{
|
||||||
rid = $"osx-{arch}";
|
|
||||||
ridFallback = "";
|
|
||||||
if (string.IsNullOrEmpty(dotnetPath))
|
if (string.IsNullOrEmpty(dotnetPath))
|
||||||
{
|
{
|
||||||
dotnetPath = "/usr/local/share/dotnet/"; // Officially recommended dotnet location
|
dotnetPath = "/usr/local/share/dotnet/"; // Officially recommended dotnet location
|
||||||
@@ -258,7 +253,6 @@ namespace Flax.Build
|
|||||||
}
|
}
|
||||||
if (Flax.Build.Platforms.MacPlatform.BuildingForx64)
|
if (Flax.Build.Platforms.MacPlatform.BuildingForx64)
|
||||||
{
|
{
|
||||||
rid = "osx-x64";
|
|
||||||
dotnetPath = Path.Combine(dotnetPath, "x64");
|
dotnetPath = Path.Combine(dotnetPath, "x64");
|
||||||
architecture = TargetArchitecture.x64;
|
architecture = TargetArchitecture.x64;
|
||||||
}
|
}
|
||||||
@@ -332,6 +326,20 @@ namespace Flax.Build
|
|||||||
VersionName = dotnetSdkVersion;
|
VersionName = dotnetSdkVersion;
|
||||||
RuntimeVersionName = dotnetRuntimeVersion;
|
RuntimeVersionName = dotnetRuntimeVersion;
|
||||||
|
|
||||||
|
string rid, ridFallback = "";
|
||||||
|
switch (platform)
|
||||||
|
{
|
||||||
|
case TargetPlatform.Windows: rid = $"win-{arch}"; break;
|
||||||
|
case TargetPlatform.Linux:
|
||||||
|
{
|
||||||
|
rid = RuntimeInformation.RuntimeIdentifier;
|
||||||
|
ridFallback = $"linux-{arch}";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case TargetPlatform.Mac: rid = Flax.Build.Platforms.MacPlatform.BuildingForx64 ? "osx-x64" : $"osx-{arch}"; break;
|
||||||
|
default: throw new InvalidPlatformException(platform);
|
||||||
|
}
|
||||||
|
|
||||||
// Pick SDK runtime
|
// Pick SDK runtime
|
||||||
if (!TryAddHostRuntime(platform, architecture, rid) && !TryAddHostRuntime(platform, architecture, ridFallback))
|
if (!TryAddHostRuntime(platform, architecture, rid) && !TryAddHostRuntime(platform, architecture, ridFallback))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user