Skip to content

Commit

Permalink
[release/6.0.4xx-xcode14] Ensure we restore the temp csproj to comput…
Browse files Browse the repository at this point in the history
…e AOT compiler path (#16282)

The build command doesn't support a parameter to specify a NuGet.config,
so we need to restore the temp project first, so we pass the
NuGet.config file to use the sources from, in case it exists (e.g: the
NuGet.config from the XMA dotnet path).

This is useful to support auhtorized NuGet feeds

Fixes Bug #1611102 - [XVS][MAUI] Failed to build .NET MAUI (net6.0) with
iOS Simulator:
https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1611102

Backport of #16280

Co-authored-by: Mauro Agnoletti <mauro.agnoletti@gmail.com>
  • Loading branch information
1 parent 3da8bb2 commit fe3d332
Showing 1 changed file with 74 additions and 22 deletions.
96 changes: 74 additions & 22 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/FindAotCompilerTaskBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;

using Microsoft.Build.Framework;

using Xamarin.Localization.MSBuild;
using Threading = System.Threading.Tasks;

namespace Xamarin.MacDev.Tasks {
public abstract class FindAotCompilerTaskBase : XamarinTask {
Expand Down Expand Up @@ -46,13 +45,10 @@ public override bool Execute ()
string ComputeAotCompilerPath ()
{
var projectPath = Path.GetTempFileName ();
var outputFile = Path.GetTempFileName ();
var binlog = Path.GetTempFileName ();

File.Delete (projectPath);
projectPath += ".csproj";
File.Delete (binlog);
binlog += ".binlog";

var csproj = $@"<?xml version=""1.0"" encoding=""utf-8""?>
<Project Sdk=""Microsoft.NET.Sdk"">
<PropertyGroup>
Expand All @@ -68,17 +64,11 @@ string ComputeAotCompilerPath ()
";
File.WriteAllText (projectPath, csproj);

var executable = Environment.GetEnvironmentVariable ("DOTNET_HOST_PATH");
if (string.IsNullOrEmpty (executable))
executable = "dotnet";
var dotnetPath = Environment.GetEnvironmentVariable ("DOTNET_HOST_PATH");

var arguments = new List<string> ();
arguments.Add ("build");
arguments.Add ("/p:OutputFilePath=" + outputFile);
arguments.Add ("/p:RuntimeIdentifier=" + RuntimeIdentifier);
arguments.Add ("/t:ComputeAotCompilerPath");
arguments.Add ("/bl:" + binlog);
arguments.Add (projectPath);
if (string.IsNullOrEmpty (dotnetPath)) {
dotnetPath = "dotnet";
}

var environment = default (Dictionary<string, string>);
var customHome = Environment.GetEnvironmentVariable ("DOTNET_CUSTOM_HOME");
Expand All @@ -88,21 +78,83 @@ string ComputeAotCompilerPath ()
}

try {
ExecuteAsync (executable, arguments, environment: environment).Wait ();
return File.ReadAllText (outputFile).Trim ();
ExecuteRestoreAsync (dotnetPath, projectPath, environment).Wait ();

return ExecuteBuildAsync (dotnetPath, projectPath, environment).Result;
} finally {
if (KeepTemporaryOutput) {
Log.LogMessage (MessageImportance.Normal, "Temporary files for the FindAotCompiler task:");
Log.LogMessage (MessageImportance.Normal, $" Project file: {projectPath}");
Log.LogMessage (MessageImportance.Normal, $" Output file: {outputFile}");
Log.LogMessage (MessageImportance.Normal, $" Binary log: {binlog}");
Log.LogMessage (MessageImportance.Normal, $"Temporary project for the FindAotCompiler task: {projectPath}");
} else {
File.Delete (projectPath);
}
}
}

async Threading.Task ExecuteRestoreAsync (string dotnetPath, string projectPath, Dictionary<string, string> environment)
{
var binlog = GetTempBinLog ();
var arguments = new List<string> ();

arguments.Add ("restore");

var dotnetDir = Path.GetDirectoryName (dotnetPath);
var configFile = Path.Combine (dotnetDir, "NuGet.config");

if (File.Exists (configFile)) {
arguments.Add ("/p:RestoreConfigFile=" + configFile);
}

arguments.Add ("/bl:" + binlog);
arguments.Add (projectPath);

try {
await ExecuteAsync (dotnetPath, arguments, environment: environment);
} finally {
if (KeepTemporaryOutput) {
Log.LogMessage (MessageImportance.Normal, $"Temporary restore log for the FindAotCompiler task: {binlog}");
} else {
File.Delete (binlog);
}
}
}

async Threading.Task<string> ExecuteBuildAsync (string dotnetPath, string projectPath, Dictionary<string, string> environment)
{
var outputFile = Path.GetTempFileName ();
var binlog = GetTempBinLog ();
var arguments = new List<string> ();

arguments.Add ("build");
arguments.Add ("/p:OutputFilePath=" + outputFile);
arguments.Add ("/p:RuntimeIdentifier=" + RuntimeIdentifier);
arguments.Add ("/t:ComputeAotCompilerPath");
arguments.Add ("/bl:" + binlog);
arguments.Add (projectPath);

try {
await ExecuteAsync (dotnetPath, arguments, environment: environment);

return File.ReadAllText (outputFile).Trim ();
} finally {
if (KeepTemporaryOutput) {
Log.LogMessage (MessageImportance.Normal, $"Temporary output for the FindAotCompiler task: {outputFile}");
Log.LogMessage (MessageImportance.Normal, $"Temporary build log for the FindAotCompiler task: {binlog}");
} else {
File.Delete (outputFile);
File.Delete (binlog);
}
}
}

string GetTempBinLog ()
{
var binlog = Path.GetTempFileName ();

File.Delete (binlog);
binlog += ".binlog";

return binlog;
}
}
}

