Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support embedded interop types #13813

Merged
merged 14 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions src/Engine/ProtoCore/FFI/CLRDLLModule.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -49,22 +49,24 @@ static CLRModuleType()
/// <param name="alias">Alias name, if any. For now its not supported.</param>
public static CLRModuleType GetInstance(Type type, CLRDLLModule module, string alias)
{
CLRModuleType mtype;
if (!mTypes.TryGetValue(type, out mtype))
if (!mTypes.TryGetValue(type, out CLRModuleType mtype))
{
lock (mTypes)
{
if (!mTypes.TryGetValue(type, out mtype))
mtype = new CLRModuleType(type);
//Now check that a type with same name is not imported.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this comment entirely accurate anymore?

Type otherType;
if (mTypeNames.TryGetValue(mtype.FullName, out CLRModuleType otherMType))
{
mtype = new CLRModuleType(type);
//Now check that a type with same name is not imported.
Type otherType;
if (mTypeNames.TryGetValue(mtype.FullName, out otherType))
throw new InvalidOperationException(string.Format("Can't import {0}, {1} is already imported as {2}, namespace support needed.", type.FullName, type.Name, otherType.FullName));

mTypes.Add(type, mtype);
mTypeNames.Add(mtype.FullName, type);
if (otherMType.CLRType.IsEquivalentTo(type))
{
return otherMType;
}
throw new InvalidOperationException(string.Format("Can't import {0}, {1} is already imported as {2}.", type.FullName, type.Name, otherMType.CLRType.FullName));
}

mTypes.Add(type, mtype);
mTypeNames.Add(mtype.FullName, mtype);
}
}

Expand Down Expand Up @@ -242,9 +244,8 @@ public static ProtoCore.Type GetProtoCoreType(Type type, CLRDLLModule module)

public static System.Type GetImportedType(string typename)
{
Type type = null;
if (mTypeNames.TryGetValue(typename, out type))
return type;
if (mTypeNames.TryGetValue(typename, out CLRModuleType mType))
return mType.CLRType;

return null;
}
Expand All @@ -260,7 +261,7 @@ public static System.Type GetImportedType(string typename)

private static readonly Dictionary<Type, CLRModuleType> mTypes = new Dictionary<Type, CLRModuleType>();

private static readonly Dictionary<string, Type> mTypeNames = new Dictionary<string, Type>();
private static readonly Dictionary<string, CLRModuleType> mTypeNames = new Dictionary<string, CLRModuleType>();

private static readonly Dictionary<System.Type, ProtoCore.Type> mTypeMaps = new Dictionary<Type, ProtoCore.Type>();

Expand Down
15 changes: 14 additions & 1 deletion test/Engine/FFITarget/ClassFunctionality.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;

namespace FFITarget
{
Expand All @@ -7,7 +7,20 @@ namespace FFITarget
/// </summary>
public class ClassFunctionality : IDisposable
{
#if NETFRAMEWORK
public static Microsoft.Office.Interop.Excel.XlPivotLineType GetExcelInteropType()
{
return Microsoft.Office.Interop.Excel.XlPivotLineType.xlPivotLineBlank;
}

public static bool TestExcelInteropType(Microsoft.Office.Interop.Excel.XlPivotLineType arg1)
{
if (arg1 == Microsoft.Office.Interop.Excel.XlPivotLineType.xlPivotLineBlank)
return true;

return false;
}
#endif
private int intVal;
public int IntVal {
get { return intVal; }
Expand Down
12 changes: 10 additions & 2 deletions test/Engine/FFITarget/FFITarget.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DocumentationFile>..\..\..\bin\AnyCPU\Debug\en-US\FFITarget.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net48' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'net48'">
<PackageReference Include="NUnitTestAdapter" Version="2.3.0" ExcludeAssets="all" />
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -22,9 +22,17 @@
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="$(PkgMicrosoft_Office_Interop_Excel)\lib\net20\Microsoft.Office.Interop.Excel.dll">
Copy link
Member

@mjkkirschner mjkkirschner Mar 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this reference be wrapped in a condition for now? (I mean the one below)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this make it to the bin folder? I think we purposefully removed it at some point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totally forgot about test dlls. Will work on removing them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

<EmbedInteropTypes>True</EmbedInteropTypes>
<WrapperTool>tlbimp</WrapperTool>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this?

<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Microsoft.Office.Interop.Excel" Version="15.0.4795.1000" GeneratePathProperty="true">
<ExcludeAssets>all</ExcludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\DynamoCore\DynamoCore.csproj">
Expand Down
17 changes: 17 additions & 0 deletions test/Engine/ProtoTest/FFITests/FFITest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using FFITarget;
using NUnit.Framework;
using ProtoCore.DSASM.Mirror;
using ProtoCore.Mirror;
Expand Down Expand Up @@ -206,5 +207,21 @@ public void TestReturnArbitraryDimensionAttribute()
thisTest.Verify("x", new object[] { 1.3, new double[] { 4.5, 7.8 } });

}
#if NETFRAMEWORK
[Test]
public void Test_Embedded_Interop_Types()
{
string code = @"
import (ClassFunctionality from ""FFITarget.dll"");
import (EmbeddedInteropTestClass from ""..\\..\\..\\test\\test_dependencies\\EmbeddedInterop.dll"");

val = EmbeddedInteropTestClass.GetExcelInteropType();
o = ClassFunctionality.TestExcelInteropType(val);
";

thisTest.RunScriptSource(code);
thisTest.Verify("o", true);
}
#endif
}
}
8 changes: 7 additions & 1 deletion test/Engine/ProtoTest/ProtoTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
<ItemGroup>
<PackageReference Include="NUnit" Version="2.6.3" />
<PackageReference Include="NUnitTestAdapter" Version="2.3.0" ExcludeAssets="all" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<Reference Include="EmbeddedInterop" Condition=" '$(TargetFramework)' == 'net48'">
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Windows.Forms" />
Expand Down Expand Up @@ -71,4 +74,7 @@
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Target Name="AfterBuildOps" AfterTargets="ResolveSateliteResDeps">
<Copy SourceFiles="..\..\test_support_projects\EmbeddedInterop.dll" DestinationFolder="$(TestDependenciesPath)" />
</Target>
</Project>
23 changes: 23 additions & 0 deletions test/test_support_projects/ClassFunctionality.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;

namespace EmbeddedInterop
{
/// <summary>
/// Tests for basic functional testing of FFI implementations
/// </summary>
public class EmbeddedInteropTestClass
{
public static Microsoft.Office.Interop.Excel.XlPivotLineType GetExcelInteropType()
{
return Microsoft.Office.Interop.Excel.XlPivotLineType.xlPivotLineBlank;
}

public static bool TestExcelInteropType(Microsoft.Office.Interop.Excel.XlPivotLineType arg1)
{
if (arg1 == Microsoft.Office.Interop.Excel.XlPivotLineType.xlPivotLineBlank)
return true;

return false;
}
}
}
22 changes: 22 additions & 0 deletions test/test_support_projects/EmbeddedInterop.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>EmbeddedInterop</RootNamespace>
<AssemblyName>EmbeddedInterop</AssemblyName>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Office.Interop.Excel" Version="15.0.4795.1000" GeneratePathProperty="true">
<ExcludeAssets>all</ExcludeAssets>
</PackageReference>
<Reference Include="$(PkgMicrosoft_Office_Interop_Excel)\lib\net20\Microsoft.Office.Interop.Excel.dll">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so is there anything in this binary except for the office types?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, just office types and a wrapping class

<EmbedInteropTypes>True</EmbedInteropTypes>
<WrapperTool>tlbimp</WrapperTool>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
</ItemGroup>
</Project>
Binary file added test/test_support_projects/EmbeddedInterop.dll
Binary file not shown.