Skip to content

Commit fe33488

Browse files
IIFEBuild Agent
andauthored
Option to allow caller to specify it does not want unchanged output files to be modified. This supports incremental build in VS. (#1373)
Check if generated code is different to existing files and only overwrite if so Co-authored-by: Build Agent <[email protected]>
1 parent e31dc22 commit fe33488

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Generator/Driver.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,14 +316,23 @@ public void SaveCode(IEnumerable<GeneratorOutput> outputs)
316316
var fileRelativePath = $"{fileBase}.{template.FileExtension}";
317317

318318
var file = Path.Combine(outputPath, fileRelativePath);
319-
File.WriteAllText(file, template.Generate());
319+
WriteGeneratedCodeToFile(file, template.Generate());
320320
output.TranslationUnit.Module.CodeFiles.Add(file);
321321

322322
Diagnostics.Message("Generated '{0}'", fileRelativePath);
323323
}
324324
}
325325
}
326326

327+
private void WriteGeneratedCodeToFile(string file, string generatedCode)
328+
{
329+
var fi = new FileInfo(file);
330+
331+
if (!fi.Exists || fi.Length != generatedCode.Length ||
332+
File.ReadAllText(file) != generatedCode)
333+
File.WriteAllText(file, generatedCode);
334+
}
335+
327336
private static readonly Dictionary<Module, string> libraryMappings = new Dictionary<Module, string>();
328337

329338
public void CompileCode(Module module)

0 commit comments

Comments
 (0)