Skip to content

Commit b7fd046

Browse files
committed
🔧 Add date, version to Config Export
1 parent 4c9146c commit b7fd046

6 files changed

Lines changed: 50 additions & 130 deletions

File tree

Marlin/Configuration_adv.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
// @section develop
3636

3737
/**
38-
* Configuration Dump
38+
* Configuration Export
3939
*
40-
* Dump the configuration as part of the build. (See signature.py)
40+
* Export the configuration as part of the build. (See signature.py)
4141
* Output files are saved with the build (e.g., .pio/build/mega2560).
4242
*
4343
* See `build_all_examples --ini` as an example of config.ini archiving.
@@ -48,7 +48,7 @@
4848
* 3 = schema.json - The entire configuration schema. (13 = pattern groups)
4949
* 4 = schema.yml - The entire configuration schema.
5050
*/
51-
//#define CONFIG_DUMP // :[1:'JSON', 2:'config.ini', 3:'schema.json', 4:'schema.yml']
51+
//#define CONFIG_EXPORT // :[1:'JSON', 2:'config.ini', 3:'schema.json', 4:'schema.yml']
5252

5353
//===========================================================================
5454
//============================= Thermal Settings ============================

Marlin/base.ini

Lines changed: 0 additions & 107 deletions
This file was deleted.

Marlin/config.ini

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@
44
#
55
[config:base]
66
ini_use_config = none
7-
#ini_use_config = base.ini, another.ini
8-
#ini_use_config = example/Creality/Ender-5 Plus
9-
#ini_use_config = https://me.myserver.com/path/to/configs
10-
#ini_use_config = base
11-
#config_dump = 2
127

8+
# Load all config: sections in this file
9+
;ini_use_config = all
10+
# Load config file relative to Marlin/
11+
;ini_use_config = another.ini
12+
# Download configurations from GitHub
13+
;ini_use_config = example/Creality/Ender-5 Plus @ bugfix-2.1.x
14+
# Download configurations from your server
15+
;ini_use_config = https://me.myserver.com/path/to/configs
16+
# Evaluate config:base and do a config dump
17+
;ini_use_config = base
18+
;config_export = 2
19+
20+
[config:minimal]
1321
motherboard = BOARD_RAMPS_14_EFB
1422
serial_port = 0
1523
baudrate = 250000

buildroot/share/PlatformIO/scripts/configuration.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def apply_opt(name, val, conf=None):
1818
if name == "lcd": name, val = val, "on"
1919

2020
# Create a regex to match the option and capture parts of the line
21-
regex = re.compile(r'^(\s*)(//\s*)?(#define\s+)(' + name + r'\b)(\s*)(.*?)(\s*)(//.*)?$', re.IGNORECASE)
21+
regex = re.compile(rf'^(\s*)(//\s*)?(#define\s+)({name}\b)(\s*)(.*?)(\s*)(//.*)?$', re.IGNORECASE)
2222

2323
# Find and enable and/or update all matches
2424
for file in ("Configuration.h", "Configuration_adv.h"):
@@ -87,6 +87,9 @@ def fetch_example(path):
8787
if path.endswith("/"):
8888
path = path[:-1]
8989

90+
if '@' in path:
91+
path, brch = map(strip, path.split('@'))
92+
9093
url = path.replace("%", "%25").replace(" ", "%20")
9194
if not path.startswith('http'):
9295
url = "https://raw.githubusercontent.com/MarlinFirmware/Configurations/bugfix-2.1.x/config/%s" % url

buildroot/share/PlatformIO/scripts/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class Parse:
9595
# Regex for #define NAME [VALUE] [COMMENT] with sanitized line
9696
defgrep = re.compile(r'^(//)?\s*(#define)\s+([A-Za-z0-9_]+)\s*(.*?)\s*(//.+)?$')
9797
# Defines to ignore
98-
ignore = ('CONFIGURATION_H_VERSION', 'CONFIGURATION_ADV_H_VERSION', 'CONFIG_DUMP')
98+
ignore = ('CONFIGURATION_H_VERSION', 'CONFIGURATION_ADV_H_VERSION', 'CONFIG_EXPORT')
9999
# Start with unknown state
100100
state = Parse.NORMAL
101101
# Serial ID

buildroot/share/PlatformIO/scripts/signature.py

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#
22
# signature.py
33
#
4-
import subprocess,re,json,hashlib
54
import schema
5+
6+
import subprocess,re,json,hashlib
7+
from datetime import datetime
68
from pathlib import Path
79

