|
4 | 4 | using System.IO; |
5 | 5 | using System.Linq; |
6 | 6 | using System.Collections.Generic; |
| 7 | +using System.Diagnostics; |
| 8 | +using System.Text; |
7 | 9 | using NUnit.Framework; |
8 | 10 |
|
9 | 11 | namespace generatortests |
@@ -67,6 +69,46 @@ public static Assembly Compile (Xamarin.Android.Binder.CodeGeneratorOptions opti |
67 | 69 | parameters.IncludeDebugInformation = false; |
68 | 70 | #endif |
69 | 71 |
|
| 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 | + } |
70 | 112 | using (var codeProvider = GetCodeDomProvider ()) { |
71 | 113 | CompilerResults results = codeProvider.CompileAssemblyFromFile (parameters, sourceFiles.ToArray ()); |
72 | 114 |
|
|
0 commit comments