Skip to content

Commit

Permalink
Exapnd to full paths inside individual tasks, instead of inside MSBui…
Browse files Browse the repository at this point in the history
…ld, before any async dispatch happens.

Add many comments.
Run IkvmJavaCompiler task async, on a separate thread, even though we cannot effectuate cancellation. Should allow a little better scheduling between tasks.
  • Loading branch information
wasabii committed Oct 17, 2023
1 parent 351f547 commit 93736d9
Show file tree
Hide file tree
Showing 8 changed files with 322 additions and 77 deletions.
154 changes: 128 additions & 26 deletions src/IKVM.MSBuild.Tasks/IkvmCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,63 @@ public class IkvmCompiler : IkvmToolExecTask
[Required]
public string Output { get; set; }

/// <summary>
/// Name of the assembly to output.
/// </summary>
public string Assembly { get; set; }

/// <summary>
/// Version of the assembly to output.
/// </summary>
public string Version { get; set; }

/// <summary>
/// Target type of the assembly to output.
/// </summary>
public string Target { get; set; }

/// <summary>
/// Platform of the assembly to output.
/// </summary>
public string Platform { get; set; }

/// <summary>
/// Key file with which to strong name the generated assembly.
/// </summary>
public string KeyFile { get; set; }

/// <summary>
/// Key with which to strong name the generated assembly.
/// </summary>
public string Key { get; set; }

public bool DelaySign { get; set; }

/// <summary>
/// References to use when compiling.
/// </summary>
public ITaskItem[] References { get; set; }

public ITaskItem[] Recurse { get; set; }

/// <summary>
/// Path to class exclusion file.
/// </summary>
public string Exclude { get; set; }

/// <summary>
/// File version of assembly to output.
/// </summary>
public string FileVersion { get; set; }

/// <summary>
/// Path to the Win32 icon file.
/// </summary>
public string Win32Icon { get; set; }

/// <summary>
/// Path to the Win32 manifest file.
/// </summary>
public string Win32Manifest { get; set; }

public ITaskItem[] Resources { get; set; }
Expand Down Expand Up @@ -123,19 +156,88 @@ public class IkvmCompiler : IkvmToolExecTask

public bool Static { get; set; }

/// <summary>
/// Paths to the assembly attributes file.
/// </summary>
public ITaskItem[] AssemblyAttributes { get; set; }

/// <summary>
/// Path to the IKVM.Runtime assembly to incorporate.
/// </summary>
public string Runtime { get; set; }

public string JNI { get; set; }

public string WarningLevel { get; set; }

public bool NoParameterReflection { get; set; }

/// <summary>
/// Path to the map.xml file to use.
/// </summary>
public string Remap { get; set; }

string GetAbsolutePathIfNotNull(string path) => path != null ? Path.GetFullPath(path) : null;
public override bool Execute()
{
if (ResponseFile != null)
ResponseFile = Path.GetFullPath(ResponseFile);

if (Output != null)
Output = Path.GetFullPath(Output);

if (KeyFile != null)
KeyFile = Path.GetFullPath(KeyFile);

if (References != null)
foreach (var reference in References)
if (reference.ItemSpec != null)
reference.ItemSpec = Path.GetFullPath(reference.ItemSpec);

if (Lib != null)
foreach (var lib in Lib)
if (lib.ItemSpec != null)
lib.ItemSpec = Path.GetFullPath(lib.ItemSpec);

if (Resources != null)
foreach (var i in Resources)
if (i.ItemSpec != null)
i.ItemSpec = Path.GetFullPath(i.ItemSpec);

if (ExternalResources != null)
foreach (var i in ExternalResources)
if (i.ItemSpec != null)
i.ItemSpec = Path.GetFullPath(i.ItemSpec);

if (AssemblyAttributes != null)
foreach (var i in AssemblyAttributes)
if (i.ItemSpec != null)
i.ItemSpec = Path.GetFullPath(i.ItemSpec);

if (Runtime != null)
Runtime = Path.GetFullPath(Runtime);

if (Remap != null)
Remap = Path.GetFullPath(Remap);

if (Input != null)
foreach (var i in Input)
if (i.ItemSpec != null)
i.ItemSpec = Path.GetFullPath(i.ItemSpec);

if (Recurse != null)
foreach (var i in Recurse)
if (i.ItemSpec != null)
i.ItemSpec = Path.GetFullPath(i.ItemSpec);

if (Exclude != null)
Exclude = Path.GetFullPath(Exclude);

if (Win32Icon != null)
Win32Icon = Path.GetFullPath(Win32Icon);

if (Win32Manifest != null)
Win32Manifest = Path.GetFullPath(Win32Manifest);

return base.Execute();
}

