-
Notifications
You must be signed in to change notification settings - Fork 569
Expand file tree
/
Copy pathGenerateNativeAotEnvironmentAssemblerSources.cs
More file actions
56 lines (46 loc) · 2.1 KB
/
GenerateNativeAotEnvironmentAssemblerSources.cs
File metadata and controls
56 lines (46 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using Microsoft.Android.Build.Tasks;
using Microsoft.Build.Framework;
using Xamarin.Android.Tools;
namespace Xamarin.Android.Tasks;
public class GenerateNativeAotEnvironmentAssemblerSources : AndroidTask
{
public override string TaskPrefix => "GNAEAS";
[Required]
public ITaskItem[] OutputSources { get; set; } = [];
[Required]
public string RID { get; set; } = "";
public ITaskItem[]? Environments { get; set; }
public ITaskItem[]? DotNetStartupHooks { get; set; }
public string? HttpClientHandlerType { get; set; }
public override bool RunTask ()
{
var envBuilder = new EnvironmentBuilder (Log);
envBuilder.Read (Environments);
envBuilder.AddDotNetStartupHooks (DotNetStartupHooks);
// Environment variables are set by Java (code generated in the GenerateAdditionalProviderSources task)
// We still want to set system properties, if any
envBuilder.EnvironmentVariables.Clear ();
string abi = MonoAndroidHelper.RidToAbi (RID);
AndroidTargetArch targetArch = MonoAndroidHelper.RidToArch (RID);
// There can be only one, since we run in the inner build
ITaskItem? outputFile = GenerateNativeAotLibraryLoadAssemblerSources.FindOutputFile (OutputSources, abi: abi, rid: RID);
Log.LogDebugMessage ($"Environment variables file to generate: {outputFile.ItemSpec}");
string environmentLlFilePath = outputFile.ItemSpec;
var generator = new NativeAotEnvironmentNativeAssemblyGenerator (Log, envBuilder);
LLVMIR.LlvmIrModule environmentModule = generator.Construct ();
using var environmentWriter = MemoryStreamPool.Shared.CreateStreamWriter ();
bool fileFullyWritten = false;
try {
generator.Generate (environmentModule, targetArch, environmentWriter, environmentLlFilePath!);
environmentWriter.Flush ();
Files.CopyIfStreamChanged (environmentWriter.BaseStream, environmentLlFilePath!);
fileFullyWritten = true;
} finally {
// Log partial contents for debugging if generation failed
if (!fileFullyWritten) {
MonoAndroidHelper.LogTextStreamContents (Log, $"Partial contents of file '{environmentLlFilePath}'", environmentWriter.BaseStream);
}
}
return !Log.HasLoggedErrors;
}
}