mirror of
https://github.com/CoolProp/CoolProp.git
synced 2026-04-23 03:00:17 -04:00
Implemented the hash checking of generate_headers.py to avoid rebuilding unnecessarily (https://github.com/CoolProp/CoolProp/issues/34)
Signed-off-by: Ian bell <ian.h.bell@gmail.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import struct
|
||||
import os
|
||||
import argparse, textwrap
|
||||
import sys
|
||||
import generate_headers
|
||||
|
||||
# 0: Input file path relative to dev folder
|
||||
# 1: Output file path relative to include folder
|
||||
@@ -16,7 +17,7 @@ values = [
|
||||
('mixtures/mixture_reducing_parameters.json', 'mixture_reducing_parameters_JSON.h', 'mixture_reducing_parameters_JSON')
|
||||
]
|
||||
|
||||
def TO_CPP(root_dir):
|
||||
def TO_CPP(root_dir, hashes):
|
||||
def to_chunks(l, n):
|
||||
if n<1:
|
||||
n=1
|
||||
@@ -48,17 +49,26 @@ def TO_CPP(root_dir):
|
||||
# Put the lines back together again
|
||||
# The chunks are joined together with commas, and then EOL are used to join the rest
|
||||
hex_string = ',\n'.join([', '.join(chunk) for chunk in chunks])
|
||||
|
||||
# Check if hash is up to date based on using variable as key
|
||||
if variable not in hashes or (variable in hashes and hashes[variable] != generate_headers.get_hash(hex_string)):
|
||||
|
||||
# Generate the output string
|
||||
output = '// File generated by the script dev/JSON_to_CPP.py on '+ str(datetime.now()) + '\n\n'
|
||||
output += '// JSON file encoded in binary form\n'
|
||||
output += 'const unsigned char '+variable+'_binary[] = {\n' + hex_string + '\n};'+'\n\n'
|
||||
output += '// Combined into a single std::string \n'
|
||||
output += 'std::string {v:s}({v:s}_binary, {v:s}_binary + sizeof({v:s}_binary)/sizeof({v:s}_binary[0]));'.format(v = variable)
|
||||
|
||||
f = open(os.path.join(root_dir,'include',outfile), 'w')
|
||||
f.write(output)
|
||||
f.close()
|
||||
# Generate the output string
|
||||
output = '// File generated by the script dev/JSON_to_CPP.py on '+ str(datetime.now()) + '\n\n'
|
||||
output += '// JSON file encoded in binary form\n'
|
||||
output += 'const unsigned char '+variable+'_binary[] = {\n' + hex_string + '\n};'+'\n\n'
|
||||
output += '// Combined into a single std::string \n'
|
||||
output += 'std::string {v:s}({v:s}_binary, {v:s}_binary + sizeof({v:s}_binary)/sizeof({v:s}_binary[0]));'.format(v = variable)
|
||||
|
||||
# Write it to file
|
||||
f = open(os.path.join(root_dir,'include',outfile), 'w')
|
||||
f.write(output)
|
||||
f.close()
|
||||
|
||||
# Store the hash of the data that was written to file (not including the header)
|
||||
hashes[variable] = generate_headers.get_hash(hex_string)
|
||||
else:
|
||||
print(outfile + 'is up to date')
|
||||
|
||||
if __name__=='__main__':
|
||||
parser = argparse.ArgumentParser(
|
||||
|
||||
Reference in New Issue
Block a user