Skip to content

Commit

Permalink
Merge pull request #478 from ikvmnet/ilgen2
Browse files Browse the repository at this point in the history
IKVM.Reflection ILGenerator/PDB Rewrite
  • Loading branch information
wasabii authored Feb 22, 2024
2 parents 6d16ad4 + 4b06d88 commit 9838f96
Show file tree
Hide file tree
Showing 132 changed files with 8,207 additions and 5,385 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/IKVM.yml
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,8 @@ jobs:
"-v:diag",
"--results-directory", "TestResults",
"--logger:console;verbosity=diag",
"--logger:trx",
"--collect", "Code Coverage"
"--logger:trx"
# "--collect", "Code Coverage"
)
$runsettings = $(gi .\tests\$tst\$tfm\*.runsettings)
Expand Down
5 changes: 5 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
<Import Project="targets\ClangProjectReference.targets" />
<Import Project="targets\DotNetOSXCodeSign.targets"/>

<PropertyGroup>
<RuntimeIdentifier Condition=" '$(RuntimeIdentifier)' == 'win7-x86' ">win-x86</RuntimeIdentifier>
<RuntimeIdentifier Condition=" '$(RuntimeIdentifier)' == 'win7-x64' ">win-x64</RuntimeIdentifier>
<Prefer32Bit Condition=" '$(RuntimeIdentifier)' == 'win-x86' ">true</Prefer32Bit>
</PropertyGroup>
</Project>
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ The output assembly will be generated as part of your project's build process an
<Sources>MyClass.java;YourClass.java</Sources>
<References>SomeExternalDependency.jar;SomeOtherExternalDependency.jar</References>
<Aliases>MyAssemblyAlias;helloworld2_0</Aliases>
<Debug>true</Debug>
<Debug>portable</Debug>
</IkvmReference>
</ItemGroup>
```
Expand All @@ -139,7 +139,7 @@ The following values can be used as either an attribute or a nested element of `
| `Compile` | A semi-colon separated list of Java class path items to compile into the assembly. By default this value is the `Identity` of the item, if the identity of the item is an existing JAR file or directory (not yet supported). MSBuild globs are supported to reference multiple JAR or .class files. |
| `Sources` | A semi-colon separated list of Java source files to use during documentation generation. (not yet supported) |
| `References` | Optional semi-colon separated list of other `IkvmReference` identity values to specify as a reference to the current one. For example, if `foo.jar` depends on `bar.jar`, include both as `IkvmReference` items, but specify the identity of `bar.jar` on the `References` metadata of `foo.jar`. |
| `Debug` | Optional boolean indicating whether to generate debug symbols. By default this is determined based on the `<DebugType>` and `<DebugSymbols>` properties of the project. Only full debug symbols are currently supported. |
| `Debug` | Optional value indicating how to generate debug symbols. By default this is determined based on the `<DebugType>` properties of the project. Only full debug symbols are currently supported. |
| `Aliases` | A semi-colon separated list of aliases that can be used to reference the assembly in `References`. |
| `ClassLoader` | A fully qualified classs name of the custom ClassLoader implementation to use as a delegation parent. Examples include `ikvm.runtime.AppDomainAssemblyClassLoader` and `ikvm.runtime.ClassPathAssemblyClassLoader`. |
| All other metadata supported on the [`Reference`](https://docs.microsoft.com/en-us/visualstudio/msbuild/common-msbuild-project-items#reference) MSBuild item group definition. | |
Expand Down
2 changes: 1 addition & 1 deletion src/IKVM.ConsoleApp/IKVM.ConsoleApp.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net481;net6.0</TargetFrameworks>
<TargetFrameworks>net6.0;net481;</TargetFrameworks>
<LangVersion>11</LangVersion>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
Expand Down
7 changes: 1 addition & 6 deletions src/IKVM.ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;

namespace IKVM.ConsoleApp
{
Expand All @@ -13,7 +14,6 @@ public static void Main(string[] args)
public static void Foo()
{
new Bar();
Environment.Exit(0);
}

class Bar
Expand All @@ -25,11 +25,6 @@ public Bar()
System.Console.WriteLine(java.net.InetAddress.getLocalHost().getHostName());
}

~Bar()
{

}

}

}
Expand Down
16 changes: 16 additions & 0 deletions src/IKVM.Java.Tests/java/lang/ThreadTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ikvm.tests.java.java.lang;

import java.lang.*;
import java.util.*;

