提交 df82e6c0 编写于 作者: J Jared Parsons

Move several components to ServerCore

上级 1b8edeb6
......@@ -17,6 +17,10 @@
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<ItemGroup Label="Project References">
<ProjectReference Include="..\..\..\Server\Core\ServerCore.csproj">
<Project>{9929e5ae-85ca-46a8-a500-3be7bc634d87}</Project>
<Name>ServerCore</Name>
</ProjectReference>
<ProjectReference Include="..\..\csc\csc.csproj">
<Project>{4B45CA0C-03A0-400F-B454-3D4BCB16AF38}</Project>
<Name>csc</Name>
......@@ -105,4 +109,4 @@
<Import Project="..\..\..\..\..\build\Targets\VSL.Imports.targets" />
<Import Project="..\..\..\..\..\build\Targets\Roslyn.Toolsets.Xunit.targets" />
</ImportGroup>
</Project>
</Project>
\ No newline at end of file
......@@ -215,6 +215,7 @@ public void TrivialMetadataCaching()
filelist.Add(source1);
var outWriter = new StringWriter();
var cmd = new CSharpCompilerServer(
new DesktopCompilerServerHost(),
new[] { "/nologo", "/touchedfiles:" + touchedBase, source1 },
null,
_baseDirectory,
......
// 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.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Microsoft.CodeAnalysis.CompilerServer
{
public interface ICompilerServerHost
{
Func<string, MetadataReferenceProperties, PortableExecutableReference> AssemblyReferenceProvider { get; }
}
}
......@@ -58,7 +58,6 @@ internal Metadata GetMetadata(string fullPath, MetadataReferenceProperties prope
Metadata metadata;
if (fileKey.HasValue && _metadataCache.TryGetValue(fileKey.Value, out metadata) && metadata != null)
{
CompilerServerLogger.Log("Using already loaded metadata for assembly reference '{0}'", fileKey);
return metadata;
}
......@@ -92,20 +91,9 @@ internal Metadata GetMetadata(string fullPath, MetadataReferenceProperties prope
/// </summary>
private FileKey? GetUniqueFileKey(string filePath)
{
FileInfo fileInfo;
try
{
fileInfo = new FileInfo(filePath);
if (!fileInfo.Exists)
{
return null;
}
else
{
return new FileKey(fileInfo.FullName, fileInfo.LastWriteTimeUtc);
}
return FileKey.Create(filePath);
}
catch (Exception)
{
......@@ -117,11 +105,11 @@ internal Metadata GetMetadata(string fullPath, MetadataReferenceProperties prope
}
}
internal class CachingMetadataReference : PortableExecutableReference
public sealed class CachingMetadataReference : PortableExecutableReference
{
private static readonly MetadataAndSymbolCache s_mdCache = new MetadataAndSymbolCache();
internal CachingMetadataReference(string fullPath, MetadataReferenceProperties properties)
public CachingMetadataReference(string fullPath, MetadataReferenceProperties properties)
: base(properties, fullPath)
{
}
......
......@@ -50,6 +50,10 @@
<Name>BasicCodeAnalysis</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="ICompilerServerHost.cs" />
<Compile Include="MetadataCache.cs" />
</ItemGroup>
<ImportGroup Label="Targets">
<Import Project="..\..\..\..\build\Targets\VSL.Imports.targets" />
</ImportGroup>
......
......@@ -13,47 +13,17 @@ namespace Microsoft.CodeAnalysis.CompilerServer
{
internal sealed class CSharpCompilerServer : CSharpCompiler
{
internal CSharpCompilerServer(string[] args, string clientDirectory, string baseDirectory, string sdkDirectory, string libDirectory, IAnalyzerAssemblyLoader analyzerLoader)
: base(CSharpCommandLineParser.Default, clientDirectory != null ? Path.Combine(clientDirectory, ResponseFileName) : null, args, clientDirectory, baseDirectory, sdkDirectory, libDirectory, analyzerLoader)
{
}
public static BuildResponse RunCompiler(
string clientDirectory,
string[] args,
string baseDirectory,
string sdkDirectory,
string libDirectory,
IAnalyzerAssemblyLoader analyzerLoader,
CancellationToken cancellationToken)
{
var compiler = new CSharpCompilerServer(args, clientDirectory, baseDirectory, sdkDirectory, libDirectory, analyzerLoader);
bool utf8output = compiler.Arguments.Utf8Output;
if (!AnalyzerConsistencyChecker.Check(baseDirectory, compiler.Arguments.AnalyzerReferences, analyzerLoader))
{
return new AnalyzerInconsistencyBuildResponse();
}
private readonly ICompilerServerHost _compilerServerHost;
TextWriter output = new StringWriter(CultureInfo.InvariantCulture);
int returnCode = compiler.Run(output, cancellationToken);
return new CompletedBuildResponse(returnCode, utf8output, output.ToString(), string.Empty);
}
public override int Run(TextWriter consoleOutput, CancellationToken cancellationToken = default(CancellationToken))
internal CSharpCompilerServer(ICompilerServerHost compilerServerHost, string[] args, string clientDirectory, string baseDirectory, string sdkDirectory, string libDirectory, IAnalyzerAssemblyLoader analyzerLoader)
: base(CSharpCommandLineParser.Default, clientDirectory != null ? Path.Combine(clientDirectory, ResponseFileName) : null, args, clientDirectory, baseDirectory, sdkDirectory, libDirectory, analyzerLoader)
{
int returnCode;
CompilerServerLogger.Log("****Running C# compiler...");
returnCode = base.Run(consoleOutput, cancellationToken);
CompilerServerLogger.Log("****C# Compilation complete.\r\n****Return code: {0}\r\n****Output:\r\n{1}\r\n", returnCode, consoleOutput.ToString());
return returnCode;
_compilerServerHost = compilerServerHost;
}
internal override Func<string, MetadataReferenceProperties, PortableExecutableReference> GetMetadataProvider()
{
return CompilerRequestHandler.AssemblyReferenceProvider;
return _compilerServerHost.AssemblyReferenceProvider;
}
protected override uint GetSqmAppID()
......
......@@ -16,12 +16,10 @@ namespace Microsoft.CodeAnalysis.CompilerServer
/// </summary>
internal class CompilerRequestHandler : IRequestHandler
{
// Caches are used by C# and VB compilers, and shared here.
public static readonly Func<string, MetadataReferenceProperties, PortableExecutableReference> AssemblyReferenceProvider =
(path, properties) => new CachingMetadataReference(path, properties);
public static readonly IAnalyzerAssemblyLoader AnalyzerLoader = new ShadowCopyAnalyzerAssemblyLoader(Path.Combine(Path.GetTempPath(), "VBCSCompiler", "AnalyzerAssemblyLoader"));
private readonly DesktopCompilerServerHost _desktopCompilerServerHost = new DesktopCompilerServerHost();
private static void LogAbnormalExit(string msg)
{
string roslynTempDir = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), "RoslynCompilerServerCrash");
......@@ -150,7 +148,8 @@ private BuildResponse CSharpCompile(BuildRequest req, CancellationToken cancella
CompilerServerLogger.Log("Argument[{0}] = '{1}'", i, commandLineArguments[i]);
}
return CSharpCompilerServer.RunCompiler(
return CSharpCompileCore(
responseFileDirectory,
commandLineArguments,
currentDirectory,
......@@ -160,6 +159,31 @@ private BuildResponse CSharpCompile(BuildRequest req, CancellationToken cancella
cancellationToken);
}
private BuildResponse CSharpCompileCore(
string clientDirectory,
string[] args,
string baseDirectory,
string sdkDirectory,
string libDirectory,
IAnalyzerAssemblyLoader analyzerLoader,
CancellationToken cancellationToken)
{
var compiler = new CSharpCompilerServer(_desktopCompilerServerHost, args, clientDirectory, baseDirectory, sdkDirectory, libDirectory, analyzerLoader);
bool utf8output = compiler.Arguments.Utf8Output;
if (!AnalyzerConsistencyChecker.Check(baseDirectory, compiler.Arguments.AnalyzerReferences, analyzerLoader))
{
return new AnalyzerInconsistencyBuildResponse();
}
CompilerServerLogger.Log("****Running C# compiler...");
TextWriter output = new StringWriter(CultureInfo.InvariantCulture);
int returnCode = compiler.Run(output, cancellationToken);
CompilerServerLogger.Log("****C# Compilation complete.\r\n****Return code: {0}\r\n****Output:\r\n{1}\r\n", returnCode, output.ToString());
return new CompletedBuildResponse(returnCode, utf8output, output.ToString(), string.Empty);
}
/// <summary>
/// A request to compile VB files. Unpack the arguments and current directory and invoke
/// the compiler, then create a response with the result of compilation.
......@@ -204,7 +228,7 @@ private BuildResponse BasicCompile(BuildRequest req, CancellationToken cancellat
CompilerServerLogger.Log("Argument[{0}] = '{1}'", i, commandLineArguments[i]);
}
return VisualBasicCompilerServer.RunCompiler(
return BasicCompileCore(
responseFileDirectory,
commandLineArguments,
currentDirectory,
......@@ -213,5 +237,31 @@ private BuildResponse BasicCompile(BuildRequest req, CancellationToken cancellat
AnalyzerLoader,
cancellationToken);
}
private BuildResponse BasicCompileCore(
string clientDirectory,
string[] args,
string baseDirectory,
string sdkDirectory,
string libDirectory,
IAnalyzerAssemblyLoader analyzerLoader,
CancellationToken cancellationToken)
{
var compiler = new VisualBasicCompilerServer(_desktopCompilerServerHost, args, clientDirectory, baseDirectory, sdkDirectory, libDirectory, analyzerLoader);
bool utf8output = compiler.Arguments.Utf8Output;
if (!AnalyzerConsistencyChecker.Check(baseDirectory, compiler.Arguments.AnalyzerReferences, analyzerLoader))
{
return new AnalyzerInconsistencyBuildResponse();
}
TextWriter output = new StringWriter(CultureInfo.InvariantCulture);
CompilerServerLogger.Log("****Running VB compiler...");
int returnCode = compiler.Run(output, cancellationToken);
CompilerServerLogger.Log("****VB Compilation complete.\r\n****Return code: {0}\r\n****Output:\r\n{1}\r\n", returnCode, output.ToString());
return new CompletedBuildResponse(returnCode, utf8output, output.ToString(), string.Empty);
}
}
}
// 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.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Microsoft.CodeAnalysis.CompilerServer
{
internal sealed class DesktopCompilerServerHost : ICompilerServerHost
{
// Caches are used by C# and VB compilers, and shared here.
private static readonly Func<string, MetadataReferenceProperties, PortableExecutableReference> s_assemblyReferenceProvider =
(path, properties) => new CachingMetadataReference(path, properties);
public Func<string, MetadataReferenceProperties, PortableExecutableReference> AssemblyReferenceProvider => s_assemblyReferenceProvider;
}
}
......@@ -65,9 +65,9 @@
<Compile Include="Assembly.cs" />
<Compile Include="CompilerRequestHandler.cs" />
<Compile Include="CSharpCompilerServer.cs" />
<Compile Include="DesktopCompilerServerHost.cs" />
<Compile Include="DiagnosticListener.cs" />
<Compile Include="IClientConnection.cs" />
<Compile Include="MetadataCache.cs" />
<Compile Include="NamedPipeClientConnection.cs" />
<Compile Include="ServerDispatcher.Connection.cs" />
<Compile Include="ServerDispatcher.cs" />
......
......@@ -15,46 +15,17 @@ namespace Microsoft.CodeAnalysis.CompilerServer
{
internal sealed class VisualBasicCompilerServer : VisualBasicCompiler
{
internal VisualBasicCompilerServer(string[] args, string clientDirectory, string baseDirectory, string sdkDirectory, string libDirectory, IAnalyzerAssemblyLoader analyzerLoader)
: base(VisualBasicCommandLineParser.Default, clientDirectory != null ? Path.Combine(clientDirectory, ResponseFileName) : null, args, clientDirectory, baseDirectory, sdkDirectory, libDirectory, analyzerLoader)
{
}
public static BuildResponse RunCompiler(
string clientDirectory,
string[] args,
string baseDirectory,
string sdkDirectory,
string libDirectory,
IAnalyzerAssemblyLoader analyzerLoader,
CancellationToken cancellationToken)
{
var compiler = new VisualBasicCompilerServer(args, clientDirectory, baseDirectory, sdkDirectory, libDirectory, analyzerLoader);
bool utf8output = compiler.Arguments.Utf8Output;
private readonly ICompilerServerHost _compilerServerHost;
if (!AnalyzerConsistencyChecker.Check(baseDirectory, compiler.Arguments.AnalyzerReferences, analyzerLoader))
{
return new AnalyzerInconsistencyBuildResponse();
}
TextWriter output = new StringWriter(CultureInfo.InvariantCulture);
int returnCode = compiler.Run(output, cancellationToken);
return new CompletedBuildResponse(returnCode, utf8output, output.ToString(), string.Empty);
}
public override int Run(TextWriter consoleOutput, CancellationToken cancellationToken)
internal VisualBasicCompilerServer(ICompilerServerHost compilerServerHost, string[] args, string clientDirectory, string baseDirectory, string sdkDirectory, string libDirectory, IAnalyzerAssemblyLoader analyzerLoader)
: base(VisualBasicCommandLineParser.Default, clientDirectory != null ? Path.Combine(clientDirectory, ResponseFileName) : null, args, clientDirectory, baseDirectory, sdkDirectory, libDirectory, analyzerLoader)
{
int runResult;
CompilerServerLogger.Log("****Running VB compiler...");
runResult = base.Run(consoleOutput, cancellationToken);
CompilerServerLogger.Log("****VB Compilation complete.\r\n****Return code: {0}\r\n****Output:\r\n{1}\r\n", runResult, consoleOutput.ToString());
return runResult;
_compilerServerHost = compilerServerHost;
}
internal override Func<string, MetadataReferenceProperties, PortableExecutableReference> GetMetadataProvider()
{
return CompilerRequestHandler.AssemblyReferenceProvider;
return _compilerServerHost.AssemblyReferenceProvider;
}
protected override uint GetSqmAppID()
......
......@@ -22,6 +22,10 @@
<Project>{76C6F005-C89D-4348-BB4A-391898DBEB52}</Project>
<Name>TestUtilities.Desktop</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Server\Core\ServerCore.csproj">
<Project>{9929e5ae-85ca-46a8-a500-3be7bc634d87}</Project>
<Name>ServerCore</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Server\VBCSCompiler\VBCSCompiler.csproj">
<Project>{9508F118-F62E-4C16-A6F4-7C3B56E166AD}</Project>
<Name>VBCSCompiler</Name>
......@@ -136,4 +140,4 @@
<Import Project="..\..\..\..\..\build\Targets\VSL.Imports.targets" />
<Import Project="..\..\..\..\..\build\Targets\Roslyn.Toolsets.Xunit.targets" />
</ImportGroup>
</Project>
</Project>
\ No newline at end of file
......@@ -169,6 +169,7 @@ End Class
Dim outWriter = New StringWriter()
Dim cmd = New VisualBasicCompilerServer(
New DesktopCompilerServerHost(),
{"/nologo",
"/touchedfiles:" + touchedBase,
source1},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册