Skip to content

Commit 01f9620

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 01f9620

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

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

Lines changed: 42 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,46 @@ 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 (" /langversion:latest")
77+
.Append (' ').Append ($"/out:\"{assemblyFileName}\"");
78+
foreach (var assembly in parameters.ReferencedAssemblies)
79+
sb.Append ($" /r:\"{assembly}\"");
80+
if (parameters.IncludeDebugInformation)
81+
sb.Append (" /debug:portable");
82+
foreach (var sourceFile in sourceFiles)
83+
sb.Append (' ').Append ($"\"{sourceFile}\"");
84+
string compiler = Path.GetFullPath (Path.Combine (unitTestFrameworkAssemblyPath, "..", "..", "..", "packages", "xamarin.android.csc.dim.0.1.2", "tools", "csc.exe"));
85+
var pinfo = new ProcessStartInfo () {
86+
UseShellExecute = false,
87+
RedirectStandardOutput = true,
88+
RedirectStandardError = true,
89+
};
90+
if (Environment.OSVersion.Platform == PlatformID.Win32NT) {
91+
pinfo.FileName = compiler;
92+
pinfo.Arguments = sb.ToString ();
93+
} else {
94+
pinfo.FileName = "mono"; // SYSMONO
95+
pinfo.Arguments = compiler + sb;
96+
}
97+
var results = new StringBuilder ();
98+
var proc = new Process ();
99+
proc.ErrorDataReceived += (o, e) =>
100+
results.Append (e.Data).Append (Environment.NewLine);
101+
proc.OutputDataReceived += (o, e) =>
102+
results.Append (e.Data).Append (Environment.NewLine);
103+
proc.StartInfo = pinfo;
104+
proc.Start ();
105+
proc.BeginOutputReadLine ();
106+
proc.BeginErrorReadLine ();
107+
proc.WaitForExit ();
108+
output = results.ToString ();
109+
hasErrors = proc.ExitCode != 0;
110+
return hasErrors ? null : Assembly.ReflectionOnlyLoadFrom (Path.GetFullPath (assemblyFileName));
111+
}
70112
using (var codeProvider = GetCodeDomProvider ()) {
71113
CompilerResults results = codeProvider.CompileAssemblyFromFile (parameters, sourceFiles.ToArray ());
72114

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)