From 9ca1f82ade2084fbf7ac0089a47615723a7fadb1 Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Fri, 7 Feb 2025 09:40:00 -0500 Subject: [PATCH] Backport `dotnet-install` script from a941e34 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Partial backport of https://github.com/dotnet/android/pull/9761 Update `build-tools/xaprepare` to improve reliability when running `Step_InstallDotNetPreview`. `Step_InstallDotNetPreview` will cache e.g. `dotnet-install.sh` into `$HOME/android-archives`, but there was no logic to verify that it was still *valid*. We've been seeing some recurring build failures in **macOS > Build** such as: Downloading dotnet-install script... Warning: Using cached installation script found in '/Users/builder/android-archives/dotnet-install.sh' Discovering download URLs for dotnet SDK '10.0.100-preview.2.25102.3'... Downloading dotnet archive... dotnet archive URL https://dotnetcli.azureedge.net/dotnet/Sdk/10.0.100-preview.2.25102.3/dotnet-sdk-10.0.100-preview.2.25102.3-osx-arm64.tar.gz not found Downloading dotnet archive... dotnet archive URL https://dotnetcli.azureedge.net/dotnet/Sdk/10.0.100-preview.2.25102.3/dotnet-dev-osx-arm64.10.0.100-preview.2.25102.3.tar.gz not found Downloading dotnet archive... Warning: Failed to obtain dotnet archive size. HTTP status code: InternalServerError (500) Downloading dotnet archive... Warning: Failed to obtain dotnet archive size. HTTP status code: InternalServerError (500) Error: Installation of dotnet SDK '10.0.100-preview.2.25102.3' failed. Step Xamarin.Android.Prepare.Step_InstallDotNetPreview failed System.InvalidOperationException: Step Xamarin.Android.Prepare.Step_InstallDotNetPreview failed at Xamarin.Android.Prepare.Scenario.Run(Context context, Log log) in /Users/builder/azdo/_work/8/s/xamarin-android/build-tools/xaprepare/xaprepare/Application/Scenario.cs:line 50 at Xamarin.Android.Prepare.Context.Execute() in /Users/builder/azdo/_work/8/s/xamarin-android/build-tools/xaprepare/xaprepare/Application/Context.cs:line 488 at Xamarin.Android.Prepare.App.Run(String[] args) in /Users/builder/azdo/_work/8/s/xamarin-android/build-tools/xaprepare/xaprepare/Main.cs:line 155 Indeed, [`dotnet-sdk-10.0.100-preview.2.25102.3-osx-arm64.tar.gz`][0] no longer exists on . The problem, though, is that .NET changed the CDN that is used in the past month, and that's not the correct URL. A newer `dotnet-install.sh` reports: % bash "…/dotnet-install.sh" "--version" "10.0.100-preview.2.25102.3" "--install-dir" "/Volumes/Xamarin-Work/src/dotnet/android/bin/Release/dotnet" "--verbose" "--dry-run … dotnet-install: Link 0: primary, 10.0.100-preview.2.25102.3, https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.100-preview.2.25102.3/dotnet-sdk-10.0.100-preview.2.25102.3-osx-x64.tar.gz dotnet-install: Link 1: legacy, 10.0.100-preview.2.25102.3, https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.100-preview.2.25102.3/dotnet-dev-osx-x64.10.0.100-preview.2.25102.3.tar.gz dotnet-install: Link 2: primary, 10.0.100-preview.2.25102.3, https://ci.dot.net/public/Sdk/10.0.100-preview.2.25102.3/dotnet-sdk-10.0.100-preview.2.25102.3-osx-x64.tar.gz dotnet-install: Link 3: legacy, 10.0.100-preview.2.25102.3, https://ci.dot.net/public/Sdk/10.0.100-preview.2.25102.3/dotnet-dev-osx-x64.10.0.100-preview.2.25102.3.tar.gz Note the different domain, ! Update `Step_InstallDotNetPreview` to try to install .NET potentially *twice*: the first time using the cached `dotnet-install.sh`, and *if that fails*, it tries again after downloading a *new* `dotnet-install.sh`. Hopefully this will fix the build failure on this machine! [0]: https://dotnetcli.azureedge.net/dotnet/Sdk/10.0.100-preview.2.25102.3/dotnet-sdk-10.0.100-preview.2.25102.3-osx-arm64.tar.gz --- .../xaprepare/Steps/Step_InstallDotNetPreview.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/build-tools/xaprepare/xaprepare/Steps/Step_InstallDotNetPreview.cs b/build-tools/xaprepare/xaprepare/Steps/Step_InstallDotNetPreview.cs index e1808adc328..ce0220fdf71 100644 --- a/build-tools/xaprepare/xaprepare/Steps/Step_InstallDotNetPreview.cs +++ b/build-tools/xaprepare/xaprepare/Steps/Step_InstallDotNetPreview.cs @@ -21,7 +21,8 @@ protected override async Task Execute (Context context) var dotnetPath = Configurables.Paths.DotNetPreviewPath; dotnetPath = dotnetPath.TrimEnd (new char [] { Path.DirectorySeparatorChar }); - if (!await InstallDotNetAsync (context, dotnetPath, BuildToolVersion)) { + if (!await InstallDotNetAsync (context, dotnetPath, BuildToolVersion, useCachedInstallScript: true) && + !await InstallDotNetAsync (context, dotnetPath, BuildToolVersion, useCachedInstallScript: false)) { Log.ErrorLine ($"Installation of dotnet SDK '{BuildToolVersion}' failed."); return false; } @@ -77,17 +78,18 @@ protected override async Task Execute (Context context) return true; } - async Task DownloadDotNetInstallScript (Context context, string dotnetScriptPath, Uri dotnetScriptUrl) + async Task DownloadDotNetInstallScript (Context context, string dotnetScriptPath, Uri dotnetScriptUrl, bool useCachedInstallScript) { string tempDotnetScriptPath = dotnetScriptPath + "-tmp"; Utilities.DeleteFile (tempDotnetScriptPath); Log.StatusLine ("Downloading dotnet-install script..."); - if (File.Exists (dotnetScriptPath)) { + if (useCachedInstallScript && File.Exists (dotnetScriptPath)) { Log.WarningLine ($"Using cached installation script found in '{dotnetScriptPath}'"); return true; } + Utilities.DeleteFile (dotnetScriptPath); Log.StatusLine ($" {context.Characters.Link} {dotnetScriptUrl}", ConsoleColor.White); await Utilities.Download (dotnetScriptUrl, tempDotnetScriptPath, DownloadStatus.Empty); @@ -173,7 +175,7 @@ string[] GetInstallationScriptArgs (string version, string dotnetPath, string do return args.ToArray (); } - async Task InstallDotNetAsync (Context context, string dotnetPath, string version, bool runtimeOnly = false) + async Task InstallDotNetAsync (Context context, string dotnetPath, string version, bool useCachedInstallScript, bool runtimeOnly = false) { string cacheDir = context.Properties.GetRequiredValue (KnownProperties.AndroidToolchainCacheDirectory); @@ -183,7 +185,7 @@ async Task InstallDotNetAsync (Context context, string dotnetPath, string Uri dotnetScriptUrl = Configurables.Urls.DotNetInstallScript; string scriptFileName = Path.GetFileName (dotnetScriptUrl.LocalPath); string cachedDotnetScriptPath = Path.Combine (cacheDir, scriptFileName); - if (!await DownloadDotNetInstallScript (context, cachedDotnetScriptPath, dotnetScriptUrl)) { + if (!await DownloadDotNetInstallScript (context, cachedDotnetScriptPath, dotnetScriptUrl, useCachedInstallScript)) { return false; }