From eff77a4ec9d322ea4cc9d1828c5c306c538e7e40 Mon Sep 17 00:00:00 2001 From: Gustavo Varo Date: Fri, 6 Dec 2019 17:24:58 -0500 Subject: [PATCH] [xaprepare] Restore for multiple solutions (#3997) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Context: https://github.com/xamarin/xamarin-android/pull/3884 Commit 91467bbd updated the build system so that instead of trying to do "everthing" within a single `.sln` file -- which would result in various file share exceptions when attempting to build `Xamarin.Android.sln` within Visual Studio on Windows -- the build tree would instead become "stateful": 1. Build `Xamarin.Android.BootstrapTasks.sln`. 2. Then `Xamarin.Android.sln` can be built. 3. Then `Xamarin.Android-Tests.sln` can be built. (1) was handled "internally" via `msbuild /t:Prepare`. A result of 91467bbd is that if e.g. `build-tools/Xamarin.Android.Tools.BootstrapTasks` were changed, building `src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj` would no longer cause `Xamarin.Android.Tools.BootstrapTasks` to be rebuilt. (This was the point, as rebuilding `Xamarin.Android.Tools.BootstrapTasks`/etc. is what caused the file sharing issues that we wanted fixed.) Overlooked in 91467bbd is that `xaprepare` (invoked by `msbuild /t:Prepare`) is responsible for restoring NuGet packages on `.sln` files, but it would only restore packages for `Xamarin.Android.sln`. This restriction caused problems in PR #3884, which attempted to add NuGet packages to `build-tools/Xamarin.Android.BootstrapTasks`, but because that solution never had its NuGet packages restored, attempting to use the expected *outputs* of NuGet restore would fail: $ cat build-tools/Xamarin.Android.BootstrapTasks/packages.config $ msbuild -t:restore build-tools/Xamarin.Android.BootstrapTasks/Xamarin.Android.Tools.BootstrapTask.csproj … $ ls packages/Microsoft.D* ls: cannot access 'packages/Microsoft.D*': No such file or directory Improve build system sanity: when `xaprepare` restores NuGet packages, it should restore the following solutions: * `Xamarin.Android.BootstrapTasks.sln` * `Xamarin.Android.Build.Tasks.sln` * `Xamarin.Android.sln` This will allow PR #3884 to work as intended. --- .../xaprepare/xaprepare/Application/Context.cs | 15 +++++++++++---- .../xaprepare/Steps/Step_PrepareExternal.cs | 13 +++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/build-tools/xaprepare/xaprepare/Application/Context.cs b/build-tools/xaprepare/xaprepare/Application/Context.cs index aada001f6fa..8205be94df8 100644 --- a/build-tools/xaprepare/xaprepare/Application/Context.cs +++ b/build-tools/xaprepare/xaprepare/Application/Context.cs @@ -18,8 +18,15 @@ partial class Context : AppObject public const ConsoleColor FailureColor = ConsoleColor.Red; public const ConsoleColor WarningColor = ConsoleColor.Yellow; - static readonly string XASolutionFilePath = Path.Combine (BuildPaths.XamarinAndroidSourceRoot, "Xamarin.Android.sln"); - static readonly string XATestsSolutionFilePath = Path.Combine (BuildPaths.XamarinAndroidSourceRoot, "Xamarin.Android-Tests.sln"); + static readonly IEnumerable XASolutionFilesPath = new string [] { + Path.Combine (BuildPaths.XamarinAndroidSourceRoot, "Xamarin.Android.BootstrapTasks.sln"), + Path.Combine (BuildPaths.XamarinAndroidSourceRoot, "Xamarin.Android.Build.Tasks.sln"), + Path.Combine (BuildPaths.XamarinAndroidSourceRoot, "Xamarin.Android.sln"), + }; + + static readonly IEnumerable XATestsSolutionFilesPath = new string [] { + Path.Combine (BuildPaths.XamarinAndroidSourceRoot, "Xamarin.Android-Tests.sln"), + }; string logDirectory; string mainLogFilePath; @@ -171,12 +178,12 @@ partial class Context : AppObject /// /// Path to the Xamarin.Android solution file /// - public string XASolutionFile => XASolutionFilePath; + public IEnumerable XASolutionFiles => XASolutionFilesPath; /// /// Path to the Xamarin.Android tests solution file /// - public string XATestsSolutionFile => XATestsSolutionFilePath; + public IEnumerable XATestsSolutionFiles => XATestsSolutionFilesPath; /// /// If true, the current console is capable of displayig UTF-8 characters diff --git a/build-tools/xaprepare/xaprepare/Steps/Step_PrepareExternal.cs b/build-tools/xaprepare/xaprepare/Steps/Step_PrepareExternal.cs index ab80015ad40..ed21d63c505 100644 --- a/build-tools/xaprepare/xaprepare/Steps/Step_PrepareExternal.cs +++ b/build-tools/xaprepare/xaprepare/Steps/Step_PrepareExternal.cs @@ -14,13 +14,18 @@ protected override async Task Execute (Context context) { var nuget = new NuGetRunner (context); - if (!await NuGetRestore (nuget, context.XASolutionFile)) { - return false; + foreach (var solutionFile in context.XASolutionFiles) { + if (!await NuGetRestore (nuget, solutionFile)) { + return false; + } } Log.StatusLine (); - if (!await NuGetRestore (nuget, context.XATestsSolutionFile)) { - return false; + + foreach (var solutionFile in context.XATestsSolutionFiles) { + if (!await NuGetRestore (nuget, solutionFile)) { + return false; + } } var msbuild = new MSBuildRunner (context);