Skip to content

Commit

Permalink
Fix unstable MSBuild compilation cache (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgiannuzzi authored Nov 9, 2021
1 parent 9caf7af commit 699644e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion T4.Build/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Concurrent;
using System.CommandLine;
using System.CommandLine.Invocation;
Expand Down Expand Up @@ -44,6 +45,7 @@ static int Transform(FileInfo[] templates, int lockTimeout, bool skipUpToDate, b
{
using (var locker = new Lock($"Global\\T4.Build.transform.{ComputeHash(templates)}.lock", lockTimeout))
{
var outputQueue = new ConcurrentQueue<String>();
var errorQueue = new ConcurrentQueue<CompilerErrorCollection>();
var didSomeWork = false;
var stopwatch = new Stopwatch();
Expand All @@ -63,7 +65,7 @@ static int Transform(FileInfo[] templates, int lockTimeout, bool skipUpToDate, b
if (generator.Errors.HasErrors)
errorQueue.Enqueue(generator.Errors);
else
Console.WriteLine(generator.OutputFile);
outputQueue.Enqueue(generator.OutputFile);
}
catch (Exception e)
{
Expand All @@ -72,6 +74,12 @@ static int Transform(FileInfo[] templates, int lockTimeout, bool skipUpToDate, b
});
stopwatch.Stop();

// Sort the generated file names so that the MSBuild compilation cache hash remains stable
var outputs = outputQueue.ToArray();
Array.Sort(outputs, new CaseInsensitiveComparer());
foreach (var output in outputs)
Console.WriteLine(output);

if (didSomeWork && errorQueue.IsEmpty)
Console.Error.WriteLine($"Templates transformed for {Path.GetFileName(Directory.GetCurrentDirectory())} (in {stopwatch.ElapsedMilliseconds / 1000.0} sec).");

Expand Down

0 comments on commit 699644e

Please sign in to comment.