diff --git a/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompiler.cs b/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompiler.cs index 57e092286ac3..782fcbcd196a 100644 --- a/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompiler.cs +++ b/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompiler.cs @@ -194,7 +194,7 @@ protected virtual NPath CompileCSharpAssemblyWithDefaultCompiler (CompilerOption #if NETCOREAPP return CompileCSharpAssemblyWithRoslyn (options); #else - return CompileCSharpAssemblyWithCodeDom (options); + return CompileCSharpAssemblyWithCsc (options); #endif } @@ -286,43 +286,29 @@ protected virtual NPath CompileCSharpAssemblyWithRoslyn (CompilerOptions options } #endif - protected virtual NPath CompileCSharpAssemblyWithCodeDom (CompilerOptions options) - { - var compilerOptions = CreateCodeDomCompilerOptions (options); - var provider = CodeDomProvider.CreateProvider ("C#"); - var result = provider.CompileAssemblyFromFile (compilerOptions, options.SourceFiles.Select (p => p.ToString ()).ToArray ()); - if (!result.Errors.HasErrors) - return compilerOptions.OutputAssembly.ToNPath (); - - var errors = new StringBuilder (); - foreach (var error in result.Errors) - errors.AppendLine (error.ToString ()); - throw new Exception ("Compilation errors: " + errors); - } - protected virtual NPath CompileCSharpAssemblyWithCsc (CompilerOptions options) { #if NETCOREAPP return CompileCSharpAssemblyWithRoslyn (options); #else - return CompileCSharpAssemblyWithExternalCompiler (LocateCscExecutable (), options); + return CompileCSharpAssemblyWithExternalCompiler (LocateCscExecutable (), options, "/shared "); #endif } protected virtual NPath CompileCSharpAssemblyWithMcs(CompilerOptions options) { if (Environment.OSVersion.Platform == PlatformID.Win32NT) - CompileCSharpAssemblyWithExternalCompiler (LocateMcsExecutable (), options); + CompileCSharpAssemblyWithExternalCompiler (LocateMcsExecutable (), options, string.Empty); return CompileCSharpAssemblyWithDefaultCompiler (options); } - protected NPath CompileCSharpAssemblyWithExternalCompiler (string executable, CompilerOptions options) + protected NPath CompileCSharpAssemblyWithExternalCompiler (string executable, CompilerOptions options, string compilerSpecificArguments) { var capturedOutput = new List (); var process = new Process (); process.StartInfo.FileName = executable; - process.StartInfo.Arguments = OptionsToCompilerCommandLineArguments (options); + process.StartInfo.Arguments = OptionsToCompilerCommandLineArguments (options, compilerSpecificArguments); process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; @@ -397,9 +383,11 @@ static string LocateMcsExecutable () return "mcs"; } - protected string OptionsToCompilerCommandLineArguments (CompilerOptions options) + protected string OptionsToCompilerCommandLineArguments (CompilerOptions options, string compilerSpecificArguments) { var builder = new StringBuilder (); + if (!string.IsNullOrEmpty(compilerSpecificArguments)) + builder.Append (compilerSpecificArguments); builder.Append ($"/out:{options.OutputPath}"); var target = options.OutputPath.ExtensionWithDot == ".exe" ? "exe" : "library"; builder.Append ($" /target:{target}"); @@ -437,28 +425,5 @@ protected NPath CompileIlAssembly (CompilerOptions options) { return _ilCompiler.Compile (options); } - - private CompilerParameters CreateCodeDomCompilerOptions (CompilerOptions options) - { - var compilerParameters = new CompilerParameters - { - OutputAssembly = options.OutputPath.ToString (), - GenerateExecutable = options.OutputPath.FileName.EndsWith (".exe") - }; - - compilerParameters.CompilerOptions = options.Defines?.Aggregate (string.Empty, (buff, arg) => $"{buff} /define:{arg}"); - - compilerParameters.ReferencedAssemblies.AddRange (options.References.Select (r => r.ToString ()).ToArray ()); - - if (options.Resources != null) - compilerParameters.EmbeddedResources.AddRange (options.Resources.Select (r => r.ToString ()).ToArray ()); - - if (options.AdditionalArguments != null) { - var combinedValues = options.AdditionalArguments.Aggregate (string.Empty, (buff, arg) => $"{buff} {arg}"); - compilerParameters.CompilerOptions = $"{compilerParameters.CompilerOptions} {combinedValues}"; - } - - return compilerParameters; - } } } \ No newline at end of file