diff --git a/src/Tools/Source/CompilerGeneratorTools/Source/VisualBasicSyntaxGenerator/Program.vb b/src/Tools/Source/CompilerGeneratorTools/Source/VisualBasicSyntaxGenerator/Program.vb index 7938edbe47f755addd83bb7a12cbbfdec2895134..6e727d92247646020f6cf8865e65c62c898d1c45 100644 --- a/src/Tools/Source/CompilerGeneratorTools/Source/VisualBasicSyntaxGenerator/Program.vb +++ b/src/Tools/Source/CompilerGeneratorTools/Source/VisualBasicSyntaxGenerator/Program.vb @@ -4,6 +4,7 @@ Imports System.IO Imports System.Collections.Generic Imports System.Console Imports System.Runtime.InteropServices +Imports System.Security.Cryptography ''' ''' Contains the startup code, command line argument processing, and driving the execution of the tool. @@ -19,7 +20,7 @@ Friend Module Program Dim outputKind As String = Nothing Dim paths As New List(Of String)() - For Each arg in args + For Each arg In args Dim c = arg.ToLowerInvariant() If c = "/test" OrElse c = "/source" OrElse c = "/gettext" Then If outputKind IsNot Nothing Then @@ -27,7 +28,7 @@ Friend Module Program Return exitWithErrors End If outputKind = c - Else If c = "/?" Then + ElseIf c = "/?" Then PrintUsage() Return exitWithErrors Else @@ -54,7 +55,8 @@ Friend Module Program Return exitWithErrors End If - WriteOutput(outputFile, definition, outputKind) + Dim checksum = GetChecksum(inputFile) + WriteOutput(outputFile, definition, outputKind, checksum) Return exitWithoutErrors @@ -67,6 +69,14 @@ Friend Module Program 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() WriteLine("VBSyntaxGenerator.exe input output [/source] [/test]") WriteLine(" /source Generates syntax model source code.") @@ -84,11 +94,11 @@ Friend Module Program Return True 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) 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") @@ -102,7 +112,7 @@ Friend Module Program output.WriteLine("Imports Roslyn.Utilities") output.WriteLine("Imports Xunit") - Dim testWriter As New TestWriter(definition) + Dim testWriter As New TestWriter(definition, checksum) testWriter.WriteTestCode(output) Case "/gettext" diff --git a/src/Tools/Source/CompilerGeneratorTools/Source/VisualBasicSyntaxGenerator/Tests/TestWriter.vb b/src/Tools/Source/CompilerGeneratorTools/Source/VisualBasicSyntaxGenerator/Tests/TestWriter.vb index 0c32658cb93215c178462dcce8cc524690a62341..576411a2fb841b4eb5b5bc0f84256445840b40e4 100644 --- a/src/Tools/Source/CompilerGeneratorTools/Source/VisualBasicSyntaxGenerator/Tests/TestWriter.vb +++ b/src/Tools/Source/CompilerGeneratorTools/Source/VisualBasicSyntaxGenerator/Tests/TestWriter.vb @@ -11,12 +11,14 @@ Imports System.IO Public Class TestWriter Inherits WriteUtils + Private ReadOnly _checksum As String Private _writer As TextWriter 'output is sent here. Private Const s_externalSourceDirectiveString As String = "ExternalSourceDirective" ' 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) + _checksum = checksum End Sub ' Write out the code defining the tree to the give file. @@ -28,7 +30,7 @@ Public Class TestWriter Private Sub GenerateFile() _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() diff --git a/src/Tools/Source/CompilerGeneratorTools/Source/VisualBasicSyntaxGenerator/Util/WriteDumper.vb b/src/Tools/Source/CompilerGeneratorTools/Source/VisualBasicSyntaxGenerator/Util/WriteDumper.vb index c2246c6a94f744c7ddd3aa4c859f056597c7f107..20c7ec6df19368cc5924442e2d57fd1da57d60ae 100644 --- a/src/Tools/Source/CompilerGeneratorTools/Source/VisualBasicSyntaxGenerator/Util/WriteDumper.vb +++ b/src/Tools/Source/CompilerGeneratorTools/Source/VisualBasicSyntaxGenerator/Util/WriteDumper.vb @@ -11,10 +11,12 @@ Imports System.IO Friend Class WriteDumper Inherits WriteUtils + Private ReadOnly _checksum As String 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) + _checksum = checksum End Sub ' Write the dumper utility function to the given file. @@ -29,7 +31,7 @@ Friend Class WriteDumper ' Write the whole contents of the file. Private Sub GenerateFile() _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()