mirror of
https://github.com/Keychron/qmk_firmware.git
synced 2024-11-22 00:16:41 +06:00
Enable 'keyboard.json' as a build target (#22891)
This commit is contained in:
parent
c5225ab500
commit
9f4a9d5826
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -37,6 +37,7 @@ quantum/version.h
|
||||||
|
|
||||||
# DD config at wrong location
|
# DD config at wrong location
|
||||||
/keyboards/**/keymaps/*/info.json
|
/keyboards/**/keymaps/*/info.json
|
||||||
|
/keyboards/**/keymaps/*/keyboard.json
|
||||||
|
|
||||||
# Old-style QMK Makefiles
|
# Old-style QMK Makefiles
|
||||||
/keyboards/**/Makefile
|
/keyboards/**/Makefile
|
||||||
|
|
|
@ -119,7 +119,7 @@ MAIN_KEYMAP_PATH_3 := $(KEYBOARD_PATH_3)/keymaps/$(KEYMAP)
|
||||||
MAIN_KEYMAP_PATH_4 := $(KEYBOARD_PATH_4)/keymaps/$(KEYMAP)
|
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 DD keyboard config
|
||||||
INFO_RULES_MK = $(shell $(QMK_BIN) generate-rules-mk --quiet --escape --keyboard $(KEYBOARD) --output $(INTERMEDIATE_OUTPUT)/src/info_rules.mk)
|
INFO_RULES_MK = $(shell $(QMK_BIN) generate-rules-mk --quiet --escape --keyboard $(KEYBOARD) --output $(INTERMEDIATE_OUTPUT)/src/info_rules.mk)
|
||||||
include $(INFO_RULES_MK)
|
include $(INFO_RULES_MK)
|
||||||
|
|
||||||
|
@ -221,7 +221,7 @@ include $(BUILDDEFS_PATH)/converters.mk
|
||||||
MCU_ORIG := $(MCU)
|
MCU_ORIG := $(MCU)
|
||||||
include $(wildcard $(PLATFORM_PATH)/*/mcu_selection.mk)
|
include $(wildcard $(PLATFORM_PATH)/*/mcu_selection.mk)
|
||||||
|
|
||||||
# PLATFORM_KEY should be detected in info.json via key 'processor' (or rules.mk 'MCU')
|
# PLATFORM_KEY should be detected in DD keyboard config via key 'processor' (or rules.mk 'MCU')
|
||||||
ifeq ($(PLATFORM_KEY),)
|
ifeq ($(PLATFORM_KEY),)
|
||||||
$(call CATASTROPHIC_ERROR,Platform not defined)
|
$(call CATASTROPHIC_ERROR,Platform not defined)
|
||||||
endif
|
endif
|
||||||
|
@ -335,38 +335,54 @@ ifneq ("$(wildcard $(KEYBOARD_PATH_5)/post_config.h)","")
|
||||||
POST_CONFIG_H += $(KEYBOARD_PATH_5)/post_config.h
|
POST_CONFIG_H += $(KEYBOARD_PATH_5)/post_config.h
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Pull in stuff from info.json
|
# Create dependencies on DD keyboard config - structure validated elsewhere
|
||||||
INFO_JSON_FILES :=
|
DD_CONFIG_FILES :=
|
||||||
ifneq ("$(wildcard $(KEYBOARD_PATH_1)/info.json)","")
|
ifneq ("$(wildcard $(KEYBOARD_PATH_1)/info.json)","")
|
||||||
INFO_JSON_FILES += $(KEYBOARD_PATH_1)/info.json
|
DD_CONFIG_FILES += $(KEYBOARD_PATH_1)/info.json
|
||||||
endif
|
endif
|
||||||
ifneq ("$(wildcard $(KEYBOARD_PATH_2)/info.json)","")
|
ifneq ("$(wildcard $(KEYBOARD_PATH_2)/info.json)","")
|
||||||
INFO_JSON_FILES += $(KEYBOARD_PATH_2)/info.json
|
DD_CONFIG_FILES += $(KEYBOARD_PATH_2)/info.json
|
||||||
endif
|
endif
|
||||||
ifneq ("$(wildcard $(KEYBOARD_PATH_3)/info.json)","")
|
ifneq ("$(wildcard $(KEYBOARD_PATH_3)/info.json)","")
|
||||||
INFO_JSON_FILES += $(KEYBOARD_PATH_3)/info.json
|
DD_CONFIG_FILES += $(KEYBOARD_PATH_3)/info.json
|
||||||
endif
|
endif
|
||||||
ifneq ("$(wildcard $(KEYBOARD_PATH_4)/info.json)","")
|
ifneq ("$(wildcard $(KEYBOARD_PATH_4)/info.json)","")
|
||||||
INFO_JSON_FILES += $(KEYBOARD_PATH_4)/info.json
|
DD_CONFIG_FILES += $(KEYBOARD_PATH_4)/info.json
|
||||||
endif
|
endif
|
||||||
ifneq ("$(wildcard $(KEYBOARD_PATH_5)/info.json)","")
|
ifneq ("$(wildcard $(KEYBOARD_PATH_5)/info.json)","")
|
||||||
INFO_JSON_FILES += $(KEYBOARD_PATH_5)/info.json
|
DD_CONFIG_FILES += $(KEYBOARD_PATH_5)/info.json
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifneq ("$(wildcard $(KEYBOARD_PATH_1)/keyboard.json)","")
|
||||||
|
DD_CONFIG_FILES += $(KEYBOARD_PATH_1)/keyboard.json
|
||||||
|
endif
|
||||||
|
ifneq ("$(wildcard $(KEYBOARD_PATH_2)/keyboard.json)","")
|
||||||
|
DD_CONFIG_FILES += $(KEYBOARD_PATH_2)/keyboard.json
|
||||||
|
endif
|
||||||
|
ifneq ("$(wildcard $(KEYBOARD_PATH_3)/keyboard.json)","")
|
||||||
|
DD_CONFIG_FILES += $(KEYBOARD_PATH_3)/keyboard.json
|
||||||
|
endif
|
||||||
|
ifneq ("$(wildcard $(KEYBOARD_PATH_4)/keyboard.json)","")
|
||||||
|
DD_CONFIG_FILES += $(KEYBOARD_PATH_4)/keyboard.json
|
||||||
|
endif
|
||||||
|
ifneq ("$(wildcard $(KEYBOARD_PATH_5)/keyboard.json)","")
|
||||||
|
DD_CONFIG_FILES += $(KEYBOARD_PATH_5)/keyboard.json
|
||||||
endif
|
endif
|
||||||
|
|
||||||
CONFIG_H += $(INTERMEDIATE_OUTPUT)/src/info_config.h
|
CONFIG_H += $(INTERMEDIATE_OUTPUT)/src/info_config.h
|
||||||
KEYBOARD_SRC += $(INTERMEDIATE_OUTPUT)/src/default_keyboard.c
|
KEYBOARD_SRC += $(INTERMEDIATE_OUTPUT)/src/default_keyboard.c
|
||||||
|
|
||||||
$(INTERMEDIATE_OUTPUT)/src/info_config.h: $(INFO_JSON_FILES)
|
$(INTERMEDIATE_OUTPUT)/src/info_config.h: $(DD_CONFIG_FILES)
|
||||||
@$(SILENT) || printf "$(MSG_GENERATING) $@" | $(AWK_CMD)
|
@$(SILENT) || printf "$(MSG_GENERATING) $@" | $(AWK_CMD)
|
||||||
$(eval CMD=$(QMK_BIN) generate-config-h --quiet --keyboard $(KEYBOARD) --output $(INTERMEDIATE_OUTPUT)/src/info_config.h)
|
$(eval CMD=$(QMK_BIN) generate-config-h --quiet --keyboard $(KEYBOARD) --output $(INTERMEDIATE_OUTPUT)/src/info_config.h)
|
||||||
@$(BUILD_CMD)
|
@$(BUILD_CMD)
|
||||||
|
|
||||||
$(INTERMEDIATE_OUTPUT)/src/default_keyboard.c: $(INFO_JSON_FILES)
|
$(INTERMEDIATE_OUTPUT)/src/default_keyboard.c: $(DD_CONFIG_FILES)
|
||||||
@$(SILENT) || printf "$(MSG_GENERATING) $@" | $(AWK_CMD)
|
@$(SILENT) || printf "$(MSG_GENERATING) $@" | $(AWK_CMD)
|
||||||
$(eval CMD=$(QMK_BIN) generate-keyboard-c --quiet --keyboard $(KEYBOARD) --output $(INTERMEDIATE_OUTPUT)/src/default_keyboard.c)
|
$(eval CMD=$(QMK_BIN) generate-keyboard-c --quiet --keyboard $(KEYBOARD) --output $(INTERMEDIATE_OUTPUT)/src/default_keyboard.c)
|
||||||
@$(BUILD_CMD)
|
@$(BUILD_CMD)
|
||||||
|
|
||||||
$(INTERMEDIATE_OUTPUT)/src/default_keyboard.h: $(INFO_JSON_FILES)
|
$(INTERMEDIATE_OUTPUT)/src/default_keyboard.h: $(DD_CONFIG_FILES)
|
||||||
@$(SILENT) || printf "$(MSG_GENERATING) $@" | $(AWK_CMD)
|
@$(SILENT) || printf "$(MSG_GENERATING) $@" | $(AWK_CMD)
|
||||||
$(eval CMD=$(QMK_BIN) generate-keyboard-h --quiet --keyboard $(KEYBOARD) --include $(FOUND_KEYBOARD_H) --output $(INTERMEDIATE_OUTPUT)/src/default_keyboard.h)
|
$(eval CMD=$(QMK_BIN) generate-keyboard-h --quiet --keyboard $(KEYBOARD) --include $(FOUND_KEYBOARD_H) --output $(INTERMEDIATE_OUTPUT)/src/default_keyboard.h)
|
||||||
@$(BUILD_CMD)
|
@$(BUILD_CMD)
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
// Copyright %YEAR% %REAL_NAME% (@%USER_NAME%)
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Feature disable options
|
|
||||||
* These options are also useful to firmware size reduction.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* disable debug print */
|
|
||||||
//#define NO_DEBUG
|
|
||||||
|
|
||||||
/* disable print */
|
|
||||||
//#define NO_PRINT
|
|
||||||
|
|
||||||
/* disable action features */
|
|
||||||
//#define NO_ACTION_LAYER
|
|
||||||
//#define NO_ACTION_TAPPING
|
|
||||||
//#define NO_ACTION_ONESHOT
|
|
|
@ -1 +0,0 @@
|
||||||
# This file intentionally left blank
|
|
|
@ -1,3 +0,0 @@
|
||||||
# Disable unsupported hardware
|
|
||||||
AUDIO_SUPPORTED = no
|
|
||||||
BACKLIGHT_SUPPORTED = no
|
|
|
@ -18,10 +18,11 @@ from qmk.path import normpath, FileType
|
||||||
@cli.argument('-km', '--keymap', completer=keymap_completer, help='The keymap to build a firmware for. Ignored when a configurator export is supplied.')
|
@cli.argument('-km', '--keymap', completer=keymap_completer, help='The keymap to build a firmware for. Ignored when a configurator export is supplied.')
|
||||||
@cli.subcommand('Generates the list of dependencies associated with a keyboard build and its generated files.', hidden=True)
|
@cli.subcommand('Generates the list of dependencies associated with a keyboard build and its generated files.', hidden=True)
|
||||||
def generate_make_dependencies(cli):
|
def generate_make_dependencies(cli):
|
||||||
"""Generates the list of dependent info.json, rules.mk, and config.h files for a keyboard.
|
"""Generates the list of dependent config files for a keyboard.
|
||||||
"""
|
"""
|
||||||
interesting_files = [
|
interesting_files = [
|
||||||
'info.json',
|
'info.json',
|
||||||
|
'keyboard.json',
|
||||||
'rules.mk',
|
'rules.mk',
|
||||||
'post_rules.mk',
|
'post_rules.mk',
|
||||||
'config.h',
|
'config.h',
|
||||||
|
|
|
@ -251,7 +251,7 @@ def new_keyboard(cli):
|
||||||
|
|
||||||
# merge in infos
|
# merge in infos
|
||||||
community_info = Path(COMMUNITY / f'{default_layout}/info.json')
|
community_info = Path(COMMUNITY / f'{default_layout}/info.json')
|
||||||
augment_community_info(community_info, keyboard(kb_name) / community_info.name)
|
augment_community_info(community_info, keyboard(kb_name) / 'keyboard.json')
|
||||||
|
|
||||||
cli.log.info(f'{{fg_green}}Created a new keyboard called {{fg_cyan}}{kb_name}{{fg_green}}.{{fg_reset}}')
|
cli.log.info(f'{{fg_green}}Created a new keyboard called {{fg_cyan}}{kb_name}{{fg_green}}.{{fg_reset}}')
|
||||||
cli.log.info(f"Build Command: {{fg_yellow}}qmk compile -kb {kb_name} -km default{{fg_reset}}.")
|
cli.log.info(f"Build Command: {{fg_yellow}}qmk compile -kb {kb_name} -km default{{fg_reset}}.")
|
||||||
|
|
|
@ -863,7 +863,17 @@ def unknown_processor_rules(info_data, rules):
|
||||||
def merge_info_jsons(keyboard, info_data):
|
def merge_info_jsons(keyboard, info_data):
|
||||||
"""Return a merged copy of all the info.json files for a keyboard.
|
"""Return a merged copy of all the info.json files for a keyboard.
|
||||||
"""
|
"""
|
||||||
for info_file in find_info_json(keyboard):
|
config_files = find_info_json(keyboard)
|
||||||
|
|
||||||
|
# keyboard.json can only exist at the deepest part of the tree
|
||||||
|
keyboard_json_count = 0
|
||||||
|
for index, info_file in enumerate(config_files):
|
||||||
|
if Path(info_file).name == 'keyboard.json':
|
||||||
|
keyboard_json_count += 1
|
||||||
|
if index != 0 or keyboard_json_count > 1:
|
||||||
|
_log_error(info_data, f'Invalid keyboard.json location detected: {info_file}.')
|
||||||
|
|
||||||
|
for info_file in config_files:
|
||||||
# Load and validate the JSON data
|
# Load and validate the JSON data
|
||||||
new_info_data = json_load(info_file)
|
new_info_data = json_load(info_file)
|
||||||
|
|
||||||
|
@ -921,7 +931,7 @@ def find_info_json(keyboard):
|
||||||
base_path = Path('keyboards')
|
base_path = Path('keyboards')
|
||||||
keyboard_path = base_path / keyboard
|
keyboard_path = base_path / keyboard
|
||||||
keyboard_parent = keyboard_path.parent
|
keyboard_parent = keyboard_path.parent
|
||||||
info_jsons = [keyboard_path / 'info.json']
|
info_jsons = [keyboard_path / 'info.json', keyboard_path / 'keyboard.json']
|
||||||
|
|
||||||
# Add DEFAULT_FOLDER before parents, if present
|
# Add DEFAULT_FOLDER before parents, if present
|
||||||
rules = rules_mk(keyboard)
|
rules = rules_mk(keyboard)
|
||||||
|
@ -933,6 +943,7 @@ def find_info_json(keyboard):
|
||||||
if keyboard_parent == base_path:
|
if keyboard_parent == base_path:
|
||||||
break
|
break
|
||||||
info_jsons.append(keyboard_parent / 'info.json')
|
info_jsons.append(keyboard_parent / 'info.json')
|
||||||
|
info_jsons.append(keyboard_parent / 'keyboard.json')
|
||||||
keyboard_parent = keyboard_parent.parent
|
keyboard_parent = keyboard_parent.parent
|
||||||
|
|
||||||
# Return a list of the info.json files that actually exist
|
# Return a list of the info.json files that actually exist
|
||||||
|
|
|
@ -166,9 +166,9 @@ def keyboard_folder_or_all(keyboard):
|
||||||
|
|
||||||
|
|
||||||
def _find_name(path):
|
def _find_name(path):
|
||||||
"""Determine the keyboard name by stripping off the base_path and rules.mk.
|
"""Determine the keyboard name by stripping off the base_path and filename.
|
||||||
"""
|
"""
|
||||||
return path.replace(base_path, "").replace(os.path.sep + "rules.mk", "")
|
return path.replace(base_path, "").rsplit(os.path.sep, 1)[0]
|
||||||
|
|
||||||
|
|
||||||
def keyboard_completer(prefix, action, parser, parsed_args):
|
def keyboard_completer(prefix, action, parser, parsed_args):
|
||||||
|
@ -181,8 +181,10 @@ def list_keyboards(resolve_defaults=True):
|
||||||
"""Returns a list of all keyboards - optionally processing any DEFAULT_FOLDER.
|
"""Returns a list of all keyboards - optionally processing any DEFAULT_FOLDER.
|
||||||
"""
|
"""
|
||||||
# We avoid pathlib here because this is performance critical code.
|
# We avoid pathlib here because this is performance critical code.
|
||||||
kb_wildcard = os.path.join(base_path, "**", "rules.mk")
|
paths = []
|
||||||
paths = [path for path in glob(kb_wildcard, recursive=True) if os.path.sep + 'keymaps' + os.path.sep not in path]
|
for marker in ['rules.mk', 'keyboard.json']:
|
||||||
|
kb_wildcard = os.path.join(base_path, "**", marker)
|
||||||
|
paths += [path for path in glob(kb_wildcard, recursive=True) if os.path.sep + 'keymaps' + os.path.sep not in path]
|
||||||
|
|
||||||
found = map(_find_name, paths)
|
found = map(_find_name, paths)
|
||||||
if resolve_defaults:
|
if resolve_defaults:
|
||||||
|
|
|
@ -15,8 +15,9 @@ def is_keyboard(keyboard_name):
|
||||||
if keyboard_name:
|
if keyboard_name:
|
||||||
keyboard_path = QMK_FIRMWARE / 'keyboards' / keyboard_name
|
keyboard_path = QMK_FIRMWARE / 'keyboards' / keyboard_name
|
||||||
rules_mk = keyboard_path / 'rules.mk'
|
rules_mk = keyboard_path / 'rules.mk'
|
||||||
|
keyboard_json = keyboard_path / 'keyboard.json'
|
||||||
|
|
||||||
return rules_mk.exists()
|
return rules_mk.exists() or keyboard_json.exists()
|
||||||
|
|
||||||
|
|
||||||
def under_qmk_firmware(path=Path(os.environ['ORIG_CWD'])):
|
def under_qmk_firmware(path=Path(os.environ['ORIG_CWD'])):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user