From 6dd0957c4ad8f6650c3c4214ab95fb9a445b5d83 Mon Sep 17 00:00:00 2001 From: Crawcik Date: Thu, 14 Sep 2023 22:34:03 +0200 Subject: [PATCH 1/4] Adding better finding dotnet root location for mac&unix --- .../Flax.Build/Build/DotNet/DotNetSdk.cs | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs b/Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs index d3a706a43..e61642379 100644 --- a/Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs +++ b/Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs @@ -192,18 +192,18 @@ namespace Flax.Build case TargetPlatform.Linux: { // TODO: Support /etc/dotnet/install_location - - // Detect custom RID in some distros - rid = Utilities.ReadProcessOutput("dotnet", "--info").Split('\n').FirstOrDefault(x => x.StartsWith(" RID:"), "").Replace("RID:", "").Trim(); + rid = ""; ridFallback = $"linux-{arch}"; - if (rid == ridFallback) - ridFallback = ""; if (string.IsNullOrEmpty(dotnetPath)) + dotnetPath ??= SearchForDotnetLocationLinux(); + + if (dotnetPath == null) { - dotnetPath = "/usr/lib/dotnet/"; - if (!Directory.Exists(dotnetPath)) - dotnetPath = "/usr/share/dotnet/"; + rid = Utilities.ReadProcessOutput("dotnet", "--info").Split('\n').FirstOrDefault(x => x.StartsWith(" RID:"), "").Replace("RID:", "").Trim(); + if (rid == ridFallback) + ridFallback = ""; } + break; } case TargetPlatform.Mac: @@ -211,7 +211,12 @@ namespace Flax.Build rid = $"osx-{arch}"; ridFallback = ""; if (string.IsNullOrEmpty(dotnetPath)) - dotnetPath = "/usr/local/share/dotnet/"; + { + if (Directory.Exists("/usr/local/share/dotnet")) // Officialy recommended dotnet location + dotnetPath = "/usr/local/share/dotnet"; + else if (Environment.GetEnvironmentVariable("PATH") is string globalBinPath) + dotnetPath = globalBinPath.Split(':').FirstOrDefault(x => File.Exists(Path.Combine(x, "dotnet"))); + } break; } default: throw new InvalidPlatformException(platform); @@ -441,5 +446,18 @@ namespace Flax.Build // TODO: reject 'future' versions like .Net 8? return versions.OrderByDescending(ParseVersion).FirstOrDefault(); } + + private static string SearchForDotnetLocationLinux() + { + if (File.Exists("/etc/dotnet/install_location")) // Officialy recommended dotnet location file + return File.ReadAllText("/etc/dotnet/install_location").Trim(); + if (Directory.Exists("/usr/share/dotnet")) // Officialy recommended dotnet location + return"/usr/share/dotnet"; + if (Directory.Exists("/usr/lib/dotnet")) // Deprecated recommended dotnet location + return "/usr/lib/dotnet"; + if (Environment.GetEnvironmentVariable("PATH") is string globalBinPath) // Searching for dotnet binary + return globalBinPath.Split(':').FirstOrDefault(x => File.Exists(Path.Combine(x, "dotnet"))); + return null; + } } } From 73bf28dc4712da7d465dda33299e107cfbc9df46 Mon Sep 17 00:00:00 2001 From: Crawcik Date: Thu, 14 Sep 2023 22:37:56 +0200 Subject: [PATCH 2/4] Change of priorities on RID --- Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs b/Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs index e61642379..ecb6c9fea 100644 --- a/Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs +++ b/Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs @@ -192,17 +192,13 @@ namespace Flax.Build case TargetPlatform.Linux: { // TODO: Support /etc/dotnet/install_location - rid = ""; - ridFallback = $"linux-{arch}"; + rid = $"linux-{arch}"; + ridFallback = ""; if (string.IsNullOrEmpty(dotnetPath)) dotnetPath ??= SearchForDotnetLocationLinux(); if (dotnetPath == null) - { - rid = Utilities.ReadProcessOutput("dotnet", "--info").Split('\n').FirstOrDefault(x => x.StartsWith(" RID:"), "").Replace("RID:", "").Trim(); - if (rid == ridFallback) - ridFallback = ""; - } + ridFallback = Utilities.ReadProcessOutput("dotnet", "--info").Split('\n').FirstOrDefault(x => x.StartsWith(" RID:"), "").Replace("RID:", "").Trim(); break; } From 64a5d895bd607a90bce13832ba353c7459578b7b Mon Sep 17 00:00:00 2001 From: Crawcik Date: Thu, 14 Sep 2023 23:18:12 +0200 Subject: [PATCH 3/4] Better version checking --- Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs b/Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs index ecb6c9fea..4b430702f 100644 --- a/Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs +++ b/Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs @@ -428,7 +428,8 @@ namespace Flax.Build version = version.Substring(0, version.IndexOf("-")); rev = 0; } - Version ver = new Version(version); + if (!Version.TryParse(version, out var ver)) + return null; return new Version(ver.Major, ver.Minor, ver.Build, rev); } From 1dd7a27568e6d4d1438bcb849f210960bf02dbdf Mon Sep 17 00:00:00 2001 From: Crawcik Date: Thu, 14 Sep 2023 23:19:36 +0200 Subject: [PATCH 4/4] Checking for executable --- Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs b/Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs index 4b430702f..66b578693 100644 --- a/Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs +++ b/Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs @@ -448,9 +448,9 @@ namespace Flax.Build { if (File.Exists("/etc/dotnet/install_location")) // Officialy recommended dotnet location file return File.ReadAllText("/etc/dotnet/install_location").Trim(); - if (Directory.Exists("/usr/share/dotnet")) // Officialy recommended dotnet location + if (File.Exists("/usr/share/dotnet/dotnet")) // Officialy recommended dotnet location return"/usr/share/dotnet"; - if (Directory.Exists("/usr/lib/dotnet")) // Deprecated recommended dotnet location + if (File.Exists("/usr/lib/dotnet/dotnet")) // Deprecated recommended dotnet location return "/usr/lib/dotnet"; if (Environment.GetEnvironmentVariable("PATH") is string globalBinPath) // Searching for dotnet binary return globalBinPath.Split(':').FirstOrDefault(x => File.Exists(Path.Combine(x, "dotnet")));