forked from mirrors/qmk_firmware
Compare commits
3 commits
develop
...
keyboard_o
Author | SHA1 | Date | |
---|---|---|---|
|
4821b3c3a1 | ||
|
0d9d1d0414 | ||
|
3f9e745b71 |
15 changed files with 125 additions and 93 deletions
|
@ -15,3 +15,5 @@ else ifneq ("$(wildcard $(MAIN_KEYMAP_PATH_1)/keymap.json)","")
|
||||||
KEYMAP_JSON := $(MAIN_KEYMAP_PATH_1)/keymap.json
|
KEYMAP_JSON := $(MAIN_KEYMAP_PATH_1)/keymap.json
|
||||||
KEYMAP_PATH := $(MAIN_KEYMAP_PATH_1)
|
KEYMAP_PATH := $(MAIN_KEYMAP_PATH_1)
|
||||||
endif
|
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)
|
MAIN_KEYMAP_PATH_5 := $(KEYBOARD_PATH_5)/keymaps/$(KEYMAP)
|
||||||
|
|
||||||
# Pull in rules from info.json
|
# 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)
|
include $(INFO_RULES_MK)
|
||||||
|
|
||||||
# Check for keymap.json first, so we can regenerate keymap.c
|
# 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
|
CONFIG_H += $(KEYBOARD_OUTPUT)/src/info_config.h $(KEYBOARD_OUTPUT)/src/layouts.h
|
||||||
|
|
||||||
$(KEYBOARD_OUTPUT)/src/info_config.h: $(INFO_JSON_FILES)
|
$(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)
|
$(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)
|
$(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
|
generated-files: $(KEYBOARD_OUTPUT)/src/info_config.h $(KEYBOARD_OUTPUT)/src/default_keyboard.h $(KEYBOARD_OUTPUT)/src/layouts.h
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,9 @@
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"author": {"type": "string"},
|
"author": {"type": "string"},
|
||||||
|
"config": {"$ref": "qmk.keyboard.v1"},
|
||||||
"keyboard": {"$ref": "qmk.definitions.v1#/text_identifier"},
|
"keyboard": {"$ref": "qmk.definitions.v1#/text_identifier"},
|
||||||
|
"keyboard_overrides": {"$ref": "qmk.keyboard.v1"},
|
||||||
"keymap": {"$ref": "qmk.definitions.v1#/text_identifier"},
|
"keymap": {"$ref": "qmk.definitions.v1#/text_identifier"},
|
||||||
"layout": {"$ref": "qmk.definitions.v1#/layout_macro"},
|
"layout": {"$ref": "qmk.definitions.v1#/layout_macro"},
|
||||||
"layers": {
|
"layers": {
|
||||||
|
@ -15,10 +17,6 @@
|
||||||
"items": {"type": "string"}
|
"items": {"type": "string"}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"config": {"$ref": "qmk.keyboard.v1"},
|
"notes": { "type": "string" }
|
||||||
"notes": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "asdf"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"keyboard":"clueboard/2x1800/2019",
|
"keyboard":"clueboard/2x1800/2019",
|
||||||
|
"keyboard_overrides": {"keyboard_name": "keymap override"},
|
||||||
"keymap":"default",
|
"keymap":"default",
|
||||||
"layout":"LAYOUT_all",
|
"layout":"LAYOUT_all",
|
||||||
"layers":[
|
"layers":[
|
||||||
|
|
|
@ -42,7 +42,7 @@ def format_json(cli):
|
||||||
if json_encoder == KeymapJSONEncoder and 'layout' in json_file:
|
if json_encoder == KeymapJSONEncoder and 'layout' in json_file:
|
||||||
# Attempt to format the keycodes.
|
# Attempt to format the keycodes.
|
||||||
layout = json_file['layout']
|
layout = json_file['layout']
|
||||||
info_data = info_json(json_file['keyboard'])
|
info_data = info_json(json_file['keyboard'], overrides=json_file.get('keyboard_overrides'))
|
||||||
|
|
||||||
if layout in info_data.get('layout_aliases', {}):
|
if layout in info_data.get('layout_aliases', {}):
|
||||||
layout = json_file['layout'] = info_data['layout_aliases'][layout]
|
layout = json_file['layout'] = info_data['layout_aliases'][layout]
|
||||||
|
|
|
@ -5,10 +5,9 @@ from pathlib import Path
|
||||||
from dotty_dict import dotty
|
from dotty_dict import dotty
|
||||||
from milc import cli
|
from milc import cli
|
||||||
|
|
||||||
from qmk.info import info_json
|
from qmk.info import info_json, get_keyboard_overrides
|
||||||
from qmk.json_schema import json_load, validate
|
from qmk.json_schema import json_load
|
||||||
from qmk.keyboard import keyboard_completer, keyboard_folder
|
from qmk.keyboard import keyboard_completer, keyboard_folder
|
||||||
from qmk.keymap import locate_keymap
|
|
||||||
from qmk.path import normpath
|
from qmk.path import normpath
|
||||||
|
|
||||||
|
|
||||||
|
@ -158,19 +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('-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('-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('-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 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)
|
@cli.subcommand('Used by the make system to generate info_config.h from info.json', hidden=True)
|
||||||
def generate_config_h(cli):
|
def generate_config_h(cli):
|
||||||
"""Generates the info_config.h file.
|
"""Generates the info_config.h file.
|
||||||
"""
|
"""
|
||||||
# Determine our keyboard/keymap
|
kb_info_json = dotty(info_json(cli.args.keyboard, overrides=get_keyboard_overrides(cli.args.keyboard, cli.args.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))
|
|
||||||
|
|
||||||
# Build the info_config.h file.
|
# 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']
|
config_h_lines = ['/* This file was generated by `qmk generate-config-h`. Do not edit or copy.' ' */', '', '#pragma once']
|
||||||
|
|
|
@ -4,7 +4,7 @@ from dotty_dict import dotty
|
||||||
from milc import cli
|
from milc import cli
|
||||||
|
|
||||||
from qmk.decorators import automagic_keyboard
|
from qmk.decorators import automagic_keyboard
|
||||||
from qmk.info import info_json
|
from qmk.info import info_json, get_keyboard_overrides
|
||||||
from qmk.path import is_keyboard, normpath
|
from qmk.path import is_keyboard, normpath
|
||||||
from qmk.keyboard import keyboard_completer
|
from qmk.keyboard import keyboard_completer
|
||||||
|
|
||||||
|
@ -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('-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('-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('-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)
|
@cli.subcommand('Used by the make system to generate LUFA Keyboard.h from info.json', hidden=True)
|
||||||
@automagic_keyboard
|
@automagic_keyboard
|
||||||
def generate_dfu_header(cli):
|
def generate_dfu_header(cli):
|
||||||
|
@ -28,7 +29,7 @@ def generate_dfu_header(cli):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Build the Keyboard.h file.
|
# Build the Keyboard.h file.
|
||||||
kb_info_json = dotty(info_json(cli.config.generate_dfu_header.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 = ['/* 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"]}')
|
keyboard_h_lines.append(f'#define MANUFACTURER {kb_info_json["manufacturer"]}')
|
||||||
|
|
|
@ -9,7 +9,7 @@ from jsonschema import Draft7Validator, RefResolver, validators
|
||||||
from milc import cli
|
from milc import cli
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from qmk.decorators import automagic_keyboard, automagic_keymap
|
from qmk.decorators import automagic_keyboard
|
||||||
from qmk.info import info_json
|
from qmk.info import info_json
|
||||||
from qmk.json_encoders import InfoJSONEncoder
|
from qmk.json_encoders import InfoJSONEncoder
|
||||||
from qmk.json_schema import compile_schema_store
|
from qmk.json_schema import compile_schema_store
|
||||||
|
@ -46,12 +46,10 @@ def strip_info_json(kb_info_json):
|
||||||
|
|
||||||
|
|
||||||
@cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='Keyboard to show info for.')
|
@cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='Keyboard to show info for.')
|
||||||
@cli.argument('-km', '--keymap', help='Show the layers for a JSON keymap too.')
|
|
||||||
@cli.argument('-o', '--output', arg_only=True, completer=FilesCompleter, help='Write the output the specified file, overwriting if necessary.')
|
@cli.argument('-o', '--output', arg_only=True, completer=FilesCompleter, help='Write the output the specified file, overwriting if necessary.')
|
||||||
@cli.argument('-ow', '--overwrite', arg_only=True, action='store_true', help='Overwrite the existing info.json. (Overrides the location of --output)')
|
@cli.argument('-ow', '--overwrite', arg_only=True, action='store_true', help='Overwrite the existing info.json. (Overrides the location of --output)')
|
||||||
@cli.subcommand('Generate an info.json file for a keyboard.', hidden=False if cli.config.user.developer else True)
|
@cli.subcommand('Generate an info.json file for a keyboard.', hidden=False if cli.config.user.developer else True)
|
||||||
@automagic_keyboard
|
@automagic_keyboard
|
||||||
@automagic_keymap
|
|
||||||
def generate_info_json(cli):
|
def generate_info_json(cli):
|
||||||
"""Generate an info.json file for a keyboard
|
"""Generate an info.json file for a keyboard
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -2,16 +2,16 @@
|
||||||
"""
|
"""
|
||||||
from milc import cli
|
from milc import cli
|
||||||
|
|
||||||
from qmk.info import info_json
|
from qmk.info import info_json, get_keyboard_overrides
|
||||||
from qmk.keyboard import keyboard_completer, keyboard_folder
|
from qmk.keyboard import keyboard_completer, keyboard_folder
|
||||||
from qmk.path import normpath
|
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
|
"""Detect if a given keyboard is doing data driven layouts
|
||||||
"""
|
"""
|
||||||
# Build the info.json file
|
# Build the info.json file
|
||||||
kb_info_json = info_json(keyboard)
|
kb_info_json = info_json(keyboard, overrides=get_keyboard_overrides(keyboard, keymap))
|
||||||
|
|
||||||
for layout_name in kb_info_json['layouts']:
|
for layout_name in kb_info_json['layouts']:
|
||||||
if kb_info_json['layouts'][layout_name]['c_macro']:
|
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('-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('-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('-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)
|
@cli.subcommand('Used by the make system to generate keyboard.h from info.json', hidden=True)
|
||||||
def generate_keyboard_h(cli):
|
def generate_keyboard_h(cli):
|
||||||
"""Generates the keyboard.h file.
|
"""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.
|
# 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"']
|
keyboard_h_lines = ['/* This file was generated by `qmk generate-keyboard-h`. Do not edit or copy.' ' */', '', '#pragma once', '#include "quantum.h"']
|
||||||
|
|
|
@ -4,7 +4,7 @@ from milc import cli
|
||||||
|
|
||||||
from qmk.constants import COL_LETTERS, ROW_LETTERS
|
from qmk.constants import COL_LETTERS, ROW_LETTERS
|
||||||
from qmk.decorators import automagic_keyboard, automagic_keymap
|
from qmk.decorators import automagic_keyboard, automagic_keymap
|
||||||
from qmk.info import info_json
|
from qmk.info import info_json, get_keyboard_overrides
|
||||||
from qmk.keyboard import keyboard_completer, keyboard_folder
|
from qmk.keyboard import keyboard_completer, keyboard_folder
|
||||||
from qmk.path import is_keyboard, normpath
|
from qmk.path import is_keyboard, normpath
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ usb_properties = {
|
||||||
@cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to')
|
@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('-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('-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)
|
@cli.subcommand('Used by the make system to generate layouts.h from info.json', hidden=True)
|
||||||
@automagic_keyboard
|
@automagic_keyboard
|
||||||
@automagic_keymap
|
@automagic_keymap
|
||||||
|
@ -35,7 +36,7 @@ def generate_layouts(cli):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Build the info.json file
|
# Build the info.json file
|
||||||
kb_info_json = info_json(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.
|
# Build the layouts.h file.
|
||||||
layouts_h_lines = ['/* This file was generated by `qmk generate-layouts`. Do not edit or copy.' ' */', '', '#pragma once']
|
layouts_h_lines = ['/* This file was generated by `qmk generate-layouts`. Do not edit or copy.' ' */', '', '#pragma once']
|
||||||
|
|
|
@ -5,10 +5,9 @@ from pathlib import Path
|
||||||
from dotty_dict import dotty
|
from dotty_dict import dotty
|
||||||
from milc import cli
|
from milc import cli
|
||||||
|
|
||||||
from qmk.info import info_json
|
from qmk.info import info_json, get_keyboard_overrides
|
||||||
from qmk.json_schema import json_load, validate
|
from qmk.json_schema import json_load
|
||||||
from qmk.keyboard import keyboard_completer, keyboard_folder
|
from qmk.keyboard import keyboard_completer, keyboard_folder
|
||||||
from qmk.keymap import locate_keymap
|
|
||||||
from qmk.path import normpath
|
from qmk.path import normpath
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,21 +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('-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('-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('-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('-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)
|
@cli.subcommand('Used by the make system to generate rules.mk from info.json', hidden=True)
|
||||||
def generate_rules_mk(cli):
|
def generate_rules_mk(cli):
|
||||||
"""Generates a rules.mk file from info.json.
|
"""Generates a rules.mk file from info.json.
|
||||||
"""
|
"""
|
||||||
# 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))
|
|
||||||
|
|
||||||
info_rules_map = json_load(Path('data/mappings/info_rules.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, cli.args.keymap)))
|
||||||
rules_mk_lines = ['# This file was generated by `qmk generate-rules-mk`. Do not edit or copy.', '']
|
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
|
# Iterate through the info_rules map to generate basic rules
|
||||||
|
|
|
@ -18,13 +18,9 @@ from qmk.path import is_keyboard
|
||||||
UNICODE_SUPPORT = sys.stdout.encoding.lower().startswith('utf')
|
UNICODE_SUPPORT = sys.stdout.encoding.lower().startswith('utf')
|
||||||
|
|
||||||
|
|
||||||
def show_keymap(kb_info_json, title_caps=True):
|
def show_keymap(kb_info_json, keymap_data, title_caps=True):
|
||||||
"""Render the keymap in ascii art.
|
"""Render the keymap in ascii art.
|
||||||
"""
|
"""
|
||||||
keymap_path = locate_keymap(cli.config.info.keyboard, cli.config.info.keymap)
|
|
||||||
|
|
||||||
if keymap_path and keymap_path.suffix == '.json':
|
|
||||||
keymap_data = json.load(keymap_path.open(encoding='utf-8'))
|
|
||||||
layout_name = keymap_data['layout']
|
layout_name = keymap_data['layout']
|
||||||
layout_name = kb_info_json.get('layout_aliases', {}).get(layout_name, layout_name) # Resolve alias names
|
layout_name = kb_info_json.get('layout_aliases', {}).get(layout_name, layout_name) # Resolve alias names
|
||||||
|
|
||||||
|
@ -161,19 +157,27 @@ def info(cli):
|
||||||
print_parsed_rules_mk(cli.config.info.keyboard)
|
print_parsed_rules_mk(cli.config.info.keyboard)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
# Pull in keymap overrides if necessary
|
||||||
|
keymap_path = locate_keymap(cli.config.info.keyboard, cli.config.info.keymap) if cli.config.info.keymap else None
|
||||||
|
keymap_data = json.load(keymap_path.open(encoding='utf-8')) if keymap_path and keymap_path.suffix == '.json' else None
|
||||||
|
|
||||||
# Build the info.json file
|
# Build the info.json file
|
||||||
kb_info_json = info_json(cli.config.info.keyboard)
|
overrides = keymap_data.get('keyboard_overrides') if keymap_data else None
|
||||||
|
kb_info_json = info_json(cli.config.info.keyboard, overrides=overrides)
|
||||||
|
|
||||||
# Output in the requested format
|
# Output in the requested format
|
||||||
if cli.args.format == 'json':
|
if cli.args.format == 'json':
|
||||||
print(json.dumps(kb_info_json, cls=InfoJSONEncoder))
|
print(json.dumps(kb_info_json, cls=InfoJSONEncoder))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
elif cli.args.format == 'text':
|
elif cli.args.format == 'text':
|
||||||
print_dotted_output(kb_info_json)
|
print_dotted_output(kb_info_json)
|
||||||
title_caps = False
|
title_caps = False
|
||||||
|
|
||||||
elif cli.args.format == 'friendly':
|
elif cli.args.format == 'friendly':
|
||||||
print_friendly_output(kb_info_json)
|
print_friendly_output(kb_info_json)
|
||||||
title_caps = True
|
title_caps = True
|
||||||
|
|
||||||
else:
|
else:
|
||||||
cli.log.error('Unknown format: %s', cli.args.format)
|
cli.log.error('Unknown format: %s', cli.args.format)
|
||||||
return False
|
return False
|
||||||
|
@ -184,5 +188,5 @@ def info(cli):
|
||||||
if cli.config.info.matrix:
|
if cli.config.info.matrix:
|
||||||
show_matrix(kb_info_json, title_caps)
|
show_matrix(kb_info_json, title_caps)
|
||||||
|
|
||||||
if cli.config_source.info.keymap and cli.config_source.info.keymap != 'config_file':
|
if keymap_data:
|
||||||
show_keymap(kb_info_json, title_caps)
|
show_keymap(kb_info_json, keymap_data, title_caps)
|
||||||
|
|
|
@ -76,10 +76,12 @@ def lint(cli):
|
||||||
cli.log.warning('Both --all-kb and --keyboard passed, --all-kb takes presidence.')
|
cli.log.warning('Both --all-kb and --keyboard passed, --all-kb takes presidence.')
|
||||||
|
|
||||||
keyboard_list = list_keyboards()
|
keyboard_list = list_keyboards()
|
||||||
|
|
||||||
elif not cli.config.lint.keyboard:
|
elif not cli.config.lint.keyboard:
|
||||||
cli.log.error('Missing required arguments: --keyboard or --all-kb')
|
cli.log.error('Missing required arguments: --keyboard or --all-kb')
|
||||||
cli.print_help()
|
cli.print_help()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
else:
|
else:
|
||||||
keyboard_list = cli.config.lint.keyboard.split(',')
|
keyboard_list = cli.config.lint.keyboard.split(',')
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ from milc import cli
|
||||||
|
|
||||||
import qmk.keymap
|
import qmk.keymap
|
||||||
from qmk.constants import QMK_FIRMWARE, KEYBOARD_OUTPUT_PREFIX
|
from qmk.constants import QMK_FIRMWARE, KEYBOARD_OUTPUT_PREFIX
|
||||||
from qmk.json_schema import json_load
|
from qmk.json_schema import json_load, validate
|
||||||
|
|
||||||
time_fmt = '%Y-%m-%d-%H:%M:%S'
|
time_fmt = '%Y-%m-%d-%H:%M:%S'
|
||||||
|
|
||||||
|
@ -194,6 +194,12 @@ def compile_configurator_json(user_keymap, bootloader=None, parallel=1, **env_va
|
||||||
version_h = Path('quantum/version.h')
|
version_h = Path('quantum/version.h')
|
||||||
version_h.write_text(create_version_h())
|
version_h.write_text(create_version_h())
|
||||||
|
|
||||||
|
# Write the keymap json out
|
||||||
|
json_output = keymap_output / 'keymap.json'
|
||||||
|
|
||||||
|
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
|
# Return a command that can be run to make the keymap and flash if given
|
||||||
verbose = 'true' if cli.config.general.verbose else 'false'
|
verbose = 'true' if cli.config.general.verbose else 'false'
|
||||||
color = 'true' if cli.config.general.color else 'false'
|
color = 'true' if cli.config.general.color else 'false'
|
||||||
|
@ -242,8 +248,10 @@ def compile_configurator_json(user_keymap, bootloader=None, parallel=1, **env_va
|
||||||
def parse_configurator_json(configurator_file):
|
def parse_configurator_json(configurator_file):
|
||||||
"""Open and parse a configurator json export
|
"""Open and parse a configurator json export
|
||||||
"""
|
"""
|
||||||
# FIXME(skullydazed/anyone): Add validation here
|
|
||||||
user_keymap = json.load(configurator_file)
|
user_keymap = json.load(configurator_file)
|
||||||
|
|
||||||
|
validate(user_keymap, 'qmk.keymap.v1')
|
||||||
|
|
||||||
orig_keyboard = user_keymap['keyboard']
|
orig_keyboard = user_keymap['keyboard']
|
||||||
aliases = json_load(Path('data/mappings/keyboard_aliases.json'))
|
aliases = json_load(Path('data/mappings/keyboard_aliases.json'))
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
"""Functions that help us generate and use info.json files.
|
"""Functions that help us generate and use info.json files.
|
||||||
"""
|
"""
|
||||||
|
import json
|
||||||
from glob import glob
|
from glob import glob
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
@ -7,7 +8,7 @@ import jsonschema
|
||||||
from dotty_dict import dotty
|
from dotty_dict import dotty
|
||||||
from milc import cli
|
from milc import cli
|
||||||
|
|
||||||
from qmk.constants import CHIBIOS_PROCESSORS, LUFA_PROCESSORS, VUSB_PROCESSORS
|
from qmk.constants import CHIBIOS_PROCESSORS, KEYBOARD_OUTPUT_PREFIX, LUFA_PROCESSORS, VUSB_PROCESSORS
|
||||||
from qmk.c_parse import find_layouts
|
from qmk.c_parse import find_layouts
|
||||||
from qmk.json_schema import deep_update, json_load, validate
|
from qmk.json_schema import deep_update, json_load, validate
|
||||||
from qmk.keyboard import config_h, rules_mk
|
from qmk.keyboard import config_h, rules_mk
|
||||||
|
@ -25,7 +26,7 @@ def _valid_community_layout(layout):
|
||||||
return (Path('layouts/default') / layout).exists()
|
return (Path('layouts/default') / layout).exists()
|
||||||
|
|
||||||
|
|
||||||
def info_json(keyboard):
|
def info_json(keyboard, *, overrides=None):
|
||||||
"""Generate the info.json data for a specific keyboard.
|
"""Generate the info.json data for a specific keyboard.
|
||||||
"""
|
"""
|
||||||
cur_dir = Path('keyboards')
|
cur_dir = Path('keyboards')
|
||||||
|
@ -59,11 +60,14 @@ def info_json(keyboard):
|
||||||
layout_json['c_macro'] = True
|
layout_json['c_macro'] = True
|
||||||
info_data['layouts'][layout_name] = layout_json
|
info_data['layouts'][layout_name] = layout_json
|
||||||
|
|
||||||
# Merge in the data from info.json, config.h, and rules.mk
|
# Merge in the data from info.json, config.h, rules.mk, and overrides
|
||||||
info_data = merge_info_jsons(keyboard, info_data)
|
info_data = merge_info_jsons(keyboard, info_data)
|
||||||
info_data = _extract_rules_mk(info_data)
|
info_data = _extract_rules_mk(info_data)
|
||||||
info_data = _extract_config_h(info_data)
|
info_data = _extract_config_h(info_data)
|
||||||
|
|
||||||
|
if overrides:
|
||||||
|
info_data = merge_info_data(info_data, overrides)
|
||||||
|
|
||||||
# Ensure that we have matrix row and column counts
|
# Ensure that we have matrix row and column counts
|
||||||
info_data = _matrix_size(info_data)
|
info_data = _matrix_size(info_data)
|
||||||
|
|
||||||
|
@ -102,6 +106,27 @@ def info_json(keyboard):
|
||||||
return info_data
|
return info_data
|
||||||
|
|
||||||
|
|
||||||
|
def get_keyboard_overrides(keyboard, keymap=None):
|
||||||
|
"""Checks for keyboard_overrides.json in the keyboard build directory and returns them if it exists.
|
||||||
|
"""
|
||||||
|
if not keymap:
|
||||||
|
return None
|
||||||
|
|
||||||
|
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']
|
||||||
|
|
||||||
|
if 'config' in keymap_json:
|
||||||
|
return keymap_json['config']
|
||||||
|
|
||||||
|
|
||||||
def _extract_features(info_data, rules):
|
def _extract_features(info_data, rules):
|
||||||
"""Find all the features enabled in rules.mk.
|
"""Find all the features enabled in rules.mk.
|
||||||
"""
|
"""
|
||||||
|
@ -660,26 +685,9 @@ def unknown_processor_rules(info_data, rules):
|
||||||
return info_data
|
return info_data
|
||||||
|
|
||||||
|
|
||||||
def merge_info_jsons(keyboard, info_data):
|
def merge_info_data(info_data, new_info_data):
|
||||||
"""Return a merged copy of all the info.json files for a keyboard.
|
"""Return a merged copy of info_data and new_info_data.
|
||||||
"""
|
"""
|
||||||
for info_file in find_info_json(keyboard):
|
|
||||||
# Load and validate the JSON data
|
|
||||||
new_info_data = json_load(info_file)
|
|
||||||
|
|
||||||
if not isinstance(new_info_data, dict):
|
|
||||||
_log_error(info_data, "Invalid file %s, root object should be a dictionary." % (str(info_file),))
|
|
||||||
continue
|
|
||||||
|
|
||||||
try:
|
|
||||||
validate(new_info_data, 'qmk.keyboard.v1')
|
|
||||||
except jsonschema.ValidationError as e:
|
|
||||||
json_path = '.'.join([str(p) for p in e.absolute_path])
|
|
||||||
cli.log.error('Not including data from file: %s', info_file)
|
|
||||||
cli.log.error('\t%s: %s', json_path, e.message)
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Merge layout data in
|
|
||||||
if 'layout_aliases' in new_info_data:
|
if 'layout_aliases' in new_info_data:
|
||||||
info_data['layout_aliases'] = {**info_data.get('layout_aliases', {}), **new_info_data['layout_aliases']}
|
info_data['layout_aliases'] = {**info_data.get('layout_aliases', {}), **new_info_data['layout_aliases']}
|
||||||
del new_info_data['layout_aliases']
|
del new_info_data['layout_aliases']
|
||||||
|
@ -709,6 +717,31 @@ def merge_info_jsons(keyboard, info_data):
|
||||||
return info_data
|
return info_data
|
||||||
|
|
||||||
|
|
||||||
|
def merge_info_jsons(keyboard, info_data):
|
||||||
|
"""Return a merged copy of all the info.json files for a keyboard.
|
||||||
|
"""
|
||||||
|
for info_file in find_info_json(keyboard):
|
||||||
|
# Load and validate the JSON data
|
||||||
|
new_info_data = json_load(info_file)
|
||||||
|
|
||||||
|
if not isinstance(new_info_data, dict):
|
||||||
|
_log_error(info_data, "Invalid file %s, root object should be a dictionary." % (str(info_file),))
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
validate(new_info_data, 'qmk.keyboard.v1')
|
||||||
|
except jsonschema.ValidationError as e:
|
||||||
|
json_path = '.'.join([str(p) for p in e.absolute_path])
|
||||||
|
cli.log.error('Not including data from file: %s', info_file)
|
||||||
|
cli.log.error('\t%s: %s', json_path, e.message)
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Merge layout data in
|
||||||
|
merge_info_data(info_data, new_info_data)
|
||||||
|
|
||||||
|
return info_data
|
||||||
|
|
||||||
|
|
||||||
def find_info_json(keyboard):
|
def find_info_json(keyboard):
|
||||||
"""Finds all the info.json files associated with a keyboard.
|
"""Finds all the info.json files associated with a keyboard.
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue