Skip to content
This repository was archived by the owner on Dec 12, 2020. It is now read-only.

Commit 66af177

Browse files
committed
Rollback PR unrelated changes
1 parent a352e29 commit 66af177

3 files changed

Lines changed: 13 additions & 12 deletions

File tree

src/CodeGeneration.Roslyn.Engine/CompilationGenerator.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public class CompilationGenerator
8484
/// <param name="progress">Optional handler of diagnostics provided by code generator.</param>
8585
/// <param name="cancellationToken">Cancellation token to interrupt async operations.</param>
8686
/// <returns>A <see cref="Task.CompletedTask"/>.</returns>
87-
public async Task GenerateAsync(IProgress<Diagnostic> progress, CancellationToken cancellationToken)
87+
public async Task GenerateAsync(IProgress<Diagnostic> progress = null, CancellationToken cancellationToken = default)
8888
{
8989
Verify.Operation(this.Compile != null, $"{nameof(Compile)} must be set first.");
9090
Verify.Operation(this.ReferencePath != null, $"{nameof(ReferencePath)} must be set first.");
@@ -104,14 +104,13 @@ public async Task GenerateAsync(IProgress<Diagnostic> progress, CancellationToke
104104
{
105105
cancellationToken.ThrowIfCancellationRequested();
106106

107-
string sourceHash = Convert.ToBase64String(hasher.ComputeHash(Encoding.UTF8.GetBytes(inputSyntaxTree.FilePath)), 0, 6).Replace(Path.AltDirectorySeparatorChar, '-').Replace(Path.DirectorySeparatorChar, '-');
107+
string sourceHash = Convert.ToBase64String(hasher.ComputeHash(Encoding.UTF8.GetBytes(inputSyntaxTree.FilePath)), 0, 6).Replace('/', '-');
108108
Logger.Info($"File \"{inputSyntaxTree.FilePath}\" hashed to {sourceHash}");
109-
string outputFilePath = Path.Combine(this.IntermediateOutputDirectory, Path.GetFileNameWithoutExtension(inputSyntaxTree.FilePath) + FormattableString.Invariant($".{sourceHash}.generated.cs"));
110-
var outputFile = new FileInfo(outputFilePath);
109+
string outputFilePath = Path.Combine(this.IntermediateOutputDirectory, Path.GetFileNameWithoutExtension(inputSyntaxTree.FilePath) + $".{sourceHash}.generated.cs");
111110

112111
// Code generation is relatively fast, but it's not free.
113112
// So skip files that haven't changed since we last generated them.
114-
DateTime outputLastModified = outputFile.Exists ? outputFile.LastWriteTime : DateTime.MinValue;
113+
DateTime outputLastModified = File.Exists(outputFilePath) ? File.GetLastWriteTime(outputFilePath) : DateTime.MinValue;
115114
if (File.GetLastWriteTime(inputSyntaxTree.FilePath) > outputLastModified || assembliesLastModified > outputLastModified)
116115
{
117116
int retriesLeft = 3;
@@ -127,7 +126,7 @@ public async Task GenerateAsync(IProgress<Diagnostic> progress, CancellationToke
127126
progress,
128127
cancellationToken);
129128
var outputText = await generatedSyntaxTree.GetTextAsync(cancellationToken);
130-
using (var outputFileStream = outputFile.OpenWrite())
129+
using (var outputFileStream = File.OpenWrite(outputFilePath))
131130
using (var outputWriter = new StreamWriter(outputFileStream))
132131
{
133132
outputText.Write(outputWriter, cancellationToken);
@@ -143,7 +142,7 @@ public async Task GenerateAsync(IProgress<Diagnostic> progress, CancellationToke
143142
bool anyTypesGenerated = root.DescendantNodes().OfType<TypeDeclarationSyntax>().Any();
144143
if (!anyTypesGenerated)
145144
{
146-
this.emptyGeneratedFiles.Add(outputFile.FullName);
145+
this.emptyGeneratedFiles.Add(outputFilePath);
147146
}
148147
}
149148
break;
@@ -163,7 +162,7 @@ public async Task GenerateAsync(IProgress<Diagnostic> progress, CancellationToke
163162
while (true);
164163
}
165164

166-
this.generatedFiles.Add(outputFile.FullName);
165+
this.generatedFiles.Add(outputFilePath);
167166
}
168167
}
169168

@@ -233,7 +232,10 @@ private static void ReportError(IProgress<Diagnostic> progress, string id, Synta
233232

234233
var location = inputSyntaxTree != null ? Location.Create(inputSyntaxTree, TextSpan.FromBounds(0, 0)) : Location.None;
235234

236-
var messageArgs = new object[] { ex };
235+
var messageArgs = new object[]
236+
{
237+
ex,
238+
};
237239

238240
var reportDiagnostic = Diagnostic.Create(descriptor, location, messageArgs);
239241

src/CodeGeneration.Roslyn.Engine/DocumentTransform.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static async Task<SyntaxTree> TransformAsync(
5050
string projectDirectory,
5151
Func<AssemblyName, Assembly> assemblyLoader,
5252
IProgress<Diagnostic> progress,
53-
CancellationToken cancellationToken)
53+
CancellationToken cancellationToken = default)
5454
{
5555
Requires.NotNull(compilation, nameof(compilation));
5656
Requires.NotNull(inputDocument, nameof(inputDocument));

src/CodeGeneration.Roslyn.Tests/Helpers/CompilationTestsBase.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.IO;
77
using System.Linq;
88
using System.Reflection;
9-
using System.Threading;
109
using System.Threading.Tasks;
1110
using CodeGeneration.Roslyn;
1211
using CodeGeneration.Roslyn.Engine;
@@ -79,7 +78,7 @@ protected static async Task<SyntaxTree> GenerateAsync(string source)
7978
var diagnostics = compilation.GetDiagnostics();
8079
Assert.Empty(diagnostics.Where(x => x.Severity >= DiagnosticSeverity.Warning));
8180
var progress = new Progress<Diagnostic>();
82-
var result = await DocumentTransform.TransformAsync(compilation, tree, null, Assembly.Load, progress, CancellationToken.None);
81+
var result = await DocumentTransform.TransformAsync(compilation, tree, null, Assembly.Load, progress);
8382
return result;
8483
}
8584

0 commit comments

Comments
 (0)