提交 f152c992 编写于 作者: J Jared Parsons

Replace timestamp with hash in generated files

Some of our generators were embedding timestamps in the output files as comments.  This was indirectly preventing us from producing determistic builds as every rebuild came from different content.

Issue #7270 is tracking changing determinism to not be influenced by the comments.  Short term though changing this from using a time stamp (which changes and doesn't have meaning between machines) to outputing the checksum of the input file it ran against.
上级 9e6cb00a
...@@ -4,6 +4,7 @@ Imports System.IO ...@@ -4,6 +4,7 @@ Imports System.IO
Imports System.Collections.Generic Imports System.Collections.Generic
Imports System.Console Imports System.Console
Imports System.Runtime.InteropServices Imports System.Runtime.InteropServices
Imports System.Security.Cryptography
''' <summary> ''' <summary>
''' Contains the startup code, command line argument processing, and driving the execution of the tool. ''' Contains the startup code, command line argument processing, and driving the execution of the tool.
...@@ -19,7 +20,7 @@ Friend Module Program ...@@ -19,7 +20,7 @@ Friend Module Program
Dim outputKind As String = Nothing Dim outputKind As String = Nothing
Dim paths As New List(Of String)() Dim paths As New List(Of String)()
For Each arg in args For Each arg In args
Dim c = arg.ToLowerInvariant() Dim c = arg.ToLowerInvariant()
If c = "/test" OrElse c = "/source" OrElse c = "/gettext" Then If c = "/test" OrElse c = "/source" OrElse c = "/gettext" Then
If outputKind IsNot Nothing Then If outputKind IsNot Nothing Then
...@@ -27,7 +28,7 @@ Friend Module Program ...@@ -27,7 +28,7 @@ Friend Module Program
Return exitWithErrors Return exitWithErrors
End If End If
outputKind = c outputKind = c
Else If c = "/?" Then ElseIf c = "/?" Then
PrintUsage() PrintUsage()
Return exitWithErrors Return exitWithErrors
Else Else
...@@ -54,7 +55,8 @@ Friend Module Program ...@@ -54,7 +55,8 @@ Friend Module Program
Return exitWithErrors Return exitWithErrors
End If End If
WriteOutput(outputFile, definition, outputKind) Dim checksum = GetChecksum(inputFile)
WriteOutput(outputFile, definition, outputKind, checksum)
Return exitWithoutErrors Return exitWithoutErrors
...@@ -67,6 +69,14 @@ Friend Module Program ...@@ -67,6 +69,14 @@ Friend Module Program
End Function End Function
Private Function GetChecksum(filePath As String) As String
Dim fileBytes = File.ReadAllBytes(filePath)
Dim func = SHA256.Create()
Dim hashBytes = func.ComputeHash(fileBytes)
Dim data = BitConverter.ToString(hashBytes)
Return data.Replace("-", "")
End Function
Private Sub PrintUsage() Private Sub PrintUsage()
WriteLine("VBSyntaxGenerator.exe input output [/source] [/test]") WriteLine("VBSyntaxGenerator.exe input output [/source] [/test]")
WriteLine(" /source Generates syntax model source code.") WriteLine(" /source Generates syntax model source code.")
...@@ -84,11 +94,11 @@ Friend Module Program ...@@ -84,11 +94,11 @@ Friend Module Program
Return True Return True
End Function End Function
Public Sub WriteOutput(outputFile As String, definition As ParseTree, outputKind As String) Public Sub WriteOutput(outputFile As String, definition As ParseTree, outputKind As String, checksum As String)
Using output As New StreamWriter(outputFile) Using output As New StreamWriter(outputFile)
output.WriteLine("' Definition of syntax model.") output.WriteLine("' Definition of syntax model.")
output.WriteLine("' Generated by a tool on {0:g}", Date.Now) output.WriteLine("' Generated by a tool from SHA256 content {0}", checksum)
output.WriteLine("' DO NOT HAND EDIT") output.WriteLine("' DO NOT HAND EDIT")
...@@ -102,7 +112,7 @@ Friend Module Program ...@@ -102,7 +112,7 @@ Friend Module Program
output.WriteLine("Imports Roslyn.Utilities") output.WriteLine("Imports Roslyn.Utilities")
output.WriteLine("Imports Xunit") output.WriteLine("Imports Xunit")
Dim testWriter As New TestWriter(definition) Dim testWriter As New TestWriter(definition, checksum)
testWriter.WriteTestCode(output) testWriter.WriteTestCode(output)
Case "/gettext" Case "/gettext"
......
...@@ -11,12 +11,14 @@ Imports System.IO ...@@ -11,12 +11,14 @@ Imports System.IO
Public Class TestWriter Public Class TestWriter
Inherits WriteUtils Inherits WriteUtils
Private ReadOnly _checksum As String
Private _writer As TextWriter 'output is sent here. Private _writer As TextWriter 'output is sent here.
Private Const s_externalSourceDirectiveString As String = "ExternalSourceDirective" Private Const s_externalSourceDirectiveString As String = "ExternalSourceDirective"
' Initialize the class with the parse tree to write. ' Initialize the class with the parse tree to write.
Public Sub New(parseTree As ParseTree) Public Sub New(parseTree As ParseTree, checksum As String)
MyBase.New(parseTree) MyBase.New(parseTree)
_checksum = checksum
End Sub End Sub
' Write out the code defining the tree to the give file. ' Write out the code defining the tree to the give file.
...@@ -28,7 +30,7 @@ Public Class TestWriter ...@@ -28,7 +30,7 @@ Public Class TestWriter
Private Sub GenerateFile() Private Sub GenerateFile()
_writer.WriteLine("' Tests for parse trees.") _writer.WriteLine("' Tests for parse trees.")
_writer.WriteLine("' Generated by a tool on {0:g}", DateTime.Now) _writer.WriteLine("' Generated by a tool from SHA256 content {0}", _checksum)
_writer.WriteLine("' DO NOT HAND EDIT") _writer.WriteLine("' DO NOT HAND EDIT")
_writer.WriteLine() _writer.WriteLine()
......
...@@ -11,10 +11,12 @@ Imports System.IO ...@@ -11,10 +11,12 @@ Imports System.IO
Friend Class WriteDumper Friend Class WriteDumper
Inherits WriteUtils Inherits WriteUtils
Private ReadOnly _checksum As String
Private _writer As TextWriter 'output is sent here. Private _writer As TextWriter 'output is sent here.
Public Sub New(parseTree As ParseTree) Public Sub New(parseTree As ParseTree, checksum As String)
MyBase.New(parseTree) MyBase.New(parseTree)
_checksum = checksum
End Sub End Sub
' Write the dumper utility function to the given file. ' Write the dumper utility function to the given file.
...@@ -29,7 +31,7 @@ Friend Class WriteDumper ...@@ -29,7 +31,7 @@ Friend Class WriteDumper
' Write the whole contents of the file. ' Write the whole contents of the file.
Private Sub GenerateFile() Private Sub GenerateFile()
_writer.WriteLine("' Definition of parse trees dumper.") _writer.WriteLine("' Definition of parse trees dumper.")
_writer.WriteLine("' Generated by a tool on {0:g}", DateTime.Now) _writer.WriteLine("' Generated by a tool from SHA256 content {0}", _checksum)
_writer.WriteLine("' DO NOT HAND EDIT") _writer.WriteLine("' DO NOT HAND EDIT")
_writer.WriteLine() _writer.WriteLine()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册