5 comments on commit fe3d332

@vs-mobiletools-engineering-service2
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ [CI Build] Tests on macOS Mac Catalina (10.15) failed ❌

No test package could be found for tests on macOS Mac Catalina (10.15)

Pipeline on Agent
Hash: fe3d3329d95ee75afd6b5ca68e39bdbb70a3d3fb [CI build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ [CI Build] Tests on macOS M1 - Mac Big Sur (11.5) failed ❌

No test package could be found for tests on macOS M1 - Mac Big Sur (11.5)

Pipeline on Agent
Hash: fe3d3329d95ee75afd6b5ca68e39bdbb70a3d3fb [CI build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ API diff for current PR / commit

Legacy Xamarin (No breaking changes)
  • iOS (no change detected)
  • tvOS (no change detected)
  • watchOS (no change detected)
NET (empty diffs)
  • iOS: (empty diff detected)
  • tvOS: (empty diff detected)

✅ API diff vs stable

Legacy Xamarin (No breaking changes)
.NET (No breaking changes)
Legacy Xamarin (stable) vs .NET

✅ Generator diff

Generator diff is empty

Pipeline on Agent
Hash: fe3d3329d95ee75afd6b5ca68e39bdbb70a3d3fb [CI build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 [CI Build] Test results 🔥

Test results

❌ Tests failed on VSTS: simulator tests

0 tests crashed, 4 tests failed, 156 tests passed.

Failures

❌ bcl tests

3 tests failed, 56 tests passed.
  • [NUnit] Mono BCL tests group 1/iOS Unified 64-bits - simulator/Debug: BuildFailure
  • [NUnit] Mono BCL tests group 2/iOS Unified 64-bits - simulator/Debug: BuildFailure
  • [xUnit] Mono BCL tests group 3/iOS Unified 64-bits - simulator/Debug: BuildFailure

Html Report (VSDrops) Download

❌ mtouch tests

1 tests failed, 0 tests passed.
  • MTouch tests/NUnit: Failed (Execution failed with exit code 3)

Html Report (VSDrops) Download

Successes

✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests: All 1 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 5 tests passed. Html Report (VSDrops) Download
✅ framework: All 5 tests passed. Html Report (VSDrops) Download
✅ generator: All 2 tests passed. Html Report (VSDrops) Download
✅ interdependent_binding_projects: All 5 tests passed. Html Report (VSDrops) Download
✅ install_source: All 1 tests passed. Html Report (VSDrops) Download
✅ introspection: All 5 tests passed. Html Report (VSDrops) Download
✅ linker: All 38 tests passed. Html Report (VSDrops) Download
⚠️ mac_binding_project: No tests selected. Html Report (VSDrops) Download
⚠️ mmp: No tests selected. Html Report (VSDrops) Download
✅ mononative: All 8 tests passed. Html Report (VSDrops) Download
✅ monotouch: All 20 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
⚠️ xammac: No tests selected. Html Report (VSDrops) Download
✅ xcframework: All 5 tests passed. Html Report (VSDrops) Download
✅ xtro: All 2 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: [CI build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator Author

Please sign in to comment.