@cli.Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute.Annotation()
public class ThreadTests {

@cli.Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute.Annotation()
public void canPrintStackTrace() throws Throwable {
for (StackTraceElement ste : Thread.currentThread().getStackTrace()) {
System.out.println(ste + "\n");
}
}

}
35 changes: 27 additions & 8 deletions src/IKVM.Java/map.xml
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,8 @@
<field name="suppressedExceptions" sig="Ljava.util.List;" />
<clinit>
<body>
<call type="IKVM.Runtime.ExceptionHelper" name="GetPersistentFields" sig="()[Ljava.io.ObjectStreamField;" />
<call class="cli.IKVM.Runtime.ExceptionHelper" name="GetPersistentFields" sig="()[Ljava.lang.Object;" />
<castclass class="[Ljava.io.ObjectStreamField;" />
<stsfld class="java.lang.Throwable" name="serialPersistentFields" sig="[Ljava.io.ObjectStreamField;" />
<ldc_i4_0 />
<newarr sig="Ljava.lang.StackTraceElement;" />
Expand Down Expand Up @@ -1010,7 +1011,7 @@
<body>
<ldarg_0 />
<ldarg_1 />
<call type="IKVM.Runtime.ExceptionHelper" name="ReadObject" sig="(Ljava.lang.Throwable;Ljava.io.ObjectInputStream;)V" />
<call class="cli.IKVM.Runtime.ExceptionHelper" name="ReadObject" sig="(Ljava.lang.Throwable;Ljava.lang.Object;)V" />
<ret />
</body>
</method>
Expand All @@ -1019,7 +1020,7 @@
<body>
<ldarg_0 />
<ldarg_1 />
<call type="IKVM.Runtime.ExceptionHelper" name="WriteObject" sig="(Ljava.lang.Throwable;Ljava.io.ObjectOutputStream;)V" />
<call class="cli.IKVM.Runtime.ExceptionHelper" name="WriteObject" sig="(Ljava.lang.Throwable;Ljava.lang.Object;)V" />
<ret />
</body>
</method>
Expand Down Expand Up @@ -1341,18 +1342,29 @@
<method name="getStackTrace" sig="()[Ljava.lang.StackTraceElement;" modifiers="public">
<body>
<ldarg_0 />
<call type="IKVM.Runtime.ExceptionHelper" name="GetOurStackTrace" sig="(Ljava.lang.Throwable;)[Ljava.lang.StackTraceElement;" />
<call class="cli.IKVM.Runtime.ExceptionHelper" name="GetOurStackTrace" sig="(Ljava.lang.Throwable;)[Ljava.lang.Object;" />
<castclass class="[Ljava.lang.StackTraceElement;" />
<callvirt type="System.Array" name="Clone" sig="()Ljava.lang.Object;" />
<castclass class="[Ljava.lang.StackTraceElement;" />
<ret />
</body>
</method>
<method name="getOurStackTrace" sig="()[Ljava.lang.StackTraceElement;" modifiers="private">
<redirect class="cli.IKVM.Runtime.ExceptionHelper" name="GetOurStackTrace" sig="(Ljava.lang.Throwable;)[Ljava.lang.StackTraceElement;" />
<body>
<ldarg_0 />
<call class="cli.IKVM.Runtime.ExceptionHelper" name="GetOurStackTrace" sig="(Ljava.lang.Throwable;)[Ljava.lang.Object;" />
<castclass class="[Ljava.lang.StackTraceElement;" />
<ret />
</body>
</method>
<method name="setStackTrace" sig="([Ljava.lang.StackTraceElement;)V" modifiers="public">
<parameter name="stackTrace" />
<redirect class="cli.IKVM.Runtime.ExceptionHelper" name="SetStackTrace" sig="(Ljava.lang.Throwable;[Ljava.lang.StackTraceElement;)V" />
<body>
<ldarg_0 />
<ldarg_1 />
<call class="cli.IKVM.Runtime.ExceptionHelper" name="SetStackTrace" sig="(Ljava.lang.Throwable;[Ljava.lang.Object;)V" />
<ret/>
</body>
</method>
<method name="toString" sig="()Ljava.lang.String;" modifiers="public">
<redirect class="cli.IKVM.Runtime.ExceptionHelper" name="ToString" sig="(Ljava.lang.Throwable;)Ljava.lang.String;" />
Expand Down Expand Up @@ -1398,14 +1410,21 @@
<redirect class="cli.IKVM.Runtime.ExceptionHelper" name="GetStackTraceDepth" sig="(Ljava.lang.Throwable;)I" />
</method>
<method name="getStackTraceElement" sig="(I)Ljava.lang.StackTraceElement;" modifiers="">
<redirect class="cli.IKVM.Runtime.ExceptionHelper" name="GetStackTraceElement" sig="(Ljava.lang.Throwable;I)Ljava.lang.StackTraceElement;" />
<body>
<ldarg_0 />
<ldarg_1 />
<call class="cli.IKVM.Runtime.ExceptionHelper" name="GetStackTraceElement" sig="(Ljava.lang.Throwable;I)Ljava.lang.Object;" />
<castclass class="java.lang.StackTraceElement" />
<ret />
</body>
</method>
</class>
<class name="java.lang.ThrowableHelper">
<method name="getOurStackTrace" sig="(Ljava.lang.Throwable;)[Ljava.lang.StackTraceElement;">
<body>
<ldarg_0 />
<call type="IKVM.Runtime.ExceptionHelper" name="GetOurStackTrace" sig="(Ljava.lang.Throwable;)[Ljava.lang.StackTraceElement;" />
<call class="cli.IKVM.Runtime.ExceptionHelper" name="GetOurStackTrace" sig="(Ljava.lang.Throwable;)[Ljava.lang.Object;" />
<castclass class="[Ljava.lang.StackTraceElement;" />
<ret />
</body>
</method>
Expand Down
19 changes: 11 additions & 8 deletions src/IKVM.MSBuild.Tasks/IkvmCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public class IkvmCompiler : IkvmToolExecTask

