1
+ #!/usr/bin/env python3
1
2
#
2
3
# signature.py
3
4
#
@@ -44,35 +45,35 @@ def compress_file(filepath, storedname, outpath):
44
45
zipf .write (filepath , arcname = storedname , compress_type = zipfile .ZIP_BZIP2 , compresslevel = 9 )
45
46
46
47
#
47
- # Compute the build signature. The idea is to extract all defines in the configuration headers
48
- # to build a unique reversible signature from this build so it can be included in the binary
49
- # We can reverse the signature to get a 1:1 equivalent configuration file
48
+ # Compute the build signature by extracting all configuration settings and
49
+ # building a unique reversible signature that can be included in the binary.
50
+ # The signature can be reversed to get a 1:1 equivalent configuration file.
50
51
#
51
52
def compute_build_signature (env ):
52
53
if 'BUILD_SIGNATURE' in env :
53
54
return
54
55
56
+ build_path = Path (env ['PROJECT_BUILD_DIR' ], env ['PIOENV' ])
57
+ marlin_json = build_path / 'marlin_config.json'
58
+ marlin_zip = build_path / 'mc.zip'
59
+
55
60
# Definitions from these files will be kept
56
61
files_to_keep = [ 'Marlin/Configuration.h' , 'Marlin/Configuration_adv.h' ]
57
62
58
- build_path = Path (env ['PROJECT_BUILD_DIR' ], env ['PIOENV' ])
59
-
60
63
# Check if we can skip processing
61
64
hashes = ''
62
65
for header in files_to_keep :
63
66
hashes += get_file_sha256sum (header )[0 :10 ]
64
67
65
- marlin_json = build_path / 'marlin_config.json'
66
- marlin_zip = build_path / 'mc.zip'
67
-
68
- # Read existing config file
68
+ # Read a previously exported JSON file
69
+ # Same configuration, skip recomputing the build signature
70
+ same_hash = False
69
71
try :
70
72
with marlin_json .open () as infile :
71
73
conf = json .load (infile )
72
- if conf ['__INITIAL_HASH' ] == hashes :
73
- # Same configuration, skip recomputing the building signature
74
+ same_hash = conf ['__INITIAL_HASH' ] == hashes
75
+ if same_hash :
74
76
compress_file (marlin_json , 'marlin_config.json' , marlin_zip )
75
- return
76
77
except :
77
78
pass
78
79
@@ -125,9 +126,6 @@ def compute_build_signature(env):
125
126
# Remove all boards now
126
127
if key .startswith ("BOARD_" ) and key != "BOARD_INFO_NAME" :
127
128
continue
128
- # Remove all keys ending by "_NAME" as it does not make a difference to the configuration
129
- if key .endswith ("_NAME" ) and key != "CUSTOM_MACHINE_NAME" :
130
- continue
131
129
# Remove all keys ending by "_T_DECLARED" as it's a copy of extraneous system stuff
132
130
if key .endswith ("_T_DECLARED" ):
133
131
continue
@@ -196,7 +194,7 @@ def tryint(key):
196
194
outfile .write (ini_fmt .format (key .lower (), ' = ' + val ))
197
195
198
196
#
199
- # Produce a schema.json file if CONFIG_EXPORT == 3
197
+ # CONFIG_EXPORT 3 = schema.json, 4 = schema.yml
200
198
#
201
199
if config_dump >= 3 :
202
200
try :
@@ -207,7 +205,7 @@ def tryint(key):
207
205
208
206
if conf_schema :
209
207
#
210
- # Produce a schema.json file if CONFIG_EXPORT == 3
208
+ # 3 = schema.json
211
209
#
212
210
if config_dump in (3 , 13 ):
213
211
print ("Generating schema.json ..." )
@@ -217,7 +215,7 @@ def tryint(key):
217
215
schema .dump_json (conf_schema , build_path / 'schema_grouped.json' )
218
216
219
217
#
220
- # Produce a schema.yml file if CONFIG_EXPORT == 4
218
+ # 4 = schema.yml
221
219
#
222
220
elif config_dump == 4 :
223
221
print ("Generating schema.yml ..." )
@@ -243,8 +241,9 @@ def tryint(key):
243
241
244
242
#
245
243
# Produce a JSON file for CONFIGURATION_EMBEDDING or CONFIG_EXPORT == 1
244
+ # Skip if an identical JSON file was already present.
246
245
#
247
- if config_dump == 1 or 'CONFIGURATION_EMBEDDING' in defines :
246
+ if not same_hash and ( config_dump == 1 or 'CONFIGURATION_EMBEDDING' in defines ) :
248
247
with marlin_json .open ('w' ) as outfile :
249
248
json .dump (data , outfile , separators = (',' , ':' ))
250
249
@@ -255,9 +254,10 @@ def tryint(key):
255
254
return
256
255
257
256
# Compress the JSON file as much as we can
258
- compress_file (marlin_json , 'marlin_config.json' , marlin_zip )
257
+ if not same_hash :
258
+ compress_file (marlin_json , 'marlin_config.json' , marlin_zip )
259
259
260
- # Generate a C source file for storing this array
260
+ # Generate a C source file containing the entire ZIP file as an array
261
261
with open ('Marlin/src/mczip.h' ,'wb' ) as result_file :
262
262
result_file .write (
263
263
b'#ifndef NO_CONFIGURATION_EMBEDDING_WARNING\n '
@@ -274,3 +274,8 @@ def tryint(key):
274
274
if count % 16 :
275
275
result_file .write (b'\n ' )
276
276
result_file .write (b'};\n ' )
277
+
278
+ if __name__ == "__main__" :
279
+ # Build required. From command line just explain usage.
280
+ print ("Use schema.py to export JSON and YAML from the command-line." )
281
+ print ("Build Marlin with CONFIG_EXPORT 2 to export 'config.ini'." )
0 commit comments