Create a system to map between info.json and config.h/rules.mk (#11548)
* generate rules.mk from a json mapping * generate rules.mk from a json mapping * support for config.h from json maps * improve the mapping system * document the mapping system * move data/maps to data/mappings * fix flake8 errors * fixup LED_MATRIX_DRIVER * remove product and description from the vision_division keymap level * reduce the complexity of generate-rules-mk * add tests for the generate commands * fix qmk doctor when submodules are not clean
This commit is contained in:
parent
6cada2a35f
commit
ef6329af7c
13 changed files with 338 additions and 460 deletions
|
@ -1,16 +1,37 @@
|
|||
"""Used by the make system to generate a rules.mk
|
||||
"""
|
||||
from pathlib import Path
|
||||
|
||||
from dotty_dict import dotty
|
||||
from milc import cli
|
||||
|
||||
from qmk.decorators import automagic_keyboard, automagic_keymap
|
||||
from qmk.info import info_json
|
||||
from qmk.info import _json_load, info_json
|
||||
from qmk.path import is_keyboard, normpath
|
||||
|
||||
info_to_rules = {
|
||||
'board': 'BOARD',
|
||||
'bootloader': 'BOOTLOADER',
|
||||
'processor': 'MCU',
|
||||
}
|
||||
|
||||
def process_mapping_rule(kb_info_json, rules_key, info_dict):
|
||||
"""Return the rules.mk line(s) for a mapping rule.
|
||||
"""
|
||||
if not info_dict.get('to_c', True):
|
||||
return None
|
||||
|
||||
info_key = info_dict['info_key']
|
||||
key_type = info_dict.get('value_type', 'str')
|
||||
|
||||
try:
|
||||
rules_value = kb_info_json[info_key]
|
||||
except KeyError:
|
||||
return None
|
||||
|
||||
if key_type == 'array':
|
||||
return f'{rules_key} ?= {" ".join(rules_value)}'
|
||||
elif key_type == 'bool':
|
||||
return f'{rules_key} ?= {"on" if rules_value else "off"}'
|
||||
elif key_type == 'mapping':
|
||||
return '\n'.join([f'{key} ?= {value}' for key, value in rules_value.items()])
|
||||
|
||||
return f'{rules_key} ?= {rules_value}'
|
||||
|
||||
|
||||
@cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to')
|
||||
|
@ -22,7 +43,6 @@ info_to_rules = {
|
|||
def generate_rules_mk(cli):
|
||||
"""Generates a rules.mk file from info.json.
|
||||
"""
|
||||
# Determine our keyboard(s)
|
||||
if not cli.config.generate_rules_mk.keyboard:
|
||||
cli.log.error('Missing paramater: --keyboard')
|
||||
cli.subcommands['info'].print_help()
|
||||
|
@ -32,16 +52,18 @@ def generate_rules_mk(cli):
|
|||
cli.log.error('Invalid keyboard: "%s"', cli.config.generate_rules_mk.keyboard)
|
||||
return False
|
||||
|
||||
# Build the info.json file
|
||||
kb_info_json = info_json(cli.config.generate_rules_mk.keyboard)
|
||||
kb_info_json = dotty(info_json(cli.config.generate_rules_mk.keyboard))
|
||||
info_rules_map = _json_load(Path('data/mappings/info_rules.json'))
|
||||
rules_mk_lines = ['# This file was generated by `qmk generate-rules-mk`. Do not edit or copy.', '']
|
||||
|
||||
# Bring in settings
|
||||
for info_key, rule_key in info_to_rules.items():
|
||||
if info_key in kb_info_json:
|
||||
rules_mk_lines.append(f'{rule_key} ?= {kb_info_json[info_key]}')
|
||||
# Iterate through the info_rules map to generate basic rules
|
||||
for rules_key, info_dict in info_rules_map.items():
|
||||
new_entry = process_mapping_rule(kb_info_json, rules_key, info_dict)
|
||||
|
||||
# Find features that should be enabled
|
||||
if new_entry:
|
||||
rules_mk_lines.append(new_entry)
|
||||
|
||||
# Iterate through features to enable/disable them
|
||||
if 'features' in kb_info_json:
|
||||
for feature, enabled in kb_info_json['features'].items():
|
||||
if feature == 'bootmagic_lite' and enabled:
|
||||
|
@ -51,15 +73,6 @@ def generate_rules_mk(cli):
|
|||
enabled = 'yes' if enabled else 'no'
|
||||
rules_mk_lines.append(f'{feature}_ENABLE ?= {enabled}')
|
||||
|
||||
# Set the LED driver
|
||||
if 'led_matrix' in kb_info_json and 'driver' in kb_info_json['led_matrix']:
|
||||
driver = kb_info_json['led_matrix']['driver']
|
||||
rules_mk_lines.append(f'LED_MATRIX_DRIVER ?= {driver}')
|
||||
|
||||
# Add community layouts
|
||||
if 'community_layouts' in kb_info_json:
|
||||
rules_mk_lines.append(f'LAYOUTS ?= {" ".join(kb_info_json["community_layouts"])}')
|
||||
|
||||
# Show the results
|
||||
rules_mk = '\n'.join(rules_mk_lines) + '\n'
|
||||
|
||||
|
@ -72,7 +85,7 @@ def generate_rules_mk(cli):
|
|||
if cli.args.quiet:
|
||||
print(cli.args.output)
|
||||
else:
|
||||
cli.log.info('Wrote info_config.h to %s.', cli.args.output)
|
||||
cli.log.info('Wrote rules.mk to %s.', cli.args.output)
|
||||
|
||||
else:
|
||||
print(rules_mk)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue