Skip to content

Commit 8b81673

Browse files
committed
Switch from ICompilerOptions to more complete IProviderOptions.
1 parent af16a9d commit 8b81673

15 files changed

Lines changed: 344 additions & 183 deletions

RoslynCodeProviderTest/CompilerSettingsHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ internal static class CompilerSettingsHelper {
1111

1212
private const int DefaultCompilerServerTTL = 0; // set TTL to 0 to turn of keepalive switch
1313

14+
//smolloy debug degub todo - these two lines, and the next two properties are obsolete.
1415
private static ICompilerSettings _csc = new CompilerSettings(CompilerFullPath(@"csc.exe"), DefaultCompilerServerTTL);
1516
private static ICompilerSettings _vb = new CompilerSettings(CompilerFullPath(@"vbc.exe"), DefaultCompilerServerTTL);
1617

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.IO;
3+
using Microsoft.Build.Framework;
4+
using Microsoft.Build.Utilities;
5+
6+
namespace DotNetCompilerPlatformTasks
7+
{
8+
public class CheckIfVBCSCompilerWillOverride : Task
9+
{
10+
[Required]
11+
public string Src { get; set; }
12+
[Required]
13+
public string Dest { get; set; }
14+
15+
[Output]
16+
public bool WillOverride { get; set; }
17+
18+
public override bool Execute()
19+
{
20+
WillOverride = false;
21+
22+
try
23+
{
24+
WillOverride = File.Exists(Src) && File.Exists(Dest) && (File.GetLastWriteTime(Src) != File.GetLastWriteTime(Dest));
25+
}
26+
catch { return false; }
27+
28+
return true;
29+
}
30+
}
31+
}

src/DotNetCompilerPlatformTasks/Tasks.cs renamed to src/DotNetCompilerPlatformTasks/KillProcess.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Diagnostics;
3-
using System.IO;
43
using System.Linq;
54
using System.Management;
65
using Microsoft.Build.Framework;
@@ -52,28 +51,4 @@ public override bool Execute()
5251
return true;
5352
}
5453
}
55-
56-
public class CheckIfVBCSCompilerWillOverride : Task
57-
{
58-
[Required]
59-
public string Src { get; set; }
60-
[Required]
61-
public string Dest { get; set; }
62-
63-
[Output]
64-
public bool WillOverride { get; set; }
65-
66-
public override bool Execute()
67-
{
68-
WillOverride = false;
69-
70-
try
71-
{
72-
WillOverride = File.Exists(Src) && File.Exists(Dest) && (File.GetLastWriteTime(Src) != File.GetLastWriteTime(Dest));
73-
}
74-
catch { return false; }
75-
76-
return true;
77-
}
78-
}
7954
}

src/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/AppSettings.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
using System;
5-
using System.Collections.Generic;
6-
using System.Collections.Specialized;
7-
using System.Linq;
8-
using System.Text;
9-
using System.Threading.Tasks;
4+
using System.Collections.Specialized;
105
using System.Web.Configuration;
116

