Skip to content

Commit dab61e0

Browse files
committed
🔨 Fix signature.py export with same hash
1 parent ef430b8 commit dab61e0

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

buildroot/share/PlatformIO/scripts/signature.py

100644100755
+26-21
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python3
12
#
23
# signature.py
34
#
@@ -44,35 +45,35 @@ def compress_file(filepath, storedname, outpath):
4445
zipf.write(filepath, arcname=storedname, compress_type=zipfile.ZIP_BZIP2, compresslevel=9)
4546

4647
#
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.
5051
#
5152
def compute_build_signature(env):
5253
if 'BUILD_SIGNATURE' in env:
5354
return
5455

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+
5560
# Definitions from these files will be kept
5661
files_to_keep = [ 'Marlin/Configuration.h', 'Marlin/Configuration_adv.h' ]
5762

58-
build_path = Path(env['PROJECT_BUILD_DIR'], env['PIOENV'])
59-
6063
# Check if we can skip processing
6164
hashes = ''
6265
for header in files_to_keep:
6366
hashes += get_file_sha256sum(header)[0:10]
6467

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
6971
try:
7072
with marlin_json.open() as infile:
7173
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:
7476
compress_file(marlin_json, 'marlin_config.json', marlin_zip)
75-
return
7677
except:
7778
pass
7879

@@ -125,9 +126,6 @@ def compute_build_signature(env):
125126
# Remove all boards now
126127
if key.startswith("BOARD_") and key != "BOARD_INFO_NAME":
127128
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
131129
# Remove all keys ending by "_T_DECLARED" as it's a copy of extraneous system stuff
132130
if key.endswith("_T_DECLARED"):
133131
continue
@@ -196,7 +194,7 @@ def tryint(key):
196194
outfile.write(ini_fmt.format(key.lower(), ' = ' + val))
197195

198196
#
199-
# Produce a schema.json file if CONFIG_EXPORT == 3
197+
# CONFIG_EXPORT 3 = schema.json, 4 = schema.yml
200198
#
201199
if config_dump >= 3:
202200
try:
@@ -207,7 +205,7 @@ def tryint(key):
207205

208206
if conf_schema:
209207
#
210-
# Produce a schema.json file if CONFIG_EXPORT == 3
208+
# 3 = schema.json
211209
#
212210
if config_dump in (3, 13):
213211
print("Generating schema.json ...")
@@ -217,7 +215,7 @@ def tryint(key):
217215
schema.dump_json(conf_schema, build_path / 'schema_grouped.json')
218216

219217
#
220-
# Produce a schema.yml file if CONFIG_EXPORT == 4
218+
# 4 = schema.yml
221219
#
222220
elif config_dump == 4:
223221
print("Generating schema.yml ...")
@@ -243,8 +241,9 @@ def tryint(key):
243241

244242
#
245243
# Produce a JSON file for CONFIGURATION_EMBEDDING or CONFIG_EXPORT == 1
244+
# Skip if an identical JSON file was already present.
246245
#
247-
if config_dump == 1 or 'CONFIGURATION_EMBEDDING' in defines:
246+
if not same_hash and (config_dump == 1 or 'CONFIGURATION_EMBEDDING' in defines):
248247
with marlin_json.open('w') as outfile:
249248
json.dump(data, outfile, separators=(',', ':'))
250249

@@ -255,9 +254,10 @@ def tryint(key):
255254
return
256255

257256
# 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)
259259

260-
# Generate a C source file for storing this array
260+
# Generate a C source file containing the entire ZIP file as an array
261261
with open('Marlin/src/mczip.h','wb') as result_file:
262262
result_file.write(
263263
b'#ifndef NO_CONFIGURATION_EMBEDDING_WARNING\n'
@@ -274,3 +274,8 @@ def tryint(key):
274274
if count % 16:
275275
result_file.write(b'\n')
276276
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

Comments
 (0)