diff options
author | Alex Ghiondea <ghiondea.alexandru@microsoft.com> | 2015-12-02 00:46:33 +0300 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2015-12-02 01:13:17 +0300 |
commit | 9287f362cd75512a92d735630c363ccc44120677 (patch) | |
tree | bf8c85cb86b510770a0a334c62954547702833ef /src/System.Private.DeveloperExperience.Console | |
parent | 1c0405707ef848c1a485ef0fa63452e4e12305ed (diff) |
Port System.Private.DeveloperExperience.Console to CoreRT
[tfs-changeset: 1553090]
Diffstat (limited to 'src/System.Private.DeveloperExperience.Console')
5 files changed, 186 insertions, 0 deletions
diff --git a/src/System.Private.DeveloperExperience.Console/src/Internal/DeveloperExperience/ConsolePal.Unix.cs b/src/System.Private.DeveloperExperience.Console/src/Internal/DeveloperExperience/ConsolePal.Unix.cs new file mode 100644 index 000000000..2be4652d6 --- /dev/null +++ b/src/System.Private.DeveloperExperience.Console/src/Internal/DeveloperExperience/ConsolePal.Unix.cs @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; + +namespace Internal.DeveloperExperience +{ + internal static class ConsolePal + { + internal unsafe static void WriteError(string errorMessage) + { + byte[] errorMessageAsBytes = Interop.StringHelper.GetBytesFromUTF8string(errorMessage); + fixed (byte* pBuffer = errorMessageAsBytes) + { + Interop.Sys.Write2(Interop.Sys.FileDescriptors.STDERR_FILENO, pBuffer, errorMessageAsBytes.Length); + } + + // Write new line + byte newLine = (byte) '\n'; + Interop.Sys.Write2(Interop.Sys.FileDescriptors.STDERR_FILENO, &newLine, 1); + + } + } +}
\ No newline at end of file diff --git a/src/System.Private.DeveloperExperience.Console/src/Internal/DeveloperExperience/ConsolePal.Windows.cs b/src/System.Private.DeveloperExperience.Console/src/Internal/DeveloperExperience/ConsolePal.Windows.cs new file mode 100644 index 000000000..f9ed5eacb --- /dev/null +++ b/src/System.Private.DeveloperExperience.Console/src/Internal/DeveloperExperience/ConsolePal.Windows.cs @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; + +namespace Internal.DeveloperExperience +{ + internal static class ConsolePal + { + private static IntPtr s_consoleErrorHandle = Interop.mincore.GetStdHandle(Interop.mincore.HandleTypes.STD_ERROR_HANDLE); + + internal unsafe static void WriteError(string errorMessage) + { + if (s_consoleErrorHandle == new IntPtr(Interop.mincore.HandleTypes.INVALID_HANDLE_VALUE)) + { + // ensure we have a valid handle before writing to it + return; + } + + fixed (char *pBuffer = errorMessage) + { + int numberOfCharsWritten; + Interop.mincore.WriteConsole(s_consoleErrorHandle, (byte*)pBuffer, errorMessage.Length, out numberOfCharsWritten, IntPtr.Zero); + } + + // Write new line + fixed (char* pBuffer = "\r\n") + { + int numberOfCharsWritten; + Interop.mincore.WriteConsole(s_consoleErrorHandle, (byte*)pBuffer, 2, out numberOfCharsWritten, IntPtr.Zero); + } + } + } +}
\ No newline at end of file diff --git a/src/System.Private.DeveloperExperience.Console/src/Internal/DeveloperExperience/DeveloperExperienceConnector.cs b/src/System.Private.DeveloperExperience.Console/src/Internal/DeveloperExperience/DeveloperExperienceConnector.cs new file mode 100644 index 000000000..c1aa19135 --- /dev/null +++ b/src/System.Private.DeveloperExperience.Console/src/Internal/DeveloperExperience/DeveloperExperienceConnector.cs @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using global::System; +using global::System.Diagnostics; + +namespace Internal.DeveloperExperience +{ + public static class DeveloperExperienceConnectorConsole + { + // This method is targeted by the MainMethodInjector transform. This method exists in various DeveloperExperience.*.dll's. + // The MainMethodInjector chooses an appropriate one (or none) depending on the build configuration and app structure. + // + // The Console DeveloperExperience is chosen if the main exe has a reference to System.Console. This is for internal Microsoft use only. + // It should remain small enough that we don't bother shutting it off on retail builds. + public static void Initialize() + { + DeveloperExperience.Default = new DeveloperExperienceConsole(); + return; + } + } +} + + diff --git a/src/System.Private.DeveloperExperience.Console/src/Internal/DeveloperExperience/DeveloperExperienceConsole.cs b/src/System.Private.DeveloperExperience.Console/src/Internal/DeveloperExperience/DeveloperExperienceConsole.cs new file mode 100644 index 000000000..17121740b --- /dev/null +++ b/src/System.Private.DeveloperExperience.Console/src/Internal/DeveloperExperience/DeveloperExperienceConsole.cs @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using global::System; +using global::System.Diagnostics; +using global::Internal.StackTraceGenerator; + +namespace Internal.DeveloperExperience +{ + internal sealed class DeveloperExperienceConsole : DeveloperExperience + { + public sealed override void WriteLine(String s) + { + ConsolePal.WriteError(s); + } + + public sealed override String CreateStackTraceString(IntPtr ip, bool includeFileInfo) + { + String s = Internal.StackTraceGenerator.StackTraceGenerator.CreateStackTraceString(ip, includeFileInfo); + if (s != null) + return s; + return base.CreateStackTraceString(ip, includeFileInfo); + } + + public sealed override void TryGetSourceLineInfo(IntPtr ip, out string fileName, out int lineNumber, out int columnNumber) + { + Internal.StackTraceGenerator.StackTraceGenerator.TryGetSourceLineInfo(ip, out fileName, out lineNumber, out columnNumber); + // we take whatever data StackTraceGenerator can get (none/partial/all). No reason to fall-back because the base-type + // never finds anything. + } + } +} + diff --git a/src/System.Private.DeveloperExperience.Console/src/System.Private.DeveloperExperience.Console.csproj b/src/System.Private.DeveloperExperience.Console/src/System.Private.DeveloperExperience.Console.csproj new file mode 100644 index 000000000..3518511d0 --- /dev/null +++ b/src/System.Private.DeveloperExperience.Console/src/System.Private.DeveloperExperience.Console.csproj @@ -0,0 +1,71 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build"> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> + <PropertyGroup> + <AssemblyName>System.Private.DeveloperExperience.Console</AssemblyName> + <OutputType>Library</OutputType> + <ProjectGuid>{F9EF39E7-C8E4-4776-A952-FEF7A1FC2D3B}</ProjectGuid> + <AllowUnsafeBlocks>true</AllowUnsafeBlocks> + + <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> + <TargetPlatformIdentifier>Portable</TargetPlatformIdentifier> + <TargetFrameworkIdentifier>.NETPortable</TargetFrameworkIdentifier> + <TargetFrameworkProfile>Profile7</TargetFrameworkProfile> + <TargetFrameworkMonikerDisplayName>.NET Portable Subset</TargetFrameworkMonikerDisplayName> + <ImplicitlyExpandTargetFramework>false</ImplicitlyExpandTargetFramework> + </PropertyGroup> + + <!-- Default configurations to help VS understand the options --> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> + <PlatformTarget>x86</PlatformTarget> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> + <PlatformTarget>x86</PlatformTarget> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|amd64' "> + <PlatformTarget>x64</PlatformTarget> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|amd64' "> + <PlatformTarget>x64</PlatformTarget> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|arm' "> + <PlatformTarget>arm</PlatformTarget> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|arm' "> + <PlatformTarget>arm</PlatformTarget> + </PropertyGroup> + <ItemGroup> + <Compile Include="Internal\DeveloperExperience\DeveloperExperienceConnector.cs" /> + <Compile Include="Internal\DeveloperExperience\DeveloperExperienceConsole.cs" /> + </ItemGroup> + + <ItemGroup Condition="'$(TargetsWindows)'=='true'"> + <Compile Include="..\..\Common\src\Interop\Windows\mincore\Interop.Console.cs" /> + <Compile Include="..\..\Common\src\Interop\Windows\mincore\Interop.HandleTypes.cs" /> + <Compile Include="Internal\DeveloperExperience\ConsolePal.Windows.cs" /> + </ItemGroup> + + <ItemGroup Condition="'$(TargetsUnix)'=='true'"> + <Compile Include="..\..\Common\src\Interop\Unix\System.Private.CoreLib.Native\Interop.StringHelper.cs" /> + <Compile Include="..\..\Common\src\Interop\Unix\System.Private.CoreLib.Native\Interop.Libraries.cs" /> + <Compile Include="..\..\Common\src\Interop\Unix\System.Private.CoreLib.Native\Interop.Write.cs" /> + <Compile Include="..\..\Common\src\Interop\Unix\libc\Interop.FileDescriptors.cs" /> + <Compile Include="Internal\DeveloperExperience\ConsolePal.Unix.cs" /> + </ItemGroup> + + <ItemGroup> + <ProjectReference Include="..\..\System.Private.CoreLib\src\System.Private.CoreLib.csproj" /> + <ProjectReference Include="..\..\AotPackageReference\AotPackageReference.depproj"> + <ReferenceOutputAssembly>false</ReferenceOutputAssembly> + </ProjectReference> + + <ReferencePath Include="$(AotPackageReferencePath)\System.Runtime.dll" /> + <ReferencePath Include="$(AotPackageReferencePath)\System.Runtime.Extensions.dll" /> + <ReferencePath Include="$(AotPackageReferencePath)\System.Diagnostics.Tracing.dll" /> + <ReferencePath Include="$(AotPackageReferencePath)\System.Collections.dll" /> + <ReferencePath Include="$(AotPackageReferencePath)\System.Resources.ResourceManager.dll" /> + + <ProjectReference Include="..\..\System.Private.StackTraceGenerator\src\System.Private.StackTraceGenerator.csproj" /> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> +</Project> |