summaryrefslogtreecommitdiff
path: root/lib/python/qmk/cli/generate/rules_mk.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/qmk/cli/generate/rules_mk.py')
-rwxr-xr-xlib/python/qmk/cli/generate/rules_mk.py41
1 files changed, 25 insertions, 16 deletions
diff --git a/lib/python/qmk/cli/generate/rules_mk.py b/lib/python/qmk/cli/generate/rules_mk.py
index 41c94e16b5..cdf17dfbcb 100755
--- a/lib/python/qmk/cli/generate/rules_mk.py
+++ b/lib/python/qmk/cli/generate/rules_mk.py
@@ -5,11 +5,11 @@ 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.json_schema import json_load
+from qmk.json_schema import json_load, validate
from qmk.keyboard import keyboard_completer, keyboard_folder
-from qmk.path import is_keyboard, normpath
+from qmk.keymap import locate_keymap
+from qmk.path import normpath
def process_mapping_rule(kb_info_json, rules_key, info_dict):
@@ -39,23 +39,21 @@ def process_mapping_rule(kb_info_json, rules_key, info_dict):
@cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to')
@cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages")
@cli.argument('-e', '--escape', arg_only=True, action='store_true', help="Escape spaces in quiet mode")
-@cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='Keyboard to generate config.h for.')
-@cli.subcommand('Used by the make system to generate info_config.h from info.json', hidden=True)
-@automagic_keyboard
-@automagic_keymap
+@cli.argument('-kb', '--keyboard', arg_only=True, type=keyboard_folder, completer=keyboard_completer, required=True, help='Keyboard to generate rules.mk for.')
+@cli.argument('-km', '--keymap', arg_only=True, help='Keymap to generate rules.mk for.')
+@cli.subcommand('Used by the make system to generate rules.mk from info.json', hidden=True)
def generate_rules_mk(cli):
"""Generates a rules.mk file from info.json.
"""
- if not cli.config.generate_rules_mk.keyboard:
- cli.log.error('Missing parameter: --keyboard')
- cli.subcommands['info'].print_help()
- return False
-
- if not is_keyboard(cli.config.generate_rules_mk.keyboard):
- cli.log.error('Invalid keyboard: "%s"', cli.config.generate_rules_mk.keyboard)
- return False
+ # Determine our keyboard/keymap
+ if cli.args.keymap:
+ km = locate_keymap(cli.args.keyboard, cli.args.keymap)
+ km_json = json_load(km)
+ validate(km_json, 'qmk.keymap.v1')
+ kb_info_json = dotty(km_json.get('config', {}))
+ else:
+ kb_info_json = dotty(info_json(cli.args.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.', '']
@@ -76,6 +74,17 @@ def generate_rules_mk(cli):
enabled = 'yes' if enabled else 'no'
rules_mk_lines.append(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')
+
+ # 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')
+ else:
+ rules_mk_lines.append('CUSTOM_MATRIX ?= yes')
+
# Show the results
rules_mk = '\n'.join(rules_mk_lines) + '\n'