diff options
author | Joel Challis <git@zvecr.com> | 2022-10-19 17:43:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-19 17:43:25 +0100 |
commit | aa8e0a3e7aa9268136fea31d5fd5832e91c0ccc4 (patch) | |
tree | 43849250d4e1893f94a8062f9868e2bea5b0804f /lib/python/qmk/cli/generate/rules_mk.py | |
parent | 18dc851e37a203b32db0261c365dd300488e1c71 (diff) |
Build correctly when out of tree (#18775)
Diffstat (limited to 'lib/python/qmk/cli/generate/rules_mk.py')
-rwxr-xr-x | lib/python/qmk/cli/generate/rules_mk.py | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/lib/python/qmk/cli/generate/rules_mk.py b/lib/python/qmk/cli/generate/rules_mk.py index 9623d00fb5..361d3c758a 100755 --- a/lib/python/qmk/cli/generate/rules_mk.py +++ b/lib/python/qmk/cli/generate/rules_mk.py @@ -1,15 +1,16 @@ """Used by the make system to generate a rules.mk """ from pathlib import Path - from dotty_dict import dotty + +from argcomplete.completers import FilesCompleter from milc import cli -from qmk.info import info_json, keymap_json_config +from qmk.info import info_json from qmk.json_schema import json_load from qmk.keyboard import keyboard_completer, keyboard_folder -from qmk.commands import dump_lines -from qmk.path import normpath +from qmk.commands import dump_lines, parse_configurator_json +from qmk.path import normpath, FileType from qmk.constants import GPL2_HEADER_SH_LIKE, GENERATED_HEADER_SH_LIKE @@ -39,20 +40,25 @@ def process_mapping_rule(kb_info_json, rules_key, info_dict): return f'{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.') @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', 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.argument('-kb', '--keyboard', arg_only=True, type=keyboard_folder, completer=keyboard_completer, help='Keyboard 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. """ # Determine our keyboard/keymap - if cli.args.keymap: - kb_info_json = dotty(keymap_json_config(cli.args.keyboard, cli.args.keymap)) - else: + if cli.args.filename: + user_keymap = parse_configurator_json(cli.args.filename) + kb_info_json = user_keymap.get('config', {}) + elif cli.args.keyboard: kb_info_json = dotty(info_json(cli.args.keyboard)) + else: + cli.log.error('You must supply a configurator export or `--keyboard`.') + cli.subcommands['generate-rules-mk'].print_help() + return False info_rules_map = json_load(Path('data/mappings/info_rules.json')) rules_mk_lines = [GPL2_HEADER_SH_LIKE, GENERATED_HEADER_SH_LIKE] |