Skip to content

Commit

Permalink
Merge pull request #469 from ikvmnet/srm
Browse files Browse the repository at this point in the history
Use System.Reflection.Metadata to write assemblies in IKVM.Reflection. Enable win-arm64 Framework tools and images.
  • Loading branch information
wasabii authored Jan 15, 2024
2 parents 65226ff + 1dff302 commit 233bb20
Show file tree
Hide file tree
Showing 132 changed files with 3,294 additions and 5,931 deletions.
12 changes: 6 additions & 6 deletions IKVM.sln
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IKVM.MSBuild.Tasks.Tests", "src\IKVM.MSBuild.Tasks.Tests\IKVM.MSBuild.Tasks.Tests.csproj", "{E7C0E8FA-F34C-48C6-AD55-FD9798F5BC71}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IKVM.Java", "src\IKVM.Java\IKVM.Java.msbuildproj", "{ABD81C7E-F986-4018-986E-ACAF82C64D3A}"
ProjectSection(ProjectDependencies) = postProject
{0A87FF49-AC9D-479A-ACBB-F4028A0BE1F7} = {0A87FF49-AC9D-479A-ACBB-F4028A0BE1F7}
{17979A73-C0CE-41CD-B54F-4E72B998E6D0} = {17979A73-C0CE-41CD-B54F-4E72B998E6D0}
{2F29E48C-63C3-4E47-BCBA-A7454B9119CF} = {2F29E48C-63C3-4E47-BCBA-A7454B9119CF}
{50954AE0-E513-4CE7-AC8E-F3896CA0BEB7} = {50954AE0-E513-4CE7-AC8E-F3896CA0BEB7}
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IKVM.NET.Sdk", "src\IKVM.NET.Sdk\IKVM.NET.Sdk.msbuildproj", "{704BD7C7-7746-4D72-A86E-ECFE7BBD80CC}"
EndProject
Expand Down Expand Up @@ -325,6 +319,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IKVM.Image.runtime.win-arm6
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IKVM.Reflection.Tests", "src\IKVM.Reflection.Tests\IKVM.Reflection.Tests.csproj", "{17755A44-22EC-4D28-B219-3C5CAE6317C8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IKVM.Java.Tests.Util", "src\IKVM.Java.Tests.Util\IKVM.Java.Tests.Util.csproj", "{00AFE142-5F4F-48DD-90C1-20CC0512C43C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -803,6 +799,10 @@ Global
{17755A44-22EC-4D28-B219-3C5CAE6317C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{17755A44-22EC-4D28-B219-3C5CAE6317C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{17755A44-22EC-4D28-B219-3C5CAE6317C8}.Release|Any CPU.Build.0 = Release|Any CPU
{00AFE142-5F4F-48DD-90C1-20CC0512C43C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{00AFE142-5F4F-48DD-90C1-20CC0512C43C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{00AFE142-5F4F-48DD-90C1-20CC0512C43C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{00AFE142-5F4F-48DD-90C1-20CC0512C43C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<IncludeSymbols>false</IncludeSymbols>
<ImageRuntimeIdentifier>win-arm64</ImageRuntimeIdentifier>
<ImageBinProject>..\IKVM.Image.JDK-bin\IKVM.Image.JDK-bin.csproj</ImageBinProject>
<SupportedImageTargetFrameworks>net6.0</SupportedImageTargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
<RuntimeIdentifier>win-arm64</RuntimeIdentifier>
<ImagePath>%(RecursiveDir)%(FileName)%(Extension)</ImagePath>
</IkvmImageItem>
<IkvmImageItem Include="$(MSBuildThisFileDirectory)..\ikvm\net472\win-arm64\**\*">
<TargetFramework>net472</TargetFramework>
<RuntimeIdentifier>win-arm64</RuntimeIdentifier>
<ImagePath>%(RecursiveDir)%(FileName)%(Extension)</ImagePath>
</IkvmImageItem>
<IkvmImageItem Include="$(MSBuildThisFileDirectory)..\ikvm\net6.0\win-arm64\**\*">
<TargetFramework>net6.0</TargetFramework>
<RuntimeIdentifier>win-arm64</RuntimeIdentifier>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<IncludeSymbols>false</IncludeSymbols>
<ImageRuntimeIdentifier>win-arm64</ImageRuntimeIdentifier>
<ImageBinProject>..\IKVM.Image.JRE-bin\IKVM.Image.JRE-bin.csproj</ImageBinProject>
<SupportedImageTargetFrameworks>net6.0</SupportedImageTargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
<RuntimeIdentifier>win-arm64</RuntimeIdentifier>
<ImagePath>%(RecursiveDir)%(FileName)%(Extension)</ImagePath>
</IkvmImageItem>
<IkvmImageItem Include="$(MSBuildThisFileDirectory)..\ikvm\net472\win-arm64\**\*">
<TargetFramework>net472</TargetFramework>
<RuntimeIdentifier>win-arm64</RuntimeIdentifier>
<ImagePath>%(RecursiveDir)%(FileName)%(Extension)</ImagePath>
</IkvmImageItem>
<IkvmImageItem Include="$(MSBuildThisFileDirectory)..\ikvm\net6.0\win-arm64\**\*">
<TargetFramework>net6.0</TargetFramework>
<RuntimeIdentifier>win-arm64</RuntimeIdentifier>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<IncludeSymbols>false</IncludeSymbols>
<ImageRuntimeIdentifier>win-arm64</ImageRuntimeIdentifier>
<ImageBinProject>..\IKVM.Image-bin\IKVM.Image-bin.csproj</ImageBinProject>
<SupportedImageTargetFrameworks>net6.0</SupportedImageTargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
<RuntimeIdentifier>win-arm64</RuntimeIdentifier>
<ImagePath>%(RecursiveDir)%(FileName)%(Extension)</ImagePath>
</IkvmImageItem>
<IkvmImageItem Include="$(MSBuildThisFileDirectory)..\ikvm\net472\win-arm64\**\*">
<TargetFramework>net472</TargetFramework>
<RuntimeIdentifier>win-arm64</RuntimeIdentifier>
<ImagePath>%(RecursiveDir)%(FileName)%(Extension)</ImagePath>
</IkvmImageItem>
<IkvmImageItem Include="$(MSBuildThisFileDirectory)..\ikvm\net6.0\win-arm64\**\*">
<TargetFramework>net6.0</TargetFramework>
<RuntimeIdentifier>win-arm64</RuntimeIdentifier>
Expand Down
14 changes: 14 additions & 0 deletions src/IKVM.Java.Tests.Util/IKVM.Java.Tests.Util.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472;net6.0;net7.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CliWrap" Version="3.4.1" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="16.11.0" />
<PackageReference Include="System.Reflection.Metadata" Version="8.0.0" />
</ItemGroup>

<Import Project="$(MSBuildThisFileDirectory)..\..\IKVM.deps.targets" />
<Import Project="$(MSBuildThisFileDirectory)..\..\IKVM.refs.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace IKVM.Tests.Util
namespace IKVM.Java.Tests.Util
{
/// <summary>
/// Represents a unit of code to compile.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

using javax.tools;

namespace IKVM.Tests.Util
namespace IKVM.Java.Tests.Util
{

/// <summary>
Expand Down Expand Up @@ -174,7 +174,6 @@ public override CharSequence getCharContent(bool ignoreEncodingErrors)
public InMemoryCompiler(InMemoryCodeUnit[] source)
{
this.compiler = ToolProvider.getSystemJavaCompiler() ?? throw new System.Exception();

this.units = source ?? throw new ArgumentNullException(nameof(source));
this.files = new InMemoryForwardingJavaFileManager(compiler.getStandardFileManager(null, null, null), streams);
}
Expand Down
1 change: 1 addition & 0 deletions src/IKVM.Java/IKVM.Java.msbuildproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<PropertyGroup>
<TargetFrameworks>net472;net6.0</TargetFrameworks>
<Bootstrap>true</Bootstrap>
<DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/IKVM.MSBuild.Tasks/IKVM.MSBuild.Tasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageReference Include="CliWrap" Version="3.5.0" />
<PackageReference Include="Microsoft.Build" Version="16.9.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="16.9.0" PrivateAssets="All" />
<PackageReference Include="System.Reflection.Metadata" Version="6.0.1" />
<PackageReference Include="System.Reflection.Metadata" Version="8.0.0" />
<PackageReference Include="Microsoft.NETCore.Platforms" Version="8.0.0-preview.7.23375.6" GeneratePathProperty="true" />
</ItemGroup>

Expand Down
4 changes: 4 additions & 0 deletions src/IKVM.MSBuild.Tests/ProjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,10 @@ public static void ClassCleanup()
[DataTestMethod]
[DataRow(EnvironmentPreference.Core, "net472", "win-x86", "{0}.exe", "{0}.dll")]
[DataRow(EnvironmentPreference.Core, "net472", "win-x64", "{0}.exe", "{0}.dll")]
[DataRow(EnvironmentPreference.Core, "net472", "win-arm64", "{0}.exe", "{0}.dll")]
[DataRow(EnvironmentPreference.Core, "net48", "win-x86", "{0}.exe", "{0}.dll")]
[DataRow(EnvironmentPreference.Core, "net48", "win-x64", "{0}.exe", "{0}.dll")]
[DataRow(EnvironmentPreference.Core, "net48", "win-arm64", "{0}.exe", "{0}.dll")]
[DataRow(EnvironmentPreference.Core, "net6.0", "win-x86", "{0}.exe", "{0}.dll")]
[DataRow(EnvironmentPreference.Core, "net6.0", "win-x64", "{0}.exe", "{0}.dll")]
[DataRow(EnvironmentPreference.Core, "net6.0", "win-arm64", "{0}.exe", "{0}.dll")]
Expand All @@ -169,8 +171,10 @@ public static void ClassCleanup()
[DataRow(EnvironmentPreference.Core, "net7.0", "osx-arm64", "{0}", "lib{0}.dylib")]
[DataRow(EnvironmentPreference.Framework, "net472", "win-x86", "{0}.exe", "{0}.dll")]
[DataRow(EnvironmentPreference.Framework, "net472", "win-x64", "{0}.exe", "{0}.dll")]
[DataRow(EnvironmentPreference.Framework, "net472", "win-arm64", "{0}.exe", "{0}.dll")]
[DataRow(EnvironmentPreference.Framework, "net48", "win-x86", "{0}.exe", "{0}.dll")]
[DataRow(EnvironmentPreference.Framework, "net48", "win-x64", "{0}.exe", "{0}.dll")]
[DataRow(EnvironmentPreference.Framework, "net48", "win-arm64", "{0}.exe", "{0}.dll")]
[DataRow(EnvironmentPreference.Framework, "net6.0", "win-x86", "{0}.exe", "{0}.dll")]
[DataRow(EnvironmentPreference.Framework, "net6.0", "win-x64", "{0}.exe", "{0}.dll")]
[DataRow(EnvironmentPreference.Framework, "net6.0", "win-arm64", "{0}.exe", "{0}.dll")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@
</ItemGroup>

<ItemGroup>
<PublishProjectReference Include="..\ikvmc\ikvmc.csproj">
<SetTargetFramework>TargetFramework=net472</SetTargetFramework>
<SetRuntimeIdentifier>RuntimeIdentifier=win-arm64</SetRuntimeIdentifier>
<PublishTargetPath Condition=" '$(TargetFramework)' == 'net472' ">ikvmc\net472\win-arm64</PublishTargetPath>
<CopyToOutputDirectory Condition=" '$(TargetFramework)' == 'net472' ">PreserveNewest</CopyToOutputDirectory>
<PublishPackagePath>ikvmc\net472\win-arm64</PublishPackagePath>
<Pack>true</Pack>
</PublishProjectReference>
<PublishProjectReference Include="..\ikvmstub\ikvmstub.csproj">
<SetTargetFramework>TargetFramework=net472</SetTargetFramework>
<SetRuntimeIdentifier>RuntimeIdentifier=win-arm64</SetRuntimeIdentifier>
<PublishTargetPath Condition=" '$(TargetFramework)' == 'net472' ">ikvmstub\net472\win-arm64\bin</PublishTargetPath>
<CopyToOutputDirectory Condition=" '$(TargetFramework)' == 'net472' ">PreserveNewest</CopyToOutputDirectory>
<PublishPackagePath>ikvmstub\net472\win-arm64</PublishPackagePath>
<Pack>true</Pack>
</PublishProjectReference>
<PublishProjectReference Include="..\ikvmc\ikvmc.csproj">
<SetTargetFramework>TargetFramework=net6.0</SetTargetFramework>
<SetRuntimeIdentifier>RuntimeIdentifier=win-arm64</SetRuntimeIdentifier>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
</PropertyGroup>

<ItemGroup>
<IkvmCompilerToolPath Include="$(MSBuildThisFileDirectory)..\ikvmc\net472\win-arm64\" TargetFramework="net472" RuntimeIdentifier="win-arm64" />
<IkvmCompilerToolPath Include="$(MSBuildThisFileDirectory)..\ikvmc\net6.0\win-arm64\" TargetFramework="net6.0" RuntimeIdentifier="win-arm64" />
<IkvmExporterToolPath Include="$(MSBuildThisFileDirectory)..\ikvmstub\net472\win-arm64\" TargetFramework="net472" RuntimeIdentifier="win-arm64" />
<IkvmExporterToolPath Include="$(MSBuildThisFileDirectory)..\ikvmstub\net6.0\win-arm64\" TargetFramework="net6.0" RuntimeIdentifier="win-arm64" />
</ItemGroup>

Expand Down
2 changes: 2 additions & 0 deletions src/IKVM.NET.Sdk.Tests/ProjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ public static void ClassCleanup()
[DataTestMethod]
[DataRow(EnvironmentPreference.Core, "net472", "win-x86", "{0}.exe", "{0}.dll")]
[DataRow(EnvironmentPreference.Core, "net472", "win-x64", "{0}.exe", "{0}.dll")]
[DataRow(EnvironmentPreference.Core, "net472", "win-arm64", "{0}.exe", "{0}.dll")]
[DataRow(EnvironmentPreference.Core, "net48", "win-x86", "{0}.exe", "{0}.dll")]
[DataRow(EnvironmentPreference.Core, "net48", "win-x64", "{0}.exe", "{0}.dll")]
[DataRow(EnvironmentPreference.Core, "net48", "win-arm64", "{0}.exe", "{0}.dll")]
[DataRow(EnvironmentPreference.Core, "net6.0", "win-x86", "{0}.exe", "{0}.dll")]
[DataRow(EnvironmentPreference.Core, "net6.0", "win-x64", "{0}.exe", "{0}.dll")]
[DataRow(EnvironmentPreference.Core, "net6.0", "win-arm64", "{0}.exe", "{0}.dll")]
Expand Down
28 changes: 28 additions & 0 deletions src/IKVM.Reflection.Tests/FrameworkSpec.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Collections.Generic;

namespace IKVM.Reflection.Tests
{

/// <summary>
///
/// </summary>
/// <param name="Tfm"></param>
/// <param name="TargetFrameworkIdentifier"></param>
/// <param name="TargetFrameworkVersion"></param>
public record struct FrameworkSpec(string Tfm, string TargetFrameworkIdentifier, string TargetFrameworkVersion)
{

/// <summary>
/// Individual Frameworks to test.
/// </summary>
public static IEnumerable<object[]> GetFrameworkTestData()
{
yield return new object[] { new FrameworkSpec("net472", ".NETFramework", "4.7.2") };
yield return new object[] { new FrameworkSpec("net48", ".NETFramework", "4.8") };
yield return new object[] { new FrameworkSpec("net6.0", ".NETCore", "6.0") };
yield return new object[] { new FrameworkSpec("net7.0", ".NETCore", "7.0") };
}

}

}
18 changes: 17 additions & 1 deletion src/IKVM.Reflection.Tests/IKVM.Reflection.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472;net6.0;net7.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.8.0" />
<PackageReference Include="Microsoft.CodeCoverage" Version="17.4.0" />
<PackageReference Include="Microsoft.ILVerification" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="System.Reflection.MetadataLoadContext" Version="8.0.0" />
<PackageReference Include="xunit" Version="2.6.5" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<None Remove="sample.ico" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="sample.ico" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\IKVM.Reflection\IKVM.Reflection.csproj" />
<ProjectReference Include="..\IKVM.Tests.Util\IKVM.Tests.Util.csproj" />
</ItemGroup>

</Project>
86 changes: 86 additions & 0 deletions src/IKVM.Reflection.Tests/ModuleReaderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.InteropServices;

using FluentAssertions;

using IKVM.Tests.Util;

using Xunit;

namespace IKVM.Reflection.Tests
{
public class ModuleReaderTests
{

/// <summary>
/// Initializes the variables requires to execute tests.
/// </summary
/// <param name="framework"></param>
/// <param name="universe"></param>
/// <param name="resolver"></param>
bool Init(FrameworkSpec framework, out Universe universe, out TestAssemblyResolver resolver)
{
universe = null;
resolver = null;

// no reference assemblies for NetFX on Unix
if (framework.TargetFrameworkIdentifier == ".NETFramework")
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) == false)
return false;

// initialize primary classes
universe = new Universe(DotNetSdkUtil.GetCoreLibName(framework.Tfm, framework.TargetFrameworkIdentifier, framework.TargetFrameworkVersion));
resolver = new TestAssemblyResolver(universe, framework.Tfm, framework.TargetFrameworkIdentifier, framework.TargetFrameworkVersion);

return true;
}

[Theory]
[MemberData(nameof(FrameworkSpec.GetFrameworkTestData), MemberType = typeof(FrameworkSpec))]
public void CanMakeGenericType(FrameworkSpec framework)
{
if (Init(framework, out var universe, out var resolver) == false)
return;

var t = universe.Import(typeof(IEnumerable<>));
t.IsGenericType.Should().BeTrue();
t.IsGenericTypeDefinition.Should().BeTrue();
t.IsConstructedGenericType.Should().BeFalse();
var g = t.MakeGenericType(universe.Import(typeof(object)));
g.IsGenericTypeDefinition.Should().BeFalse();
g.IsConstructedGenericType.Should().BeTrue();
}

[Theory]
[MemberData(nameof(FrameworkSpec.GetFrameworkTestData), MemberType = typeof(FrameworkSpec))]
public void CanGetGenericPropertyOfGenericType(FrameworkSpec framework)
{
if (Init(framework, out var universe, out var resolver) == false)
return;

// simple generic with a single property
var nullableType = universe.Import(typeof(Nullable<>));
nullableType.IsGenericType.Should().BeTrue();
nullableType.IsGenericTypeDefinition.Should().BeTrue();
nullableType.IsConstructedGenericType.Should().BeFalse();
nullableType.GetGenericArguments().Should().HaveCount(1);
nullableType.GetGenericArguments()[0].Should().NotBeNull();

// make generic instance
var nullableOfObjectType = nullableType.MakeGenericType(universe.Import(typeof(object)));
nullableOfObjectType.IsGenericTypeDefinition.Should().BeFalse();
nullableOfObjectType.IsConstructedGenericType.Should().BeTrue();

// check for expected property
var valueProperty = nullableOfObjectType.GetProperty("Value");
valueProperty.PropertyType.Should().Be(universe.Import(typeof(object)));
var valueGetter = valueProperty.GetGetMethod();
valueGetter.ReturnType.Should().Be(universe.Import(typeof(object)));
valueGetter.GetParameters().Should().BeEmpty();
}

}

}
Loading

0 comments on commit 233bb20

Please sign in to comment.