Skip to content

Commit

Permalink
[msbuild] Add support for keeping temporary output when looking for A…
Browse files Browse the repository at this point in the history
…OT compilers. (#15884)
  • Loading branch information
rolfbjarne authored Sep 9, 2022
1 parent 7e20a09 commit b6cdde4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,7 @@
<FindAotCompiler
SessionId="$(BuildSessionId)"
Condition="'$(IsMacEnabled)' == 'true' And '$(_RunAotCompiler)' == 'true'"
KeepTemporaryOutput="$(FindAotCompilerKeepKeepTemporaryOutput)"
MonoAotCrossCompiler="@(MonoAotCrossCompiler)"
RuntimeIdentifier="$(RuntimeIdentifier)"
TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)"
Expand Down
18 changes: 16 additions & 2 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/FindAotCompilerTaskBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public abstract class FindAotCompilerTaskBase : XamarinTask {
[Required]
public ITaskItem[] MonoAotCrossCompiler { get; set; }

public bool KeepTemporaryOutput { get; set; }

[Required]
public string RuntimeIdentifier { get; set; }

Expand Down Expand Up @@ -45,9 +47,12 @@ 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 @@ -72,6 +77,7 @@ string ComputeAotCompilerPath ()
arguments.Add ("/p:OutputFilePath=" + outputFile);
arguments.Add ("/p:RuntimeIdentifier=" + RuntimeIdentifier);
arguments.Add ("/t:ComputeAotCompilerPath");
arguments.Add ("/bl:" + binlog);
arguments.Add (projectPath);

var environment = default (Dictionary<string, string>);
Expand All @@ -85,8 +91,16 @@ string ComputeAotCompilerPath ()
ExecuteAsync (executable, arguments, environment: environment).Wait ();
return File.ReadAllText (outputFile).Trim ();
} finally {
File.Delete (projectPath);
File.Delete (outputFile);
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}");
} else {
File.Delete (projectPath);
File.Delete (outputFile);
File.Delete (binlog);
}
}
}
}
Expand Down

5 comments on commit b6cdde4

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.