public bool CompressResources { get; set; }

public bool Debug { get; set; }
public string Debug { get; set; }

public bool NoAutoSerialization { get; set; }

Expand Down Expand Up @@ -241,12 +241,6 @@ public override bool Execute()

protected override async Task<bool> ExecuteAsync(IkvmToolTaskDiagnosticWriter writer, CancellationToken cancellationToken)
{
if (Debug && RuntimeInformation.IsOSPlatform(OSPlatform.Windows) == false)
{
Log.LogWarning("Emitting debug symbols from ikvmc is not supported on platforms other than Windows. Continuing without.");
Debug = false;
}

var options = new IkvmImporterOptions();
options.ResponseFile = ResponseFile;
options.Output = Output;
Expand Down Expand Up @@ -302,7 +296,16 @@ protected override async Task<bool> ExecuteAsync(IkvmToolTaskDiagnosticWriter wr
options.ExternalResources.Add(new IkvmImporterExternalResourceItem(resource.ItemSpec, resource.GetMetadata("ResourcePath")));

options.CompressResources = CompressResources;
options.Debug = Debug;

options.Debug = Debug?.ToLower() switch
{
"none" or "" or null => IkvmImporterDebugMode.None,
"portable" => IkvmImporterDebugMode.Portable,
"full" or "pdbonly" => IkvmImporterDebugMode.Full,
"embedded" => IkvmImporterDebugMode.Embedded,
_ => throw new NotImplementedException($"Unknown Debug option '{Debug}'.")
};

options.NoAutoSerialization = NoAutoSerialization;
options.NoGlobbing = NoGlobbing;
options.NoJNI = NoJNI;
Expand Down
36 changes: 33 additions & 3 deletions src/IKVM.MSBuild.Tasks/IkvmReferenceItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static IkvmReferenceItem[] Import(IEnumerable<ITaskItem> items)
item.References = ResolveReferences(map, item, item.Item.GetMetadata(IkvmReferenceItemMetadata.References)).ToList();
item.ClassLoader = item.Item.GetMetadata(IkvmReferenceItemMetadata.ClassLoader);
item.ResolvedReferences = item.Item.GetMetadata(IkvmReferenceItemMetadata.ResolvedReferences)?.Split(IkvmReferenceItemMetadata.PropertySeperatorCharArray, StringSplitOptions.RemoveEmptyEntries).ToList();
item.Debug = string.Equals(item.Item.GetMetadata(IkvmReferenceItemMetadata.Debug), "true", StringComparison.OrdinalIgnoreCase);
item.Debug = ParseDebug(item.Item.GetMetadata(IkvmReferenceItemMetadata.Debug));
item.KeyFile = item.Item.GetMetadata(IkvmReferenceItemMetadata.KeyFile);
item.DelaySign = string.Equals(item.Item.GetMetadata(IkvmReferenceItemMetadata.DelaySign), "true", StringComparison.OrdinalIgnoreCase);
item.Aliases = item.Item.GetMetadata(IkvmReferenceItemMetadata.Aliases);
Expand All @@ -79,6 +79,21 @@ public static IkvmReferenceItem[] Import(IEnumerable<ITaskItem> items)
return map.Values.ToArray();
}

/// <summary>
/// Parses the debug metadata value into the enum.
/// </summary>
/// <param name="debug"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
static IkvmReferenceItemDebug ParseDebug(string debug) => debug?.ToLower() switch
{
"none" or "false" or "" or null => IkvmReferenceItemDebug.None,
"full" or "true" => IkvmReferenceItemDebug.Full,
"portable" => IkvmReferenceItemDebug.Portable,
"embedded" => IkvmReferenceItemDebug.Embedded,
_ => IkvmReferenceItemDebug.None
};

/// <summary>
/// Attempts to resolve the references given by the reference string <paramref name="references"/> for
/// <paramref name="item"/> against <paramref name="map"/>.
Expand Down Expand Up @@ -229,7 +244,7 @@ public IkvmReferenceItem(ITaskItem item)
/// <summary>
/// Compile in debug mode.
/// </summary>
public bool Debug { get; set; }
public IkvmReferenceItemDebug Debug { get; set; }

/// <summary>
/// Path to the file to sign the assembly.
Expand Down Expand Up @@ -279,14 +294,29 @@ public void Save()
Item.SetMetadata(IkvmReferenceItemMetadata.StagePath, StagePath);
Item.SetMetadata(IkvmReferenceItemMetadata.StageSymbolsPath, StageSymbolsPath);
Item.SetMetadata(IkvmReferenceItemMetadata.Aliases, Aliases);
Item.SetMetadata(IkvmReferenceItemMetadata.Debug, Debug ? "true" : "false");
Item.SetMetadata(IkvmReferenceItemMetadata.Debug, ToString(Debug));
Item.SetMetadata(IkvmReferenceItemMetadata.KeyFile, KeyFile);
Item.SetMetadata(IkvmReferenceItemMetadata.DelaySign, DelaySign ? "true" : "false");
Item.SetMetadata(IkvmReferenceItemMetadata.Private, Private ? "true" : "false");
Item.SetMetadata(IkvmReferenceItemMetadata.ReferenceOutputAssembly, ReferenceOutputAssembly ? "true" : "false");
Item.SetMetadata(IkvmReferenceItemMetadata.ResolvedReferences, string.Join(IkvmReferenceItemMetadata.PropertySeperatorString, ResolvedReferences));
}

