File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -137,8 +137,9 @@ dmypy.json
137137
138138* .cproject
139139
140- # generated parser
140+ # generated parser and checksum
141141src /scenic /syntax /parser.py
142+ src /scenic /syntax /.parser_checksum
142143
143144# generated media/output
144145simulation.gif
Original file line number Diff line number Diff line change 11"""The Scenic compiler and associated support code."""
22
3+ import hashlib as _hashlib
34import pathlib as _pathlib
45import subprocess as _subprocess
56import sys as _sys
89_projectRootDir = _syntaxDir .parent .parent .parent
910_grammarPath = _syntaxDir / "scenic.gram"
1011_parserPath = _syntaxDir / "parser.py"
12+ _checksumPath = _syntaxDir / ".parser_checksum"
1113
1214
1315def buildParser ():
@@ -30,10 +32,30 @@ def buildParser():
3032 capture_output = True ,
3133 text = True ,
3234 )
35+
36+ with open (_checksumPath , "wb" ) as f :
37+ f .write (getParserHash ())
38+
3339 return result
3440
3541
36- if not _parserPath .exists ():
42+ def getParserHash ():
43+ with open (_parserPath , "rb" ) as f :
44+ data = f .read ()
45+ return _hashlib .blake2b (data ).digest ()
46+
47+
48+ def checksumValid ():
49+ if not _checksumPath .exists ():
50+ return False
51+
52+ with open (_checksumPath , "rb" ) as f :
53+ checksum = f .read ()
54+
55+ return checksum == getParserHash ()
56+
57+
58+ if not _parserPath .exists () or not checksumValid ():
3759 _result = buildParser ()
3860 _retcode = _result .returncode
3961 if _retcode != 0 :
You can’t perform that action at this time.
0 commit comments