Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
414 changes: 414 additions & 0 deletions Src/Compilers/Core/MSBuildTask/BuildClient.cs

Large diffs are not rendered by default.

84 changes: 84 additions & 0 deletions Src/Compilers/Core/MSBuildTask/NativeMethods.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Runtime.InteropServices;

namespace Microsoft.CodeAnalysis.BuildTasks
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal struct STARTUPINFO
{
internal Int32 cb;
internal string lpReserved;
internal string lpDesktop;
internal string lpTitle;
internal Int32 dwX;
internal Int32 dwY;
internal Int32 dwXSize;
internal Int32 dwYSize;
internal Int32 dwXCountChars;
internal Int32 dwYCountChars;
internal Int32 dwFillAttribute;
internal Int32 dwFlags;
internal Int16 wShowWindow;
internal Int16 cbReserved2;
internal IntPtr lpReserved2;
internal IntPtr hStdInput;
internal IntPtr hStdOutput;
internal IntPtr hStdError;
}

[StructLayout(LayoutKind.Sequential)]
internal struct PROCESS_INFORMATION
{
public IntPtr hProcess;
public IntPtr hThread;
public int dwProcessId;
public int dwThreadId;
}

/// <summary>
/// Interop methods.
/// </summary>
internal static class NativeMethods
{
#region Constants

internal static readonly IntPtr NullPtr = IntPtr.Zero;
internal static readonly IntPtr InvalidIntPtr = new IntPtr((int)-1);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Casting int to int seems pointless.


internal const uint NORMAL_PRIORITY_CLASS = 0x0020;
internal const uint CREATE_NO_WINDOW = 0x08000000;
internal const Int32 STARTF_USESTDHANDLES = 0x00000100;
internal const int ERROR_SUCCESS = 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big issue, but it looks a bit odd having Int32 on one line, and int on the next line.


#endregion

//------------------------------------------------------------------------------
// CloseHandle
//------------------------------------------------------------------------------

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment seems pointless.

[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool CloseHandle(IntPtr hObject);

//------------------------------------------------------------------------------
// CreateProcess
//------------------------------------------------------------------------------

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment seems pointless.

[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool CreateProcess
(
string lpApplicationName,
string lpCommandLine,
IntPtr lpProcessAttributes,
IntPtr lpThreadAttributes,
[In, MarshalAs(UnmanagedType.Bool)]
bool bInheritHandles,
uint dwCreationFlags,
IntPtr lpEnvironment,
string lpCurrentDirectory,
[In] ref STARTUPINFO lpStartupInfo,
out PROCESS_INFORMATION lpProcessInformation
);
}
}
24 changes: 21 additions & 3 deletions src/Compilers/Core/MSBuildTask/Csc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using Microsoft.Build.Framework;
using Microsoft.Build.Tasks.Hosting;
using Microsoft.Build.Utilities;
using Microsoft.CodeAnalysis.CompilerServer;
using Microsoft.CodeAnalysis.CSharp;

namespace Microsoft.CodeAnalysis.BuildTasks
{
Expand Down Expand Up @@ -152,6 +154,24 @@ public string WarningsNotAsErrors

#region Tool Members

internal override BuildProtocolConstants.RequestLanguage Language
=> BuildProtocolConstants.RequestLanguage.CSharpCompile;

private static string[] s_separators = { "\r\n" };

internal override void LogMessages(string output, MessageImportance messageImportance)
{
var lines = output.Split(s_separators, StringSplitOptions.RemoveEmptyEntries);
foreach (string line in lines)
{
string trimmedMessage = line.Trim();
if (trimmedMessage != "")
{
Log.LogMessageFromText(trimmedMessage, messageImportance);
}
}
}

/// <summary>
/// Return the name of the tool to execute.
/// </summary>
Expand Down Expand Up @@ -274,8 +294,6 @@ override protected internal void AddResponseFileCommands(CommandLineBuilderExten
/// list of aliases, and if any of the aliases specified is the string "global",
/// then we add that reference to the command-line without an alias.
/// </summary>
/// <param name="commandLine"></param>
/// <owner>RGoel</owner>
private void AddReferencesToCommandLine
(
CommandLineBuilderExtension commandLine
Expand Down Expand Up @@ -393,7 +411,7 @@ internal string GetDefineConstantsSwitch(string originalDefineConstants)
// add them to the outgoing string.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the doc comment for this method GetDefineConstantsSwitch (GitHub does not allow me to place a comment there). It says "Note that CSharp does support assigning a value to the constants", but probably means "Note that CSharp does NOT support assigning a value to the constants".

foreach (string singleIdentifier in allIdentifiers)
{
if (CSharp.SyntaxFacts.IsValidIdentifier(singleIdentifier))
if (SyntaxFacts.IsValidIdentifier(singleIdentifier))
{
// Separate them with a semicolon if there's something already in
// the outgoing string.
Expand Down
27 changes: 25 additions & 2 deletions src/Compilers/Core/MSBuildTask/MSBuildTask.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,22 @@
<HintPath>$(MSBuildProgramFiles32)\Reference Assemblies\Microsoft\MSBuild\v14.0\Microsoft.Build.Utilities.Core.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Collections.Immutable, Version=1.1.33.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\packages\System.Collections.Immutable.1.1.33-beta\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\CSharp\Portable\Parser\CharacterInfo.cs">
<Link>CharacterInfo.cs</Link>
<Compile Include="..\VBCSCompiler\BuildProtocol.cs">
<Link>BuildProtocol.cs</Link>
</Compile>
<Compile Include="..\VBCSCompiler\CompilerServerLogger.cs">
<Link>CompilerServerLogger.cs</Link>
</Compile>
<Compile Include="BuildClient.cs" />
<Compile Include="CanonicalError.cs" />
<Compile Include="CommandLineBuilderExtension.cs" />
<Compile Include="Csc.cs" />
Expand All @@ -46,6 +54,7 @@
<DependentUpon>ErrorString.resx</DependentUpon>
</Compile>
<Compile Include="ManagedCompiler.cs" />
<Compile Include="NativeMethods.cs" />
<Compile Include="PropertyDictionary.cs" />
<Compile Include="Utilities.cs" />
<Compile Include="Vbc.cs" />
Expand All @@ -56,6 +65,20 @@
<LastGenOutput>ErrorString.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\CSharp\Portable\CSharpCodeAnalysis.csproj">
<Project>{b501a547-c911-4a05-ac6e-274a50dff30e}</Project>
<Name>CSharpCodeAnalysis</Name>
</ProjectReference>
<ProjectReference Include="..\Desktop\CodeAnalysis.Desktop.csproj">
<Project>{dfa21ca1-7f96-47ee-940c-069858e81727}</Project>
<Name>CodeAnalysis.Desktop</Name>
</ProjectReference>
<ProjectReference Include="..\Portable\CodeAnalysis.csproj">
<Project>{1ee8cad3-55f9-4d91-96b2-084641da9a6c}</Project>
<Name>CodeAnalysis</Name>
</ProjectReference>
</ItemGroup>
<ImportGroup Label="Targets">
<Import Project="..\..\..\Tools\Microsoft.CodeAnalysis.Toolset.Open\Targets\VSL.Imports.targets" />
<Import Project="..\..\..\..\build\VSL.Imports.Closed.targets" />
Expand Down
Loading