From e07a07f13ea45cbd7a6651f69d17dba0837953e3 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Sun, 19 Feb 2023 13:51:54 +0100 Subject: [PATCH] Support 'DOTNET_ROOT' env var in build tool for custom .NET SDK location --- .../Flax.Build/Build/DotNet/DotNetSdk.cs | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs b/Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs index 381e3248c..2d3f0d7c9 100644 --- a/Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs +++ b/Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs @@ -60,9 +60,9 @@ namespace Flax.Build return; // Find system-installed SDK - string dotnetPath; + string dotnetPath = Environment.GetEnvironmentVariable("DOTNET_ROOT"); string rid, ridFallback, arch; - string[] dotnetSdkVersions, dotnetRuntimeVersions; + string[] dotnetSdkVersions = null, dotnetRuntimeVersions = null; switch (architecture) { case TargetArchitecture.x86: @@ -108,18 +108,16 @@ namespace Flax.Build ridFallback = $"linux-{arch}"; if (rid == ridFallback) ridFallback = ""; - dotnetPath = "/usr/share/dotnet/"; - dotnetSdkVersions = Directory.GetDirectories($"{dotnetPath}sdk/").Select(Path.GetFileName).ToArray(); - dotnetRuntimeVersions = Directory.GetDirectories($"{dotnetPath}shared/Microsoft.NETCore.App/").Select(Path.GetFileName).ToArray(); + if (string.IsNullOrEmpty(dotnetPath)) + dotnetPath = "/usr/share/dotnet/"; break; } case TargetPlatform.Mac: { rid = $"osx-{arch}"; ridFallback = ""; - dotnetPath = "/usr/local/share/dotnet/"; - dotnetSdkVersions = Directory.GetDirectories($"{dotnetPath}sdk/").Select(Path.GetFileName).ToArray(); - dotnetRuntimeVersions = Directory.GetDirectories($"{dotnetPath}shared/Microsoft.NETCore.App/").Select(Path.GetFileName).ToArray(); + if (string.IsNullOrEmpty(dotnetPath)) + dotnetPath = "/usr/local/share/dotnet/"; break; } default: @@ -127,11 +125,25 @@ namespace Flax.Build } // Pick SDK version + if (string.IsNullOrEmpty(dotnetPath)) + { + Log.Warning("Missing .NET SDK"); + return; + } + if (!Directory.Exists(dotnetPath)) + { + Log.Warning($"Missing .NET SDK ({dotnetPath})"); + return; + } + if (dotnetSdkVersions == null) + dotnetSdkVersions = Directory.GetDirectories($"{dotnetPath}sdk/").Select(Path.GetFileName).ToArray(); + if (dotnetRuntimeVersions == null) + dotnetRuntimeVersions = Directory.GetDirectories($"{dotnetPath}shared/Microsoft.NETCore.App/").Select(Path.GetFileName).ToArray(); string dotnetSdkVersion = dotnetSdkVersions.OrderByDescending(ParseVersion).FirstOrDefault(); string dotnetRuntimeVersion = dotnetRuntimeVersions.OrderByDescending(ParseVersion).FirstOrDefault(); if (string.IsNullOrEmpty(dotnetSdkVersion)) - dotnetSdkVersion = Environment.GetEnvironmentVariable("DOTNET_ROOT"); - if (string.IsNullOrEmpty(dotnetPath) || string.IsNullOrEmpty(dotnetSdkVersion) || string.IsNullOrEmpty(dotnetRuntimeVersion)) + dotnetSdkVersion = dotnetPath; + if (string.IsNullOrEmpty(dotnetSdkVersion) || string.IsNullOrEmpty(dotnetRuntimeVersion)) { Log.Warning("Missing .NET SDK"); return;