diff --git a/src/Test/Utilities/CLRHelpers.cs b/src/Test/Utilities/CLRHelpers.cs index ae3a7fd96c7d25407304def503cf4aeebeadd2a6..bea1f9f2659ce6bf24d47d73ddd6f37adf64ebc7 100644 --- a/src/Test/Utilities/CLRHelpers.cs +++ b/src/Test/Utilities/CLRHelpers.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; +using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; @@ -47,6 +48,20 @@ private static Assembly ReflectionOnlyAssemblyResolveHandler(object sender, Reso return null; } + public static bool IsRunningOnMono() + { + return Type.GetType ("Mono.Runtime") != null; + } + + public static object GetRuntimeInterfaceAsObject(Guid clsid, Guid riid) + { + // This API isn't available on Mono hence we must use reflection to access it. + Debug.Assert(!IsRunningOnMono()); + + var getRuntimeInterfaceAsObject = typeof(RuntimeEnvironment).GetMethod("GetRuntimeInterfaceAsObject", BindingFlags.Public | BindingFlags.Static); + return getRuntimeInterfaceAsObject.Invoke(null, new object[] { clsid, riid }); + } + /// /// Verifies the specified image. Subscribe to to provide a loader for dependent assemblies. /// @@ -68,6 +83,13 @@ public static string[] PeVerify(string filePath) private static string[] PeVerify(byte[] peImage, int domainId, string assemblyPath) { + if (IsRunningOnMono()) + { + // PEverify is currently unsupported on Mono hence return an empty + // set of messages + return new string[] { }; + } + lock (s_guard) { GCHandle pinned = GCHandle.Alloc(peImage, GCHandleType.Pinned); @@ -75,10 +97,10 @@ private static string[] PeVerify(byte[] peImage, int domainId, string assemblyPa { IntPtr buffer = pinned.AddrOfPinnedObject(); - ICLRValidator validator = (ICLRValidator)RuntimeEnvironment.GetRuntimeInterfaceAsObject(s_clsIdClrRuntimeHost, typeof(ICLRRuntimeHost).GUID); + ICLRValidator validator = (ICLRValidator)GetRuntimeInterfaceAsObject(s_clsIdClrRuntimeHost, typeof(ICLRRuntimeHost).GUID); ValidationErrorHandler errorHandler = new ValidationErrorHandler(validator); - IMetaDataDispenser dispenser = (IMetaDataDispenser)RuntimeEnvironment.GetRuntimeInterfaceAsObject(s_clsIdCorMetaDataDispenser, typeof(IMetaDataDispenser).GUID); + IMetaDataDispenser dispenser = (IMetaDataDispenser)GetRuntimeInterfaceAsObject(s_clsIdCorMetaDataDispenser, typeof(IMetaDataDispenser).GUID); // the buffer needs to be pinned during validation Guid riid = typeof(IMetaDataImport).GUID; diff --git a/src/Test/Utilities/TestUtilities.csproj b/src/Test/Utilities/TestUtilities.csproj index bcc9f4c0836cf414dab38b469966fc9a7526ce46..4beaf32606dfef931ef16164f5f59e7485544e4b 100644 --- a/src/Test/Utilities/TestUtilities.csproj +++ b/src/Test/Utilities/TestUtilities.csproj @@ -106,9 +106,6 @@ ..\..\..\packages\xunit.1.9.2\lib\net20\xunit.dll - - - @@ -233,4 +230,4 @@ - \ No newline at end of file + diff --git a/src/Tools/Microsoft.CodeAnalysis.Toolset.Open/Targets/GenerateCompilerInternals.targets b/src/Tools/Microsoft.CodeAnalysis.Toolset.Open/Targets/GenerateCompilerInternals.targets index 580f7be2cabd26a3b7afff183301279edc7e80a0..e7aaaaa9cb0b82d970ab3056c3b3c21ac34c537a 100644 --- a/src/Tools/Microsoft.CodeAnalysis.Toolset.Open/Targets/GenerateCompilerInternals.targets +++ b/src/Tools/Microsoft.CodeAnalysis.Toolset.Open/Targets/GenerateCompilerInternals.targets @@ -33,6 +33,10 @@ $(CleanDependsOn) + + + mono + - - "$(VBSyntaxGeneratorToolPath)" - - - "$(CSharpSyntaxGeneratorToolPath)" - mono $(CSharpSyntaxGeneratorToolPath) - + $(MonoPrefix) "$(VBSyntaxGeneratorToolPath)" + $(MonoPrefix) "$(CSharpSyntaxGeneratorToolPath)" @(SyntaxDefinition -> '$(IntermediateOutputPath)%(Filename)%(Extension).Generated$(DefaultLanguageSourceExtension)') @@ -78,8 +77,6 @@ > "$(VBSyntaxGeneratorToolPath)" - - @(SyntaxGetTextDefinition -> '$(IntermediateOutputPath)\%(FileName)%(Extension).Generated$(DefaultLanguageSourceExtension)') @@ -109,14 +106,9 @@ Outputs="@(SyntaxTestDefinition -> '$(IntermediateOutputPath)\%(FileName)%(Extension).Generated$(DefaultLanguageSourceExtension)')" Condition="'$(Language)' == 'VB' or '$(Language)' == 'C#'" > - - "$(VBSyntaxGeneratorToolPath)" - - - "$(CSharpSyntaxGeneratorToolPath)" - mono $(CSharpSyntaxGeneratorToolPath) - + $(MonoPrefix) "$(VBSyntaxGeneratorToolPath)" + $(MonoPrefix) "$(CSharpSyntaxGeneratorToolPath)" @(SyntaxTestDefinition -> '$(IntermediateOutputPath)\%(FileName)%(Extension).Generated$(DefaultLanguageSourceExtension)') @@ -147,8 +139,7 @@ Condition="'$(Language)' == 'VB' or '$(Language)' == 'C#'" > - "$(BoundTreeGeneratorToolPath)" - mono $(BoundTreeGeneratorToolPath) + $(MonoPrefix) "$(BoundTreeGeneratorToolPath)" @(BoundTreeDefinition -> '$(IntermediateOutputPath)%(Filename)%(Extension).Generated$(DefaultLanguageSourceExtension)') @@ -183,16 +174,9 @@ Outputs="@(ErrorCode -> '$(IntermediateOutputPath)ErrorFacts.Generated$(DefaultLanguageSourceExtension)')" Condition="'$(Language)' == 'VB' or '$(Language)' == 'C#'" > - - "$(VBErrorFactsGeneratorToolPath)" - - - - "$(CSharpErrorFactsGeneratorToolPath)" - mono $(CSharpErrorFactsGeneratorToolPath) - - + $(MonoPrefix) "$(VBErrorFactsGeneratorToolPath)" + $(MonoPrefix) "$(CSharpErrorFactsGeneratorToolPath)" @(ErrorCode -> '$(IntermediateOutputPath)ErrorFacts.Generated$(DefaultLanguageSourceExtension)')