diff options
| author | Joel Challis <git@zvecr.com> | 2021-08-18 21:52:41 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-18 21:52:41 +0100 |
| commit | 2e734fb6b9e3480854b794218d381559aab431b7 (patch) | |
| tree | 2bec5639b3dd200c640cd8c76b8c2b614f67e34b /lib | |
| parent | 10fab4ec077354f41d19f01798a49e5864a189cd (diff) | |
| download | qmk_firmware-2e734fb6b9e3480854b794218d381559aab431b7.tar.gz qmk_firmware-2e734fb6b9e3480854b794218d381559aab431b7.zip | |
Add config.h and rules.mk support for data driven keymaps (#12859)
* Add config.h and rules.mk support for data driven keymaps
* tidy up after rebase
* Rename key as it can contain more than just keyboard overrides
* tidy up after rebase
* Add validation
Diffstat (limited to 'lib')
| -rwxr-xr-x | lib/python/qmk/cli/generate/config_h.py | 29 | ||||
| -rwxr-xr-x | lib/python/qmk/cli/generate/keyboard_h.py | 7 | ||||
| -rwxr-xr-x | lib/python/qmk/cli/generate/rules_mk.py | 30 |
3 files changed, 29 insertions, 37 deletions
diff --git a/lib/python/qmk/cli/generate/config_h.py b/lib/python/qmk/cli/generate/config_h.py index c0c148f1c..ca7e14fe6 100755 --- a/lib/python/qmk/cli/generate/config_h.py +++ b/lib/python/qmk/cli/generate/config_h.py | |||
| @@ -5,11 +5,11 @@ from pathlib import Path | |||
| 5 | from dotty_dict import dotty | 5 | from dotty_dict import dotty |
| 6 | from milc import cli | 6 | from milc import cli |
| 7 | 7 | ||
| 8 | from qmk.decorators import automagic_keyboard, automagic_keymap | ||
| 9 | from qmk.info import info_json | 8 | from qmk.info import info_json |
| 10 | from qmk.json_schema import json_load | 9 | from qmk.json_schema import json_load, validate |
| 11 | from qmk.keyboard import keyboard_completer, keyboard_folder | 10 | from qmk.keyboard import keyboard_completer, keyboard_folder |
| 12 | from qmk.path import is_keyboard, normpath | 11 | from qmk.keymap import locate_keymap |
| 12 | from qmk.path import normpath | ||
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | def direct_pins(direct_pins, postfix): | 15 | def direct_pins(direct_pins, postfix): |
| @@ -157,25 +157,22 @@ def generate_split_config(kb_info_json, config_h_lines): | |||
| 157 | 157 | ||
| 158 | @cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to') | 158 | @cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to') |
| 159 | @cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages") | 159 | @cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages") |
| 160 | @cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='Keyboard to generate config.h for.') | 160 | @cli.argument('-kb', '--keyboard', arg_only=True, type=keyboard_folder, completer=keyboard_completer, required=True, help='Keyboard to generate config.h for.') |
| 161 | @cli.argument('-km', '--keymap', arg_only=True, help='Keymap to generate config.h for.') | ||
| 161 | @cli.subcommand('Used by the make system to generate info_config.h from info.json', hidden=True) | 162 | @cli.subcommand('Used by the make system to generate info_config.h from info.json', hidden=True) |
| 162 | @automagic_keyboard | ||
| 163 | @automagic_keymap | ||
| 164 | def generate_config_h(cli): | 163 | def generate_config_h(cli): |
| 165 | """Generates the info_config.h file. | 164 | """Generates the info_config.h file. |
| 166 | """ | 165 | """ |
| 167 | # Determine our keyboard(s) | 166 | # Determine our keyboard/keymap |
| 168 | if not cli.config.generate_config_h.keyboard: | 167 | if cli.args.keymap: |
| 169 | cli.log.error('Missing parameter: --keyboard') | 168 | km = locate_keymap(cli.args.keyboard, cli.args.keymap) |
| 170 | cli.subcommands['info'].print_help() | 169 | km_json = json_load(km) |
| 171 | return False | 170 | validate(km_json, 'qmk.keymap.v1') |
| 172 | 171 | kb_info_json = dotty(km_json.get('config', {})) | |
| 173 | if not is_keyboard(cli.config.generate_config_h.keyboard): | 172 | else: |
| 174 | cli.log.error('Invalid keyboard: "%s"', cli.config.generate_config_h.keyboard) | 173 | kb_info_json = dotty(info_json(cli.args.keyboard)) |
| 175 | return False | ||
| 176 | 174 | ||
| 177 | # Build the info_config.h file. | 175 | # Build the info_config.h file. |
| 178 | kb_info_json = dotty(info_json(cli.config.generate_config_h.keyboard)) | ||
| 179 | config_h_lines = ['/* This file was generated by `qmk generate-config-h`. Do not edit or copy.' ' */', '', '#pragma once'] | 176 | config_h_lines = ['/* This file was generated by `qmk generate-config-h`. Do not edit or copy.' ' */', '', '#pragma once'] |
| 180 | 177 | ||
| 181 | generate_config_items(kb_info_json, config_h_lines) | 178 | generate_config_items(kb_info_json, config_h_lines) |
diff --git a/lib/python/qmk/cli/generate/keyboard_h.py b/lib/python/qmk/cli/generate/keyboard_h.py index 22500dbc9..c9d7f549b 100755 --- a/lib/python/qmk/cli/generate/keyboard_h.py +++ b/lib/python/qmk/cli/generate/keyboard_h.py | |||
| @@ -2,7 +2,6 @@ | |||
| 2 | """ | 2 | """ |
| 3 | from milc import cli | 3 | from milc import cli |
| 4 | 4 | ||
| 5 | from qmk.decorators import automagic_keyboard, automagic_keymap | ||
| 6 | from qmk.info import info_json | 5 | from qmk.info import info_json |
| 7 | from qmk.keyboard import keyboard_completer, keyboard_folder | 6 | from qmk.keyboard import keyboard_completer, keyboard_folder |
| 8 | from qmk.path import normpath | 7 | from qmk.path import normpath |
| @@ -29,14 +28,12 @@ def would_populate_layout_h(keyboard): | |||
| 29 | 28 | ||
| 30 | @cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to') | 29 | @cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to') |
| 31 | @cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages") | 30 | @cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages") |
| 32 | @cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, required=True, help='Keyboard to generate keyboard.h for.') | 31 | @cli.argument('-kb', '--keyboard', arg_only=True, type=keyboard_folder, completer=keyboard_completer, required=True, help='Keyboard to generate keyboard.h for.') |
| 33 | @cli.subcommand('Used by the make system to generate keyboard.h from info.json', hidden=True) | 32 | @cli.subcommand('Used by the make system to generate keyboard.h from info.json', hidden=True) |
| 34 | @automagic_keyboard | ||
| 35 | @automagic_keymap | ||
| 36 | def generate_keyboard_h(cli): | 33 | def generate_keyboard_h(cli): |
| 37 | """Generates the keyboard.h file. | 34 | """Generates the keyboard.h file. |
| 38 | """ | 35 | """ |
| 39 | has_layout_h = would_populate_layout_h(cli.config.generate_keyboard_h.keyboard) | 36 | has_layout_h = would_populate_layout_h(cli.args.keyboard) |
| 40 | 37 | ||
| 41 | # Build the layouts.h file. | 38 | # Build the layouts.h file. |
| 42 | keyboard_h_lines = ['/* This file was generated by `qmk generate-keyboard-h`. Do not edit or copy.' ' */', '', '#pragma once', '#include "quantum.h"'] | 39 | keyboard_h_lines = ['/* This file was generated by `qmk generate-keyboard-h`. Do not edit or copy.' ' */', '', '#pragma once', '#include "quantum.h"'] |
diff --git a/lib/python/qmk/cli/generate/rules_mk.py b/lib/python/qmk/cli/generate/rules_mk.py index 2712b81cb..cdf17dfbc 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 | |||
| 5 | from dotty_dict import dotty | 5 | from dotty_dict import dotty |
| 6 | from milc import cli | 6 | from milc import cli |
| 7 | 7 | ||
| 8 | from qmk.decorators import automagic_keyboard, automagic_keymap | ||
| 9 | from qmk.info import info_json | 8 | from qmk.info import info_json |
| 10 | from qmk.json_schema import json_load | 9 | from qmk.json_schema import json_load, validate |
| 11 | from qmk.keyboard import keyboard_completer, keyboard_folder | 10 | from qmk.keyboard import keyboard_completer, keyboard_folder |
| 12 | from qmk.path import is_keyboard, normpath | 11 | from qmk.keymap import locate_keymap |
| 12 | from qmk.path import normpath | ||
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | def process_mapping_rule(kb_info_json, rules_key, info_dict): | 15 | 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): | |||
| 39 | @cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to') | 39 | @cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to') |
| 40 | @cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages") | 40 | @cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages") |
| 41 | @cli.argument('-e', '--escape', arg_only=True, action='store_true', help="Escape spaces in quiet mode") | 41 | @cli.argument('-e', '--escape', arg_only=True, action='store_true', help="Escape spaces in quiet mode") |
| 42 | @cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='Keyboard to generate config.h for.') | 42 | @cli.argument('-kb', '--keyboard', arg_only=True, type=keyboard_folder, completer=keyboard_completer, required=True, help='Keyboard to generate rules.mk for.') |
| 43 | @cli.subcommand('Used by the make system to generate info_config.h from info.json', hidden=True) | 43 | @cli.argument('-km', '--keymap', arg_only=True, help='Keymap to generate rules.mk for.') |
| 44 | @automagic_keyboard | 44 | @cli.subcommand('Used by the make system to generate rules.mk from info.json', hidden=True) |
| 45 | @automagic_keymap | ||
| 46 | def generate_rules_mk(cli): | 45 | def generate_rules_mk(cli): |
| 47 | """Generates a rules.mk file from info.json. | 46 | """Generates a rules.mk file from info.json. |
| 48 | """ | 47 | """ |
| 49 | if not cli.config.generate_rules_mk.keyboard: | 48 | # Determine our keyboard/keymap |
| 50 | cli.log.error('Missing parameter: --keyboard') | 49 | if cli.args.keymap: |
| 51 | cli.subcommands['info'].print_help() | 50 | km = locate_keymap(cli.args.keyboard, cli.args.keymap) |
| 52 | return False | 51 | km_json = json_load(km) |
| 53 | 52 | validate(km_json, 'qmk.keymap.v1') | |
| 54 | if not is_keyboard(cli.config.generate_rules_mk.keyboard): | 53 | kb_info_json = dotty(km_json.get('config', {})) |
| 55 | cli.log.error('Invalid keyboard: "%s"', cli.config.generate_rules_mk.keyboard) | 54 | else: |
| 56 | return False | 55 | kb_info_json = dotty(info_json(cli.args.keyboard)) |
| 57 | 56 | ||
| 58 | kb_info_json = dotty(info_json(cli.config.generate_rules_mk.keyboard)) | ||
| 59 | info_rules_map = json_load(Path('data/mappings/info_rules.json')) | 57 | info_rules_map = json_load(Path('data/mappings/info_rules.json')) |
| 60 | rules_mk_lines = ['# This file was generated by `qmk generate-rules-mk`. Do not edit or copy.', ''] | 58 | rules_mk_lines = ['# This file was generated by `qmk generate-rules-mk`. Do not edit or copy.', ''] |
| 61 | 59 | ||
