This repository has been archived by the owner on Oct 30, 2019. It is now read-only.
/
Csc.cs
69 lines (58 loc) · 2.76 KB
/
Csc.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) Microsoft Open Technologies, Inc. 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.IO;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.Shell.Interop;
namespace Microsoft.CodeAnalysis.CSharp.CommandLine
{
extern alias Microsoft_CodeAnalysis_Desktop;
using FailFast = Microsoft_CodeAnalysis_Desktop::Microsoft.CodeAnalysis.FailFast;
internal sealed class Csc : CSharpCompiler
{
internal Csc(string responseFile, string baseDirectory, string[] args)
: base(CSharpCommandLineParser.Default, responseFile, args, baseDirectory, Environment.GetEnvironmentVariable("LIB"))
{
}
internal static int Run(string[] args)
{
FatalError.Handler = FailFast.OnFatalException;
Csc compiler = new Csc(CSharpResponseFileName, Directory.GetCurrentDirectory(), args);
// We store original encoding and restore it later to revert
// the changes that might be done by /utf8output options
// NOTE: original encoding may not be restored if process terminated
Encoding origEncoding = Console.OutputEncoding;
try
{
if (compiler.Arguments.Utf8Output && Console.IsOutputRedirected)
{
Console.OutputEncoding = Encoding.UTF8;
}
return compiler.Run(Console.Out);
}
finally
{
try
{
Console.OutputEncoding = origEncoding;
}
catch
{ // Try to reset the output encoding, ignore if we can't
}
}
}
protected override uint GetSqmAppID()
{
return SqmServiceProvider.CSHARP_APPID;
}
protected override void CompilerSpecificSqm(IVsSqmMulti sqm, uint sqmSession)
{
sqm.SetDatapoint(sqmSession, SqmServiceProvider.DATAID_SQM_ROSLYN_COMPILERTYPE, (uint)SqmServiceProvider.CompilerType.Compiler);
sqm.SetDatapoint(sqmSession, SqmServiceProvider.DATAID_SQM_ROSLYN_LANGUAGEVERSION, (uint)Arguments.ParseOptions.LanguageVersion);
sqm.SetDatapoint(sqmSession, SqmServiceProvider.DATAID_SQM_ROSLYN_WARNINGLEVEL, (uint)Arguments.CompilationOptions.WarningLevel);
//Project complexity # of source files, # of references
sqm.SetDatapoint(sqmSession, SqmServiceProvider.DATAID_SQM_ROSLYN_SOURCES, (uint)Arguments.SourceFiles.Count());
sqm.SetDatapoint(sqmSession, SqmServiceProvider.DATAID_SQM_ROSLYN_REFERENCES, (uint)Arguments.ReferencePaths.Count());
}
}
}