@@ -35,18 +35,27 @@ def enabled_defines(filepath):
35
35
'''
36
36
outdict = {}
37
37
section = "user"
38
- spatt = re .compile (r".*@section +([-a-zA-Z0-9_\s]+)$" ) # must match @section ...
38
+ spatt = re .compile (r".*@section +([-a-zA-Z0-9_\s]+)$" ) # @section ...
39
39
40
40
f = open (filepath , encoding = "utf8" ).read ().split ("\n " )
41
41
42
- # Get the full contents of the file and remove all block comments.
43
- # This will avoid false positives from #defines in comments
44
- f = re .sub (r'/\*.*?\*/' , '' , '\n ' .join (f ), flags = re .DOTALL ).split ("\n " )
45
-
42
+ incomment = False
46
43
for line in f :
47
44
sline = line .strip ()
45
+
48
46
m = re .match (spatt , sline ) # @section ...
49
47
if m : section = m .group (1 ).strip () ; continue
48
+
49
+ if incomment :
50
+ if '*/' in sline :
51
+ incomment = False
52
+ continue
53
+ else :
54
+ mpos , spos = sline .find ('/*' ), sline .find ('//' )
55
+ if mpos >= 0 and (spos < 0 or spos > mpos ):
56
+ incomment = True
57
+ continue
58
+
50
59
if sline [:7 ] == "#define" :
51
60
# Extract the key here (we don't care about the value)
52
61
kv = sline [8 :].strip ().split ()
@@ -70,6 +79,11 @@ def compress_file(filepath, storedname, outpath):
70
79
with zipfile .ZipFile (outpath , 'w' , compression = zipfile .ZIP_BZIP2 , compresslevel = 9 ) as zipf :
71
80
zipf .write (filepath , arcname = storedname , compress_type = zipfile .ZIP_BZIP2 , compresslevel = 9 )
72
81
82
+ ignore = ('CONFIGURATION_H_VERSION' , 'CONFIGURATION_ADV_H_VERSION' , 'CONFIG_EXAMPLES_DIR' , 'CONFIG_EXPORT' )
83
+
84
+ #
85
+ # Compute a build signature and/or export the configuration
86
+ #
73
87
def compute_build_signature (env ):
74
88
'''
75
89
Compute the build signature by extracting all configuration settings and
@@ -81,11 +95,17 @@ def compute_build_signature(env):
81
95
env .Append (BUILD_SIGNATURE = 1 )
82
96
83
97
build_path = Path (env ['PROJECT_BUILD_DIR' ], env ['PIOENV' ])
84
- marlin_json = build_path / 'marlin_config.json'
98
+ json_name = 'marlin_config.json'
99
+ marlin_json = build_path / json_name
85
100
marlin_zip = build_path / 'mc.zip'
86
101
102
+ # ANSI colors
103
+ green = "\u001b [32m"
104
+ yellow = "\u001b [33m"
105
+ red = "\u001b [31m"
106
+
87
107
# Definitions from these files will be kept
88
- header_paths = [ 'Marlin/Configuration.h' , 'Marlin/Configuration_adv.h' ]
108
+ header_paths = ( 'Marlin/Configuration.h' , 'Marlin/Configuration_adv.h' )
89
109
90
110
# Check if we can skip processing
91
111
hashes = ''
@@ -100,7 +120,7 @@ def compute_build_signature(env):
100
120
conf = json .load (infile )
101
121
same_hash = conf ['__INITIAL_HASH' ] == hashes
102
122
if same_hash :
103
- compress_file (marlin_json , 'marlin_config.json' , marlin_zip )
123
+ compress_file (marlin_json , json_name , marlin_zip )
104
124
except :
105
125
pass
106
126
@@ -179,25 +199,28 @@ def tryint(key):
179
199
extended_dump = config_dump > 100
180
200
if extended_dump : config_dump -= 100
181
201
202
+ # Get the schema class for exports that require it
203
+ if config_dump in (3 , 4 ) or (extended_dump and config_dump in (2 , 5 )):
204
+ try :
205
+ conf_schema = schema .extract ()
206
+ except Exception as exc :
207
+ print (red + "Error: " + str (exc ))
208
+ conf_schema = None
209
+
182
210
#
183
211
# Produce an INI file if CONFIG_EXPORT == 2
184
212
#
185
213
if config_dump == 2 :
186
- print ("Generating config.ini ..." )
214
+ print (yellow + "Generating config.ini ..." )
187
215
188
216
ini_fmt = '{0:40} = {1}'
189
217
ext_fmt = '{0:40} {1}'
190
- ignore = ('CONFIGURATION_H_VERSION' , 'CONFIGURATION_ADV_H_VERSION' , 'CONFIG_EXAMPLES_DIR' , 'CONFIG_EXPORT' )
191
218
192
219
if extended_dump :
193
220
# Extended export will dump config options by section
194
221
195
222
# We'll use Schema class to get the sections
196
- try :
197
- conf_schema = schema .extract ()
198
- except Exception as exc :
199
- print ("Error: " + str (exc ))
200
- exit (1 )
223
+ if not conf_schema : exit (1 )
201
224
202
225
# Then group options by schema @section
203
226
sections = {}
@@ -305,27 +328,22 @@ def tryint(key):
305
328
for header in real_config :
306
329
outfile .write (f'\n [{ filegrp [header ]} ]\n ' )
307
330
for name in sorted (real_config [header ]):
308
- if name not in ignore :
309
- val = real_config [header ][name ]['value' ]
310
- if val == '' : val = 'on'
311
- outfile .write (ini_fmt .format (name .lower (), val ) + '\n ' )
331
+ if name in ignore : continue
332
+ val = real_config [header ][name ]['value' ]
333
+ if val == '' : val = 'on'
334
+ outfile .write (ini_fmt .format (name .lower (), val ) + '\n ' )
312
335
313
336
#
314
337
# CONFIG_EXPORT 3 = schema.json, 4 = schema.yml
315
338
#
316
- if config_dump >= 3 :
317
- try :
318
- conf_schema = schema .extract ()
319
- except Exception as exc :
320
- print ("Error: " + str (exc ))
321
- conf_schema = None
339
+ if config_dump in (3 , 4 ):
322
340
323
341
if conf_schema :
324
342
#
325
343
# 3 = schema.json
326
344
#
327
345
if config_dump in (3 , 13 ):
328
- print ("Generating schema.json ..." )
346
+ print (yellow + "Generating schema.json ..." )
329
347
schema .dump_json (conf_schema , build_path / 'schema.json' )
330
348
if config_dump == 13 :
331
349
schema .group_options (conf_schema )
@@ -335,7 +353,7 @@ def tryint(key):
335
353
# 4 = schema.yml
336
354
#
337
355
elif config_dump == 4 :
338
- print ("Generating schema.yml ..." )
356
+ print (yellow + "Generating schema.yml ..." )
339
357
try :
340
358
import yaml
341
359
except ImportError :
@@ -355,7 +373,7 @@ def tryint(key):
355
373
356
374
json_data = {}
357
375
if extended_dump :
358
- print ("Extended dump ..." )
376
+ print (yellow + "Extended dump ..." )
359
377
for header in real_config :
360
378
confs = real_config [header ]
361
379
json_data [header ] = {}
@@ -395,7 +413,7 @@ def tryint(key):
395
413
396
414
# Compress the JSON file as much as we can
397
415
if not same_hash :
398
- compress_file (marlin_json , 'marlin_config.json' , marlin_zip )
416
+ compress_file (marlin_json , json_name , marlin_zip )
399
417
400
418
# Generate a C source file containing the entire ZIP file as an array
401
419
with open ('Marlin/src/mczip.h' ,'wb' ) as result_file :
0 commit comments