protected override async Task<bool> ExecuteAsync(IkvmToolTaskDiagnosticWriter writer, CancellationToken cancellationToken)
{
Expand All @@ -146,8 +248,8 @@ protected override async Task<bool> ExecuteAsync(IkvmToolTaskDiagnosticWriter wr
}

var options = new IkvmImporterOptions();
options.ResponseFile = GetAbsolutePathIfNotNull(ResponseFile);
options.Output = GetAbsolutePathIfNotNull(Output);
options.ResponseFile = ResponseFile;
options.Output = Output;
options.Assembly = Assembly;
options.Version = Version;

Expand All @@ -173,16 +275,16 @@ protected override async Task<bool> ExecuteAsync(IkvmToolTaskDiagnosticWriter wr
_ => throw new NotImplementedException(),
};

options.KeyFile = GetAbsolutePathIfNotNull(KeyFile);
options.KeyFile = KeyFile;
options.Key = Key;
options.DelaySign = DelaySign;

if (References is not null)
foreach (var reference in References.Select(i => GetAbsolutePathIfNotNull(i.ItemSpec)))
if (options.References.Contains(reference) == false)
options.References.Add(reference);
if (References != null)
foreach (var reference in References)
if (options.References.Contains(reference.ItemSpec) == false)
options.References.Add(reference.ItemSpec);

if (Recurse is not null)
if (Recurse != null)
foreach (var recurse in Recurse)
options.Recurse.Add(recurse.ItemSpec);

Expand All @@ -193,11 +295,11 @@ protected override async Task<bool> ExecuteAsync(IkvmToolTaskDiagnosticWriter wr

if (Resources is not null)
foreach (var resource in Resources)
options.Resources.Add(new IkvmImporterResourceItem(GetAbsolutePathIfNotNull(resource.ItemSpec), resource.GetMetadata("ResourcePath")));
options.Resources.Add(new IkvmImporterResourceItem(resource.ItemSpec, resource.GetMetadata("ResourcePath")));

if (ExternalResources is not null)
foreach (var resource in ExternalResources)
options.ExternalResources.Add(new IkvmImporterExternalResourceItem(GetAbsolutePathIfNotNull(resource.ItemSpec), resource.GetMetadata("ResourcePath")));
options.ExternalResources.Add(new IkvmImporterExternalResourceItem(resource.ItemSpec, resource.GetMetadata("ResourcePath")));

options.CompressResources = CompressResources;
options.Debug = Debug;
Expand All @@ -208,13 +310,13 @@ protected override async Task<bool> ExecuteAsync(IkvmToolTaskDiagnosticWriter wr
options.RemoveAssertions = RemoveAssertions;
options.StrictFinalFieldSemantics = StrictFinalFieldSemantics;

if (NoWarn is not null)
if (NoWarn != null)
foreach (var i in NoWarn.Split(';'))
options.NoWarn.Add(i);

options.WarnAsError = WarnAsError;

if (WarnAsErrorWarnings is not null)
if (WarnAsErrorWarnings != null)
foreach (var i in WarnAsErrorWarnings.Split(';'))
options.WarnAsErrorWarnings.Add(i);

Expand All @@ -223,21 +325,21 @@ protected override async Task<bool> ExecuteAsync(IkvmToolTaskDiagnosticWriter wr
options.SrcPath = SrcPath;
options.Apartment = Apartment;

if (SetProperties is not null)
if (SetProperties != null)
foreach (var p in SetProperties.Split(new[] { ';' }).Select(i => i.Split(new[] { '=' }, 2)))
options.SetProperties[p[0]] = p.Length == 2 ? p[1] : "";

options.NoStackTraceInfo = NoStackTraceInfo;

if (XTrace is not null)
if (XTrace != null)
foreach (var i in XTrace.Split(';'))
options.XTrace.Add(i);

if (XMethodTrace is not null)
if (XMethodTrace != null)
foreach (var i in XMethodTrace.Split(';'))
options.XMethodTrace.Add(i);

if (PrivatePackages is not null)
if (PrivatePackages != null)
foreach (var i in PrivatePackages.Split(';'))
options.PrivatePackages.Add(i);

Expand All @@ -248,29 +350,29 @@ protected override async Task<bool> ExecuteAsync(IkvmToolTaskDiagnosticWriter wr
options.NoPeerCrossReference = NoPeerCrossReference;
options.NoStdLib = NoStdLib;

if (Lib is not null)
if (Lib != null)
foreach (var i in Lib)
options.Lib.Add(GetAbsolutePathIfNotNull(i.ItemSpec));
options.Lib.Add(i.ItemSpec);

options.HighEntropyVA = HighEntropyVA;
options.Static = Static;

if (AssemblyAttributes is not null)
if (AssemblyAttributes != null)
foreach (var i in AssemblyAttributes)
options.AssemblyAttributes.Add(i.ItemSpec);

options.Runtime = GetAbsolutePathIfNotNull(Runtime);
options.Runtime = Runtime;

if (options.WarningLevel is not null)
if (options.WarningLevel != null)
options.WarningLevel = int.Parse(WarningLevel);

options.NoParameterReflection = NoParameterReflection;
options.Remap = GetAbsolutePathIfNotNull(Remap);
options.Remap = Remap;
options.NoLogo = true;

if (Input != null)
foreach (var i in Input)
options.Input.Add(GetAbsolutePathIfNotNull(i.ItemSpec));
options.Input.Add(i.ItemSpec);

// kick off the launcher with the configured options
return await new IkvmImporterLauncher(ToolPath, writer).ExecuteAsync(options, cancellationToken) == 0;
Expand Down
24 changes: 23 additions & 1 deletion src/IKVM.MSBuild.Tasks/IkvmExporter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading;
using System.IO;
using System.Threading;
using System.Threading.Tasks;

using IKVM.Tools.Runner.Exporter;
Expand Down Expand Up @@ -59,6 +60,27 @@ public class IkvmExporter : IkvmToolExecTask

public bool Bootstrap { get; set; }

public override bool Execute()
{
if (Input != null)
Input = Path.GetFullPath(Input);

if (Output != null)
Output = Path.GetFullPath(Output);

if (References != null)
foreach (var i in References)
if (i.ItemSpec != null)
i.ItemSpec = Path.GetFullPath(i.ItemSpec);

if (Lib != null)
foreach (var i in Lib)
if (i.ItemSpec != null)
i.ItemSpec = Path.GetFullPath(i.ItemSpec);

return base.Execute();
}

protected override async Task<bool> ExecuteAsync(IkvmToolTaskDiagnosticWriter writer, CancellationToken cancellationToken)
{
var options = new IkvmExporterOptions();
Expand Down
Loading

0 comments on commit 93736d9

Please sign in to comment.