/// <summary>
/// Converts the enum value to a string.
/// </summary>
/// <param name="debug"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
string ToString(IkvmReferenceItemDebug debug) => debug switch
{
IkvmReferenceItemDebug.None => "none",
IkvmReferenceItemDebug.Full => "full",
IkvmReferenceItemDebug.Portable => "portable",
IkvmReferenceItemDebug.Embedded => "embedded",
_ => throw new NotImplementedException(),
};

}

}
14 changes: 14 additions & 0 deletions src/IKVM.MSBuild.Tasks/IkvmReferenceItemDebug.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace IKVM.MSBuild.Tasks
{

enum IkvmReferenceItemDebug
{

None,
Full,
Portable,
Embedded,

}

}
2 changes: 1 addition & 1 deletion src/IKVM.MSBuild.Tasks/IkvmReferenceItemPrepare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ internal async Task<string> CalculateIkvmIdentityAsync(IkvmReferenceItem item, C
manifest.WriteLine("AssemblyVersion={0}", item.AssemblyVersion);
manifest.WriteLine("AssemblyFileVersion={0}", item.AssemblyFileVersion);
manifest.WriteLine("ClassLoader={0}", item.ClassLoader);
manifest.WriteLine("Debug={0}", item.Debug ? "true" : "false");
manifest.WriteLine("Debug={0}", Enum.GetName(typeof(IkvmReferenceItemDebug), item.Debug));
manifest.WriteLine("KeyFile={0}", string.IsNullOrWhiteSpace(item.KeyFile) == false ? await fileIdentityUtil.GetIdentityForFileAsync(item.KeyFile, Log, cancellationToken) : "");
manifest.WriteLine("DelaySign={0}", item.DelaySign ? "true" : "false");

Expand Down
2 changes: 1 addition & 1 deletion src/IKVM.MSBuild.Tests/IKVM.MSBuild.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.8.0" />
<PackageReference Include="Buildalyzer" Version="5.0.1" />
<PackageReference Include="Buildalyzer" Version="6.0.4" />
<PackageReference Include="Microsoft.CodeCoverage" Version="17.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
Expand Down
2 changes: 1 addition & 1 deletion src/IKVM.MSBuild.Tests/Project/global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "7.0.0",
"version": "7.0.100",
"rollForward": "latestFeature"
}
}
Loading

0 comments on commit 9838f96

Please sign in to comment.