Skip to content

Commit 38f824c

Browse files
committed
generator unit tests now supports DIM-supported csc via nuget package.
The idea is in the same mindset as existing Windows Roslyn support in terms of access to package contents (dll/exe). I couldn't enable this for ALL projects as java.lang.Object test somehow failed. We only need it only if DIM is required, so limit the usage to it.
1 parent d3ec836 commit 38f824c

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

tools/generator/Tests/Integration-Tests/Compiler.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using System.IO;
55
using System.Linq;
66
using System.Collections.Generic;
7+
using System.Diagnostics;
8+
using System.Text;
79
using NUnit.Framework;
810

911
namespace generatortests
@@ -67,6 +69,41 @@ public static Assembly Compile (Xamarin.Android.Binder.CodeGeneratorOptions opti
6769
parameters.IncludeDebugInformation = false;
6870
#endif
6971

72+
if (options.SupportDefaultInterfaceMethods) {
73+
var sb = new StringBuilder ();
74+
sb.Append (" /t:library")
75+
.Append (" /unsafe")
76+
.Append (' ').Append ($"/out:\"{assemblyFileName}\"");
77+
foreach (var assembly in parameters.ReferencedAssemblies)
78+
sb.Append ($" /r:\"{assembly}\"");
79+
if (parameters.IncludeDebugInformation)
80+
sb.Append (" /debug:portable");
81+
foreach (var sourceFile in sourceFiles)
82+
sb.Append (' ').Append ($"\"{sourceFile}\"");
83+
string compiler = Path.GetFullPath (Path.Combine (unitTestFrameworkAssemblyPath, "..", "..", "..", "packages", "xamarin.android.csc.dim.0.1.2", "tools", "csc.exe"));
84+
var pinfo = new ProcessStartInfo () {
85+
UseShellExecute = false,
86+
RedirectStandardOutput = true,
87+
RedirectStandardError = true,
88+
};
89+
if (Environment.OSVersion.Platform == PlatformID.Win32NT) {
90+
pinfo.FileName = compiler;
91+
pinfo.Arguments = sb.ToString ();
92+
} else {
93+
pinfo.FileName = "mono"; // SYSMONO
94+
pinfo.Arguments = compiler + sb;
95+
}
96+
var results = new StringBuilder ();
97+
var proc = new Process ();
98+
proc.ErrorDataReceived += (o, e) => results.Append (e.Data + Environment.NewLine);
99+
proc.OutputDataReceived += (o, e) => results.Append (e.Data + Environment.NewLine);
100+
proc.StartInfo = pinfo;
101+
proc.Start ();
102+
proc.WaitForExit ();
103+
output = results.ToString ();
104+
hasErrors = proc.ExitCode != 0;
105+
return Assembly.ReflectionOnlyLoadFrom (Path.GetFullPath (assemblyFileName));
106+
}
70107
using (var codeProvider = GetCodeDomProvider ()) {
71108
CompilerResults results = codeProvider.CompileAssemblyFromFile (parameters, sourceFiles.ToArray ());
72109

tools/generator/Tests/generator-Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\..\..\packages\xamarin.android.csc.dim.0.1.2\build\xamarin.android.csc.dim.props" Condition="Exists('..\..\..\packages\xamarin.android.csc.dim.0.1.2\build\xamarin.android.csc.dim.props')" />
34
<PropertyGroup>
45
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
56
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -210,4 +211,5 @@
210211
<ItemGroup>
211212
<Folder Include="expected.ji\DefaultInterfaceMethods\" />
212213
</ItemGroup>
214+
<Import Project="..\..\..\packages\xamarin.android.csc.dim.0.1.2\build\xamarin.android.csc.dim.targets" Condition="Exists('..\..\..\packages\xamarin.android.csc.dim.0.1.2\build\xamarin.android.csc.dim.targets')" />
213215
</Project>

tools/generator/Tests/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.7" targetFramework="net45" />
44
<package id="Microsoft.Net.Compilers" version="2.1.0" developmentDependency="true" />
55
<package id="NUnit" version="3.7.1" targetFramework="net45" />
6+
<package id="xamarin.android.csc.dim" version="0.1.2" targetFramework="net45" />
67
</packages>

0 commit comments

Comments
 (0)