Skip to content

Commit

Permalink
Generate keymap.json config options more forcefully (qmk#21960)
Browse files Browse the repository at this point in the history
  • Loading branch information
zvecr authored and Lorenzo Castoldi committed Dec 27, 2023
1 parent cfffee0 commit ed38588
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
5 changes: 5 additions & 0 deletions lib/python/qmk/cli/generate/config_h.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@


def generate_define(define, value=None):
is_keymap = cli.args.filename
value = f' {value}' if value is not None else ''
if is_keymap:
return f"""
#undef {define}
#define {define}{value}"""
return f"""
#ifndef {define}
# define {define}{value}
Expand Down
26 changes: 16 additions & 10 deletions lib/python/qmk/cli/generate/rules_mk.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
from qmk.constants import GPL2_HEADER_SH_LIKE, GENERATED_HEADER_SH_LIKE


def generate_rule(rules_key, rules_value):
is_keymap = cli.args.filename
rule_assignment_operator = '=' if is_keymap else '?='
return f'{rules_key} {rule_assignment_operator} {rules_value}'


def process_mapping_rule(kb_info_json, rules_key, info_dict):
"""Return the rules.mk line(s) for a mapping rule.
"""
Expand All @@ -29,15 +35,15 @@ def process_mapping_rule(kb_info_json, rules_key, info_dict):
return None

if key_type in ['array', 'list']:
return f'{rules_key} ?= {" ".join(rules_value)}'
return generate_rule(rules_key, " ".join(rules_value))
elif key_type == 'bool':
return f'{rules_key} ?= {"yes" if rules_value else "no"}'
return generate_rule(rules_key, "yes" if rules_value else "no")
elif key_type == 'mapping':
return '\n'.join([f'{key} ?= {value}' for key, value in rules_value.items()])
return '\n'.join([generate_rule(key, value) for key, value in rules_value.items()])
elif key_type == 'str':
return f'{rules_key} ?= "{rules_value}"'
return generate_rule(rules_key, f'"{rules_value}"')

return f'{rules_key} ?= {rules_value}'
return generate_rule(rules_key, rules_value)


@cli.argument('filename', nargs='?', arg_only=True, type=FileType('r'), completer=FilesCompleter('.json'), help='A configurator export JSON to be compiled and flashed or a pre-compiled binary firmware file (bin/hex) to be flashed.')
Expand Down Expand Up @@ -77,21 +83,21 @@ def generate_rules_mk(cli):
for feature, enabled in kb_info_json['features'].items():
feature = feature.upper()
enabled = 'yes' if enabled else 'no'
rules_mk_lines.append(f'{feature}_ENABLE ?= {enabled}')
rules_mk_lines.append(generate_rule(f'{feature}_ENABLE', enabled))

# Set SPLIT_TRANSPORT, if needed
if kb_info_json.get('split', {}).get('transport', {}).get('protocol') == 'custom':
rules_mk_lines.append('SPLIT_TRANSPORT ?= custom')
rules_mk_lines.append(generate_rule('SPLIT_TRANSPORT', 'custom'))

# Set CUSTOM_MATRIX, if needed
if kb_info_json.get('matrix_pins', {}).get('custom'):
if kb_info_json.get('matrix_pins', {}).get('custom_lite'):
rules_mk_lines.append('CUSTOM_MATRIX ?= lite')
rules_mk_lines.append(generate_rule('CUSTOM_MATRIX', 'lite'))
else:
rules_mk_lines.append('CUSTOM_MATRIX ?= yes')
rules_mk_lines.append(generate_rule('CUSTOM_MATRIX', 'yes'))

if converter:
rules_mk_lines.append(f'CONVERT_TO ?= {converter}')
rules_mk_lines.append(generate_rule('CONVERT_TO', converter))

# Show the results
dump_lines(cli.args.output, rules_mk_lines)
Expand Down

0 comments on commit ed38588

Please sign in to comment.