mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2025-07-16 11:17:48 -06:00
🔨 Build script improvements
This commit is contained in:
parent
b94c75bcda
commit
3b33f7ec03
4 changed files with 68 additions and 39 deletions
|
@ -80,7 +80,7 @@ def load_boards():
|
|||
return ''
|
||||
|
||||
#
|
||||
# Extract the current configuration files in the form of a structured schema.
|
||||
# Extract the specified configuration files in the form of a structured schema.
|
||||
# Contains the full schema for the configuration files, not just the enabled options,
|
||||
# Contains the current values of the options, not just data structure, so "schema" is a slight misnomer.
|
||||
#
|
||||
|
@ -99,9 +99,9 @@ def load_boards():
|
|||
# - requires = The conditions that must be met for the define to be enabled
|
||||
# - comment = The comment for the define, if it has one
|
||||
# - units = The units for the define, if it has one
|
||||
# - options = The options for the define, if it has one
|
||||
# - options = The options for the define, if it has any
|
||||
#
|
||||
def extract():
|
||||
def extract_files(filekey):
|
||||
# Load board names from boards.h
|
||||
boards = load_boards()
|
||||
|
||||
|
@ -114,10 +114,8 @@ def extract():
|
|||
GET_SENSORS = 4 # Gathering temperature sensor options
|
||||
ERROR = 9 # Syntax error
|
||||
|
||||
# List of files to process, with shorthand
|
||||
filekey = { 'Configuration.h':'basic', 'Configuration_adv.h':'advanced' }
|
||||
# A JSON object to store the data
|
||||
sch_out = { 'basic':{}, 'advanced':{} }
|
||||
sch_out = { key:{} for key in filekey.values() }
|
||||
# Regex for #define NAME [VALUE] [COMMENT] with sanitized line
|
||||
defgrep = re.compile(r'^(//)?\s*(#define)\s+([A-Za-z0-9_]+)\s*(.*?)\s*(//.+)?$')
|
||||
# Pattern to match a float value
|
||||
|
@ -180,6 +178,12 @@ def extract():
|
|||
cfield = 'notes' if 'comment' in last_added_ref else 'comment'
|
||||
last_added_ref[cfield] = cline
|
||||
|
||||
#
|
||||
# Add the given comment line to the comment buffer, unless:
|
||||
# - The line starts with ':' and JSON values to assign to 'opt'.
|
||||
# - The line starts with '@section' so a new section needs to be returned.
|
||||
# - The line starts with '======' so just skip it.
|
||||
#
|
||||
def use_comment(c, opt, sec, bufref):
|
||||
if c.startswith(':'): # If the comment starts with : then it has magic JSON
|
||||
d = c[1:].strip() # Strip the leading :
|
||||
|
@ -199,7 +203,7 @@ def extract():
|
|||
# The comment will be applied to the next #define.
|
||||
if state == Parse.SLASH_COMMENT:
|
||||
if not defmatch and the_line.startswith('//'):
|
||||
use_comment(the_line[2:].strip(), options_json, section, comment_buff)
|
||||
options_json, section = use_comment(the_line[2:].strip(), options_json, section, comment_buff)
|
||||
continue
|
||||
else:
|
||||
state = Parse.NORMAL
|
||||
|
@ -219,7 +223,7 @@ def extract():
|
|||
|
||||
state = Parse.NORMAL
|
||||
|
||||
# Strip the leading '*' from block comments
|
||||
# Strip the leading '* ' from block comments
|
||||
cline = re.sub(r'^\* ?', '', cline)
|
||||
|
||||
# Collect temperature sensors
|
||||
|
@ -412,6 +416,13 @@ def extract():
|
|||
|
||||
return sch_out
|
||||
|
||||
#
|
||||
# Extract the current configuration files in the form of a structured schema.
|
||||
#
|
||||
def extract():
|
||||
# List of files to process, with shorthand
|
||||
return extract_files({ 'Configuration.h':'basic', 'Configuration_adv.h':'advanced' })
|
||||
|
||||
def dump_json(schema:dict, jpath:Path):
|
||||
with jpath.open('w') as jfile:
|
||||
json.dump(schema, jfile, ensure_ascii=False, indent=2)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue