2020-01-04 14:21:38 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import os
|
2020-01-11 21:15:24 +00:00
|
|
|
import os.path as path
|
2020-01-04 14:21:38 +00:00
|
|
|
import traceback
|
|
|
|
import hashlib
|
|
|
|
import subprocess
|
|
|
|
from shutil import which
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def is_tool(name):
|
|
|
|
return which(name) is not None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_script_folder():
|
2020-01-11 21:15:24 +00:00
|
|
|
return path.dirname(path.realpath(sys.argv[0]))
|
2020-01-04 14:21:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def read_all_text_from_file(path):
|
|
|
|
print("Reading {}".format(path))
|
2020-01-12 15:37:02 +00:00
|
|
|
with open(path, 'r', encoding='utf-8') as file:
|
2020-01-11 21:15:24 +00:00
|
|
|
text = file.read()
|
2020-01-04 14:21:38 +00:00
|
|
|
return text
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-01-11 21:15:24 +00:00
|
|
|
def run_python_script(script_path, *args):
|
|
|
|
subprocess.check_call(
|
|
|
|
['py' if is_tool('py') else 'python3', script_path] + [arg for arg in args]
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-01-04 14:21:38 +00:00
|
|
|
def main():
|
2020-01-11 21:15:24 +00:00
|
|
|
hpp_path = path.join(get_script_folder(), '..', 'toml.hpp')
|
2020-01-04 14:21:38 +00:00
|
|
|
hash1 = hashlib.sha1(read_all_text_from_file(hpp_path).encode('utf-8')).hexdigest()
|
|
|
|
print("Hash 1: {}".format(hash1))
|
2020-01-11 21:15:24 +00:00
|
|
|
run_python_script('generate_single_header.py')
|
2020-01-04 14:21:38 +00:00
|
|
|
hash2 = hashlib.sha1(read_all_text_from_file(hpp_path).encode('utf-8')).hexdigest()
|
|
|
|
print("Hash 2: {}".format(hash2))
|
|
|
|
if (hash1 != hash2):
|
|
|
|
print(
|
|
|
|
"toml.hpp wasn't up-to-date!\nRun generate_single_header.py before your commit to prevent this error.",
|
|
|
|
file=sys.stderr
|
|
|
|
)
|
|
|
|
return 1
|
|
|
|
print("toml.hpp was up-to-date")
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
try:
|
|
|
|
sys.exit(main())
|
|
|
|
except Exception as err:
|
|
|
|
print(
|
|
|
|
'Fatal error: [{}] {}'.format(
|
|
|
|
type(err).__name__,
|
|
|
|
str(err)
|
|
|
|
),
|
|
|
|
file=sys.stderr
|
|
|
|
)
|
|
|
|
traceback.print_exc(file=sys.stderr)
|
|
|
|
sys.exit(-1)
|