Skip to content

Commit

Permalink
[xaprepare] Restore for multiple solutions (dotnet#3997)
Browse files Browse the repository at this point in the history
Context: dotnet#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 dotnet#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 dotnet#3884 to work as intended.
  • Loading branch information
gugavaro authored and jonpryor committed Dec 6, 2019
1 parent 83ba00a commit eff77a4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
15 changes: 11 additions & 4 deletions build-tools/xaprepare/xaprepare/Application/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> 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<string> XATestsSolutionFilesPath = new string [] {
Path.Combine (BuildPaths.XamarinAndroidSourceRoot, "Xamarin.Android-Tests.sln"),
};

string logDirectory;
string mainLogFilePath;
Expand Down Expand Up @@ -171,12 +178,12 @@ partial class Context : AppObject
/// <summary>
/// Path to the Xamarin.Android solution file
/// </summary>
public string XASolutionFile => XASolutionFilePath;
public IEnumerable<string> XASolutionFiles => XASolutionFilesPath;

/// <summary>
/// Path to the Xamarin.Android tests solution file
/// </summary>
public string XATestsSolutionFile => XATestsSolutionFilePath;
public IEnumerable<string> XATestsSolutionFiles => XATestsSolutionFilesPath;

/// <summary>
/// If <c>true</c>, the current console is capable of displayig UTF-8 characters
Expand Down
13 changes: 9 additions & 4 deletions build-tools/xaprepare/xaprepare/Steps/Step_PrepareExternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ protected override async Task<bool> 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);
Expand Down

0 comments on commit eff77a4

Please sign in to comment.