127
namespace Microsoft.CodeDom.Providers.DotNetCompilerPlatform {
@@ -32,6 +27,8 @@ private static void EnsureSettingsLoaded() {
3227
lock (_lock) {
3328
if (!_settingsInitialized) {
3429
try {
30+
// I think it should be safe to straight up use regular ConfigurationManager here...
31+
// but if it ain't broke, don't fix it.
3532
LoadSettings(WebConfigurationManager.AppSettings);
3633
}
3734
finally {

src/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/CSharpCodeProvider.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,30 @@ namespace Microsoft.CodeDom.Providers.DotNetCompilerPlatform {
1111
/// </summary>
1212
[DesignerCategory("code")]
1313
public sealed class CSharpCodeProvider : Microsoft.CSharp.CSharpCodeProvider {
14-
private ICompilerSettings _compilerSettings;
14+
private IProviderOptions _providerOptions;
1515

1616
/// <summary>
1717
/// Default Constructor
1818
/// </summary>
1919
public CSharpCodeProvider()
20-
: this(null) {
20+
: this((IProviderOptions)null) {
2121
}
2222

23-
2423
/// <summary>
2524
/// Creates an instance using the given ICompilerSettings
2625
/// </summary>
2726
/// <param name="compilerSettings"></param>
27+
[Obsolete("ICompilerSettings is obsolete. Please update code to use IProviderOptions instead.", false)]
2828
public CSharpCodeProvider(ICompilerSettings compilerSettings = null) {
29-
_compilerSettings = compilerSettings == null ? CompilationSettingsHelper.CSC2 : compilerSettings;
29+
_providerOptions = compilerSettings == null ? CompilationUtil.CSC2 : new ProviderOptions(compilerSettings);
30+
}
31+
32+
/// <summary>
33+
/// Creates an instance using the given IProviderOptions
34+
/// </summary>
35+
/// <param name="providerOptions"></param>
36+
public CSharpCodeProvider(IProviderOptions providerOptions = null) {
37+
_providerOptions = providerOptions == null ? CompilationUtil.CSC2 : providerOptions;
3038
}
3139

3240
/// <summary>
@@ -35,7 +43,7 @@ public CSharpCodeProvider(ICompilerSettings compilerSettings = null) {
3543
/// <returns>An instance of the .NET Compiler Platform C# code compiler</returns>
3644
[Obsolete("Callers should not use the ICodeCompiler interface and should instead use the methods directly on the CodeDomProvider class.")]
3745
public override ICodeCompiler CreateCompiler() {
38-
return new CSharpCompiler(this, _compilerSettings);
46+
return new CSharpCompiler(this, _providerOptions);
3947
}
4048
}
4149
}

src/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/CSharpCompiler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ internal class CSharpCompiler : Compiler {
1414
private static volatile Regex outputRegWithFileAndLine;
1515
private static volatile Regex outputRegSimple;
1616

17-
public CSharpCompiler(CodeDomProvider codeDomProvider, ICompilerSettings compilerSettings = null)
18-
: base(codeDomProvider, compilerSettings) {
17+
public CSharpCompiler(CodeDomProvider codeDomProvider, IProviderOptions providerOptions = null)
18+
: base(codeDomProvider, providerOptions) {
1919
}
2020

2121
protected override string FileExtension {

src/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/Compiler.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
namespace Microsoft.CodeDom.Providers.DotNetCompilerPlatform {
1717
internal abstract class Compiler : ICodeCompiler {
1818
private readonly CodeDomProvider _codeDomProvider;
19-
private readonly ICompilerSettings _compilerSettings;
19+
private readonly IProviderOptions _providerOptions;
2020
private string _compilerFullPath = null;
2121
private const string CLR_PROFILING_SETTING = "COR_ENABLE_PROFILING";
2222
private const string DISABLE_PROFILING = "0";
2323

24-
public Compiler(CodeDomProvider codeDomProvider, ICompilerSettings compilerSettings) {
24+
public Compiler(CodeDomProvider codeDomProvider, IProviderOptions providerOptions)
25+
{
2526
this._codeDomProvider = codeDomProvider;
26-
this._compilerSettings = compilerSettings;
27+
this._providerOptions = providerOptions;
2728
}
2829

2930
public CompilerResults CompileAssemblyFromDom(CompilerParameters options, CodeCompileUnit compilationUnit) {
@@ -132,7 +133,7 @@ protected abstract string FileExtension {
132133
protected virtual string CompilerName {
133134
get {
134135
if (null == _compilerFullPath) {
135-
_compilerFullPath = _compilerSettings.CompilerFullPath;
136+
_compilerFullPath = _providerOptions.CompilerFullPath;
136137

137138
// Try opening the file to make sure the compiler exist. This will throw an exception
138139
// if it doesn't
@@ -277,8 +278,8 @@ private CompilerResults FromFileBatch(CompilerParameters options, string[] fileN
277278
}
278279

279280
// Appending TTL to the command line arguments.
280-
if (_compilerSettings.CompilerServerTimeToLive > 0) {
281-
args = string.Format("/shared /keepalive:\"{0}\" {1}", _compilerSettings.CompilerServerTimeToLive, args);
281+
if (_providerOptions.CompilerServerTimeToLive > 0) {
282+
args = string.Format("/shared /keepalive:\"{0}\" {1}", _providerOptions.CompilerServerTimeToLive, args);
282283
}
283284

284285
Compile(options,

src/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/Microsoft.CodeDom.Providers.DotNetCompilerPlatform.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
<Compile Include="CSharpCompiler.cs" />
5858
<Compile Include="CSharpCodeProvider.cs" />
5959
<Compile Include="Properties\AssemblyInfo.cs" />
60-
<Compile Include="Util\CompilationSettings.cs" />
60+
<Compile Include="Util\IProviderOptions.cs" />
61+
<Compile Include="Util\ProviderOptions.cs" />
6162
<Compile Include="Util\CompilationUtil.cs" />
6263
<Compile Include="Util\ICompilerSettings.cs" />
6364
<Compile Include="VBCodeProvider.cs" />

src/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/Util/CompilationSettings.cs

Lines changed: 0 additions & 123 deletions
This file was deleted.

0 commit comments

Comments
 (0)