810
#
@@ -112,9 +114,9 @@ def compute_build_signature(env):
112114
defines[key] = value if len(value) else ""
113115

114116
#
115-
# Continue to gather data for CONFIGURATION_EMBEDDING or CONFIG_DUMP
117+
# Continue to gather data for CONFIGURATION_EMBEDDING or CONFIG_EXPORT
116118
#
117-
if not ('CONFIGURATION_EMBEDDING' in defines or 'CONFIG_DUMP' in defines):
119+
if not ('CONFIGURATION_EMBEDDING' in defines or 'CONFIG_EXPORT' in defines):
118120
return
119121

120122
# Second step is to filter useless macro
@@ -157,18 +159,32 @@ def tryint(key):
157159
except:
158160
return 0
159161

160-
config_dump = tryint('CONFIG_DUMP')
162+
config_dump = tryint('CONFIG_EXPORT')
161163

162164
#
163-
# Produce an INI file if CONFIG_DUMP == 2
165+
# Produce an INI file if CONFIG_EXPORT == 2
164166
#
165167
if config_dump == 2:
166168
print("Generating config.ini ...")
167-
ignore = ('CONFIGURATION_H_VERSION', 'CONFIGURATION_ADV_H_VERSION', 'CONFIG_DUMP')
168-
filegrp = { 'Configuration.h':'config:basic', 'Configuration_adv.h':'config:advanced' }
169169
config_ini = build_path / 'config.ini'
170170
with config_ini.open('w') as outfile:
171-
outfile.write('#\n# Marlin Firmware\n# config.ini - Options to apply before the build\n#\n')
171+
ignore = ('CONFIGURATION_H_VERSION', 'CONFIGURATION_ADV_H_VERSION', 'CONFIG_EXPORT')
172+
filegrp = { 'Configuration.h':'config:basic', 'Configuration_adv.h':'config:advanced' }
173+
vers = defines["CONFIGURATION_H_VERSION"]
174+
dt_string = datetime.now().strftime("%Y-%m-%d at %H:%M:%S")
175+
ini_fmt = '{0:40}{1}\n'
176+
outfile.write(
177+
'#\n'
178+
+ '# Marlin Firmware\n'
179+
+ '# config.ini - Options to apply before the build\n'
180+
+ '#\n'
181+
+ f'# Generated by Marlin build on {dt_string}\n'
182+
+ '#\n'
183+
+ '\n'
184+
+ '[config:base]\n'
185+
+ ini_fmt.format('ini_use_config', ' = all')
186+
+ ini_fmt.format('ini_config_vers', f' = {vers}')
187+
)
172188
# Loop through the data array of arrays
173189
for header in data:
174190
if header.startswith('__'):
@@ -177,10 +193,10 @@ def tryint(key):
177193
for key in sorted(data[header]):
178194
if key not in ignore:
179195
val = 'on' if data[header][key] == '' else data[header][key]
180-
outfile.write('{0:40}{1}'.format(key.lower(), ' = ' + val) + '\n')
196+
outfile.write(ini_fmt.format(key.lower(), ' = ' + val))
181197

182198
#
183-
# Produce a schema.json file if CONFIG_DUMP == 3
199+
# Produce a schema.json file if CONFIG_EXPORT == 3
184200
#
185201
if config_dump >= 3:
186202
try:
@@ -191,7 +207,7 @@ def tryint(key):
191207

192208
if conf_schema:
193209
#
194-
# Produce a schema.json file if CONFIG_DUMP == 3
210+
# Produce a schema.json file if CONFIG_EXPORT == 3
195211
#
196212
if config_dump in (3, 13):
197213
print("Generating schema.json ...")
@@ -201,7 +217,7 @@ def tryint(key):
201217
schema.dump_json(conf_schema, build_path / 'schema_grouped.json')
202218

203219
#
204-
# Produce a schema.yml file if CONFIG_DUMP == 4
220+
# Produce a schema.yml file if CONFIG_EXPORT == 4
205221
#
206222
elif config_dump == 4:
207223
print("Generating schema.yml ...")
@@ -226,7 +242,7 @@ def tryint(key):
226242
pass
227243

228244
#
229-
# Produce a JSON file for CONFIGURATION_EMBEDDING or CONFIG_DUMP == 1
245+
# Produce a JSON file for CONFIGURATION_EMBEDDING or CONFIG_EXPORT == 1
230246
#
231247
if config_dump == 1 or 'CONFIGURATION_EMBEDDING' in defines:
232248
with marlin_json.open('w') as outfile:

0 commit comments

Comments
 (0)