Skip to content

Commit eff77a4

Browse files
gugavarojonpryor
authored andcommitted
[xaprepare] Restore for multiple solutions (#3997)
Context: #3884 Commit 91467bb 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 91467bb 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 91467bb 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 <?xml version="1.0" encoding="utf-8"?> <packages> <package id="Microsoft.DotNet.ApiCompat" version="5.0.0-beta.19602.1" targetFramework="net472" /> <package id="Microsoft.DotNet.GenAPI" version="5.0.0-beta.19602.1" targetFramework="net472" /> <package id="Mono.Posix.NETStandard" version="1.0.0" targetFramework="net472" /> <package id="Xamarin.LibZipSharp" version="1.0.6" targetFramework="net472" /> </packages> $ 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.
1 parent 83ba00a commit eff77a4

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

build-tools/xaprepare/xaprepare/Application/Context.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,15 @@ partial class Context : AppObject
1818
public const ConsoleColor FailureColor = ConsoleColor.Red;
1919
public const ConsoleColor WarningColor = ConsoleColor.Yellow;
2020

21-
static readonly string XASolutionFilePath = Path.Combine (BuildPaths.XamarinAndroidSourceRoot, "Xamarin.Android.sln");
22-
static readonly string XATestsSolutionFilePath = Path.Combine (BuildPaths.XamarinAndroidSourceRoot, "Xamarin.Android-Tests.sln");
21+
static readonly IEnumerable<string> XASolutionFilesPath = new string [] {
22+
Path.Combine (BuildPaths.XamarinAndroidSourceRoot, "Xamarin.Android.BootstrapTasks.sln"),
23+
Path.Combine (BuildPaths.XamarinAndroidSourceRoot, "Xamarin.Android.Build.Tasks.sln"),
24+
Path.Combine (BuildPaths.XamarinAndroidSourceRoot, "Xamarin.Android.sln"),
25+
};
26+
27+
static readonly IEnumerable<string> XATestsSolutionFilesPath = new string [] {
28+
Path.Combine (BuildPaths.XamarinAndroidSourceRoot, "Xamarin.Android-Tests.sln"),
29+
};
2330

2431
string logDirectory;
2532
string mainLogFilePath;
@@ -171,12 +178,12 @@ partial class Context : AppObject
171178
/// <summary>
172179
/// Path to the Xamarin.Android solution file
173180
/// </summary>
174-
public string XASolutionFile => XASolutionFilePath;
181+
public IEnumerable<string> XASolutionFiles => XASolutionFilesPath;
175182

176183
/// <summary>
177184
/// Path to the Xamarin.Android tests solution file
178185
/// </summary>
179-
public string XATestsSolutionFile => XATestsSolutionFilePath;
186+
public IEnumerable<string> XATestsSolutionFiles => XATestsSolutionFilesPath;
180187

181188
/// <summary>
182189
/// If <c>true</c>, the current console is capable of displayig UTF-8 characters

build-tools/xaprepare/xaprepare/Steps/Step_PrepareExternal.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@ protected override async Task<bool> Execute (Context context)
1414
{
1515
var nuget = new NuGetRunner (context);
1616

17-
if (!await NuGetRestore (nuget, context.XASolutionFile)) {
18-
return false;
17+
foreach (var solutionFile in context.XASolutionFiles) {
18+
if (!await NuGetRestore (nuget, solutionFile)) {
19+
return false;
20+
}
1921
}
2022

2123
Log.StatusLine ();
22-
if (!await NuGetRestore (nuget, context.XATestsSolutionFile)) {
23-
return false;
24+
25+
foreach (var solutionFile in context.XATestsSolutionFiles) {
26+
if (!await NuGetRestore (nuget, solutionFile)) {
27+
return false;
28+
}
2429
}
2530

2631
var msbuild = new MSBuildRunner (context);

0 commit comments

Comments
 (0)