forked from mirrors/qmk_firmware
add support for in-tree keymap.json (wip)
This commit is contained in:
parent
3f9e745b71
commit
0d9d1d0414
9 changed files with 35 additions and 24 deletions
|
@ -15,3 +15,5 @@ else ifneq ("$(wildcard $(MAIN_KEYMAP_PATH_1)/keymap.json)","")
|
|||
KEYMAP_JSON := $(MAIN_KEYMAP_PATH_1)/keymap.json
|
||||
KEYMAP_PATH := $(MAIN_KEYMAP_PATH_1)
|
||||
endif
|
||||
|
||||
:$(shell cp $(KEYMAP_JSON) $(KEYMAP_OUTPUT)/keymap.json)
|
||||
|
|
|
@ -109,7 +109,7 @@ MAIN_KEYMAP_PATH_4 := $(KEYBOARD_PATH_4)/keymaps/$(KEYMAP)
|
|||
MAIN_KEYMAP_PATH_5 := $(KEYBOARD_PATH_5)/keymaps/$(KEYMAP)
|
||||
|
||||
# Pull in rules from info.json
|
||||
INFO_RULES_MK = $(shell $(QMK_BIN) generate-rules-mk --quiet --escape --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/info_rules.mk)
|
||||
INFO_RULES_MK = $(shell $(QMK_BIN) generate-rules-mk --quiet --escape --keyboard $(KEYBOARD) --keymap $(KEYMAP) --output $(KEYBOARD_OUTPUT)/src/info_rules.mk)
|
||||
include $(INFO_RULES_MK)
|
||||
|
||||
# Check for keymap.json first, so we can regenerate keymap.c
|
||||
|
@ -328,13 +328,13 @@ endif
|
|||
CONFIG_H += $(KEYBOARD_OUTPUT)/src/info_config.h $(KEYBOARD_OUTPUT)/src/layouts.h
|
||||
|
||||
$(KEYBOARD_OUTPUT)/src/info_config.h: $(INFO_JSON_FILES)
|
||||
$(QMK_BIN) generate-config-h --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/info_config.h
|
||||
$(QMK_BIN) generate-config-h --quiet --keyboard $(KEYBOARD) --keymap $(KEYMAP) --output $(KEYBOARD_OUTPUT)/src/info_config.h
|
||||
|
||||
$(KEYBOARD_OUTPUT)/src/default_keyboard.h: $(INFO_JSON_FILES)
|
||||
$(QMK_BIN) generate-keyboard-h --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/default_keyboard.h
|
||||
$(QMK_BIN) generate-keyboard-h --quiet --keyboard $(KEYBOARD) --keymap $(KEYMAP) --output $(KEYBOARD_OUTPUT)/src/default_keyboard.h
|
||||
|
||||
$(KEYBOARD_OUTPUT)/src/layouts.h: $(INFO_JSON_FILES)
|
||||
$(QMK_BIN) generate-layouts --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/layouts.h
|
||||
$(QMK_BIN) generate-layouts --quiet --keyboard $(KEYBOARD) --keymap $(KEYMAP) --output $(KEYBOARD_OUTPUT)/src/layouts.h
|
||||
|
||||
generated-files: $(KEYBOARD_OUTPUT)/src/info_config.h $(KEYBOARD_OUTPUT)/src/default_keyboard.h $(KEYBOARD_OUTPUT)/src/layouts.h
|
||||
|
||||
|
|
|
@ -157,11 +157,12 @@ def generate_split_config(kb_info_json, config_h_lines):
|
|||
@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('-kb', '--keyboard', arg_only=True, type=keyboard_folder, completer=keyboard_completer, required=True, help='Keyboard to generate config.h for.')
|
||||
@cli.argument('-km', '--keymap', arg_only=True, help='Keymap to get overrides from.')
|
||||
@cli.subcommand('Used by the make system to generate info_config.h from info.json', hidden=True)
|
||||
def generate_config_h(cli):
|
||||
"""Generates the info_config.h file.
|
||||
"""
|
||||
kb_info_json = dotty(info_json(cli.args.keyboard, overrides=get_keyboard_overrides(cli.args.keyboard)))
|
||||
kb_info_json = dotty(info_json(cli.args.keyboard, overrides=get_keyboard_overrides(cli.args.keyboard, cli.args.keymap)))
|
||||
|
||||
# Build the info_config.h file.
|
||||
config_h_lines = ['/* This file was generated by `qmk generate-config-h`. Do not edit or copy.' ' */', '', '#pragma once']
|
||||
|
|
|
@ -12,6 +12,7 @@ from qmk.keyboard import keyboard_completer
|
|||
@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('-kb', '--keyboard', completer=keyboard_completer, help='Keyboard to generate LUFA Keyboard.h for.')
|
||||
@cli.argument('-km', '--keymap', arg_only=True, help='Keyboard to generate LUFA Keyboard.h for.')
|
||||
@cli.subcommand('Used by the make system to generate LUFA Keyboard.h from info.json', hidden=True)
|
||||
@automagic_keyboard
|
||||
def generate_dfu_header(cli):
|
||||
|
@ -28,7 +29,7 @@ def generate_dfu_header(cli):
|
|||
return False
|
||||
|
||||
# Build the Keyboard.h file.
|
||||
kb_info_json = dotty(info_json(cli.config.generate_dfu_header.keyboard, overrides=get_keyboard_overrides(cli.args.keyboard)))
|
||||
kb_info_json = dotty(info_json(cli.config.generate_dfu_header.keyboard, overrides=get_keyboard_overrides(cli.args.keyboard, cli.args.keymap)))
|
||||
|
||||
keyboard_h_lines = ['/* This file was generated by `qmk generate-dfu-header`. Do not edit or copy.' ' */', '', '#pragma once']
|
||||
keyboard_h_lines.append(f'#define MANUFACTURER {kb_info_json["manufacturer"]}')
|
||||
|
|
|
@ -7,11 +7,11 @@ from qmk.keyboard import keyboard_completer, keyboard_folder
|
|||
from qmk.path import normpath
|
||||
|
||||
|
||||
def would_populate_layout_h(keyboard):
|
||||
def would_populate_layout_h(keyboard, keymap):
|
||||
"""Detect if a given keyboard is doing data driven layouts
|
||||
"""
|
||||
# Build the info.json file
|
||||
kb_info_json = info_json(keyboard, overrides=get_keyboard_overrides(keyboard))
|
||||
kb_info_json = info_json(keyboard, overrides=get_keyboard_overrides(keyboard, keymap))
|
||||
|
||||
for layout_name in kb_info_json['layouts']:
|
||||
if kb_info_json['layouts'][layout_name]['c_macro']:
|
||||
|
@ -29,11 +29,12 @@ def would_populate_layout_h(keyboard):
|
|||
@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('-kb', '--keyboard', arg_only=True, type=keyboard_folder, completer=keyboard_completer, required=True, help='Keyboard to generate keyboard.h for.')
|
||||
@cli.argument('-km', '--keymap', arg_only=True, help='Keymap name to check for overrides.')
|
||||
@cli.subcommand('Used by the make system to generate keyboard.h from info.json', hidden=True)
|
||||
def generate_keyboard_h(cli):
|
||||
"""Generates the keyboard.h file.
|
||||
"""
|
||||
has_layout_h = would_populate_layout_h(cli.args.keyboard)
|
||||
has_layout_h = would_populate_layout_h(cli.args.keyboard, cli.args.keymap)
|
||||
|
||||
# Build the layouts.h file.
|
||||
keyboard_h_lines = ['/* This file was generated by `qmk generate-keyboard-h`. Do not edit or copy.' ' */', '', '#pragma once', '#include "quantum.h"']
|
||||
|
|
|
@ -18,6 +18,7 @@ usb_properties = {
|
|||
@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('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='Keyboard to generate config.h for.')
|
||||
@cli.argument('-km', '--keymap', arg_only=True, help='Keymap to get overrides from.')
|
||||
@cli.subcommand('Used by the make system to generate layouts.h from info.json', hidden=True)
|
||||
@automagic_keyboard
|
||||
@automagic_keymap
|
||||
|
@ -35,7 +36,7 @@ def generate_layouts(cli):
|
|||
return False
|
||||
|
||||
# Build the info.json file
|
||||
kb_info_json = info_json(cli.config.generate_layouts.keyboard, overrides=get_keyboard_overrides(cli.config.generate_layouts.keyboard))
|
||||
kb_info_json = info_json(cli.config.generate_layouts.keyboard, overrides=get_keyboard_overrides(cli.config.generate_layouts.keyboard, cli.args.keymap))
|
||||
|
||||
# Build the layouts.h file.
|
||||
layouts_h_lines = ['/* This file was generated by `qmk generate-layouts`. Do not edit or copy.' ' */', '', '#pragma once']
|
||||
|
|
|
@ -39,12 +39,13 @@ def process_mapping_rule(kb_info_json, rules_key, info_dict):
|
|||
@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 name to check overrides 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.
|
||||
"""
|
||||
info_rules_map = json_load(Path('data/mappings/info_rules.json'))
|
||||
kb_info_json = dotty(info_json(cli.args.keyboard, overrides=get_keyboard_overrides(cli.args.keyboard)))
|
||||
kb_info_json = dotty(info_json(cli.args.keyboard, overrides=get_keyboard_overrides(cli.args.keyboard, cli.args.keymap)))
|
||||
rules_mk_lines = ['# This file was generated by `qmk generate-rules-mk`. Do not edit or copy.', '']
|
||||
|
||||
# Iterate through the info_rules map to generate basic rules
|
||||
|
|
|
@ -194,14 +194,11 @@ def compile_configurator_json(user_keymap, bootloader=None, parallel=1, **env_va
|
|||
version_h = Path('quantum/version.h')
|
||||
version_h.write_text(create_version_h())
|
||||
|
||||
# Write the overrides file, if needed
|
||||
override_file = keyboard_output / 'keyboard_overrides.json'
|
||||
# Write the keymap json out
|
||||
json_output = keymap_output / 'keymap.json'
|
||||
|
||||
if 'keyboard_overrides' in user_keymap:
|
||||
keyboard_output.mkdir(exist_ok=True, parents=True)
|
||||
json.dump(user_keymap['keyboard_overrides'], override_file.open('w', encoding='utf-8'))
|
||||
elif override_file.exists():
|
||||
override_file.unlink()
|
||||
keymap_output.mkdir(exist_ok=True, parents=True)
|
||||
json.dump(user_keymap, json_output.open('w', encoding='utf-8'))
|
||||
|
||||
# Return a command that can be run to make the keymap and flash if given
|
||||
verbose = 'true' if cli.config.general.verbose else 'false'
|
||||
|
|
|
@ -106,15 +106,22 @@ def info_json(keyboard, *, overrides=None):
|
|||
return info_data
|
||||
|
||||
|
||||
def get_keyboard_overrides(keyboard):
|
||||
def get_keyboard_overrides(keyboard, keymap=None):
|
||||
"""Checks for keyboard_overrides.json in the keyboard build directory and returns them if it exists.
|
||||
"""
|
||||
keyboard_filesafe = keyboard.replace('/', '_')
|
||||
keyboard_output = Path(f'{KEYBOARD_OUTPUT_PREFIX}{keyboard_filesafe}')
|
||||
keyboard_overrides_file = keyboard_output / 'keyboard_overrides.json'
|
||||
if not keymap:
|
||||
return None
|
||||
|
||||
if keyboard_overrides_file.exists():
|
||||
return json.load(keyboard_overrides_file.open('r', encoding='utf-8'))
|
||||
keyboard_filesafe = keyboard.replace('/', '_')
|
||||
keymap_filesafe = f'{keyboard_filesafe}_{keymap}' if keymap else keyboard_filesafe
|
||||
keymap_output = Path(f'{KEYBOARD_OUTPUT_PREFIX}{keymap_filesafe}')
|
||||
keymap_file = keymap_output / 'keymap.json'
|
||||
|
||||
if keymap_file.exists():
|
||||
keymap_json = json.load(keymap_file.open('r', encoding='utf-8'))
|
||||
|
||||
if 'keyboard_overrides' in keymap_json:
|
||||
return keymap_json['keyboard_overrides']
|
||||
|
||||
|
||||
def _extract_features(info_data, rules):
|
||||
|
|
Loading…
Reference in a new issue