Skip to content

Commit

Permalink
Merge branch 'hotfix/8.4.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
wasabii committed Feb 7, 2023
2 parents 103f784 + 66c1b7e commit 5484303
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 39 deletions.
27 changes: 15 additions & 12 deletions src/IKVM.MSBuild.Tasks/IkvmCompiler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
Expand Down Expand Up @@ -135,6 +136,8 @@ public class IkvmCompiler : IkvmToolExecTask

public string Remap { get; set; }

string GetAbsolutePathIfNotNull(string path) => path != null ? Path.GetFullPath(path) : null;

protected override async Task<bool> ExecuteAsync(IkvmToolTaskDiagnosticWriter writer, CancellationToken cancellationToken)
{
if (Debug && RuntimeInformation.IsOSPlatform(OSPlatform.Windows) == false)
Expand All @@ -144,8 +147,8 @@ protected override async Task<bool> ExecuteAsync(IkvmToolTaskDiagnosticWriter wr
}

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

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

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

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

if (Recurse is not null)
foreach (var recurse in Recurse)
Expand All @@ -191,11 +194,11 @@ protected override async Task<bool> ExecuteAsync(IkvmToolTaskDiagnosticWriter wr

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

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

options.CompressResources = CompressResources;
options.Debug = Debug;
Expand Down Expand Up @@ -248,7 +251,7 @@ protected override async Task<bool> ExecuteAsync(IkvmToolTaskDiagnosticWriter wr

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

options.HighEntropyVA = HighEntropyVA;
options.Static = Static;
Expand All @@ -257,17 +260,17 @@ protected override async Task<bool> ExecuteAsync(IkvmToolTaskDiagnosticWriter wr
foreach (var i in AssemblyAttributes)
options.AssemblyAttributes.Add(i.ItemSpec);

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

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

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

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

// kick off the launcher with the configured options
return await new IkvmCompilerLauncher(ToolPath, writer).ExecuteAsync(options, cancellationToken) == 0;
Expand Down
2 changes: 1 addition & 1 deletion src/IKVM.MSBuild.Tasks/IkvmToolExecTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public override bool Execute()
log = new StreamWriter(File.OpenWrite(LogFile));

// kick off the launcher with the configured options
var run = System.Threading.Tasks.Task.Run(() => ExecuteAsync(new IkvmToolTaskDiagnosticWriter(Log, log), CancellationToken.None));
var run = ExecuteAsync(new IkvmToolTaskDiagnosticWriter(Log, log), CancellationToken.None);

// yield and wait for the task to complete
BuildEngine3.Yield();
Expand Down
48 changes: 27 additions & 21 deletions src/IKVM.MSBuild.Tasks/IkvmToolTaskDiagnosticWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,34 @@ public IkvmToolTaskDiagnosticWriter(Microsoft.Build.Utilities.TaskLoggingHelper
/// <returns></returns>
public Task ReceiveAsync(IkvmToolDiagnosticEvent @event)
{
switch (@event.Level)
if (@event == null)
return Task.CompletedTask;

try
{
switch (@event.Level)
{
case IkvmToolDiagnosticEventLevel.Debug:
logger.LogMessage(Microsoft.Build.Framework.MessageImportance.Low, @event.Message, @event.MessageArgs);
writer?.WriteLine("DEBUG: " + @event.Message, @event.MessageArgs);
break;
case IkvmToolDiagnosticEventLevel.Information:
logger.LogMessage(Microsoft.Build.Framework.MessageImportance.Normal, @event.Message, @event.MessageArgs);
writer?.WriteLine("INFO: " + @event.Message, @event.MessageArgs);
break;
case IkvmToolDiagnosticEventLevel.Warning:
logger.LogWarning(@event.Message, @event.MessageArgs);
writer?.WriteLine("WARN: " + @event.Message, @event.MessageArgs);
break;
case IkvmToolDiagnosticEventLevel.Error:
logger.LogWarning(@event.Message, @event.MessageArgs);
writer?.WriteLine("ERROR: " + @event.Message, @event.MessageArgs);
break;
}
}
catch (Exception e)
{
case IkvmToolDiagnosticEventLevel.Debug:
logger.LogMessage(Microsoft.Build.Framework.MessageImportance.Low, @event.Message, @event.MessageArgs);
if (writer != null)
writer.WriteLine("DEBUG: " + @event.Message, @event.MessageArgs);
break;
case IkvmToolDiagnosticEventLevel.Information:
logger.LogMessage(Microsoft.Build.Framework.MessageImportance.Normal, @event.Message, @event.MessageArgs);
if (writer != null)
writer.WriteLine("INFO: " + @event.Message, @event.MessageArgs);
break;
case IkvmToolDiagnosticEventLevel.Warning:
logger.LogWarning(@event.Message, @event.MessageArgs);
if (writer != null)
writer.WriteLine("WARN: " + @event.Message, @event.MessageArgs);
break;
case IkvmToolDiagnosticEventLevel.Error:
logger.LogWarning(@event.Message, @event.MessageArgs);
if (writer != null)
writer.WriteLine("ERROR: " + @event.Message, @event.MessageArgs);
break;
// ignore failure to log, not much we can do
}

return Task.CompletedTask;
Expand Down
11 changes: 6 additions & 5 deletions src/IKVM.Tools.Runner/Compiler/IkvmCompilerLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public IkvmCompilerLauncher(string toolPath) :
/// <param name="options"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
/// <exception cref="NullReferenceException"></exception>
public async Task<int> ExecuteAsync(IkvmCompilerOptions options, CancellationToken cancellationToken = default)
{
if (options is null)
Expand Down Expand Up @@ -248,15 +247,17 @@ public async Task<int> ExecuteAsync(IkvmCompilerOptions options, CancellationTok
foreach (var i in options.Input)
w.WriteLine(i);

// path to the temporary response file
var response = (string)null;
// prepare path to response file
var response = string.IsNullOrWhiteSpace(options.ResponseFile) == false ? Path.GetFullPath(options.ResponseFile) : Path.GetTempFileName();

// to cancel the executable
var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, new CancellationToken());

try
{
// create response file
response = options.ResponseFile ?? Path.GetTempFileName();
File.WriteAllText(response, w.ToString());
Directory.CreateDirectory(Path.GetDirectoryName(response));
File.WriteAllText(options.ResponseFile, w.ToString());

// locate EXE file
var exe = GetToolExe();
Expand Down

0 comments on commit 5484303

Please sign in to comment.