Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable 'keyboard.json' as a build target #22891

Merged
merged 2 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ quantum/version.h

# DD config at wrong location
/keyboards/**/keymaps/*/info.json
/keyboards/**/keymaps/*/keyboard.json

# Old-style QMK Makefiles
/keyboards/**/Makefile
Expand Down
40 changes: 28 additions & 12 deletions builddefs/build_keyboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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_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)
include $(INFO_RULES_MK)

Expand Down Expand Up @@ -221,7 +221,7 @@ include $(BUILDDEFS_PATH)/converters.mk
MCU_ORIG := $(MCU)
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),)
$(call CATASTROPHIC_ERROR,Platform not defined)
endif
Expand Down Expand Up @@ -335,38 +335,54 @@ ifneq ("$(wildcard $(KEYBOARD_PATH_5)/post_config.h)","")
POST_CONFIG_H += $(KEYBOARD_PATH_5)/post_config.h
endif

# Pull in stuff from info.json
INFO_JSON_FILES :=
# Create dependencies on DD keyboard config - structure validated elsewhere
DD_CONFIG_FILES :=
ifneq ("$(wildcard $(KEYBOARD_PATH_1)/info.json)","")
INFO_JSON_FILES += $(KEYBOARD_PATH_1)/info.json
DD_CONFIG_FILES += $(KEYBOARD_PATH_1)/info.json
endif
ifneq ("$(wildcard $(KEYBOARD_PATH_2)/info.json)","")
INFO_JSON_FILES += $(KEYBOARD_PATH_2)/info.json
DD_CONFIG_FILES += $(KEYBOARD_PATH_2)/info.json
endif
ifneq ("$(wildcard $(KEYBOARD_PATH_3)/info.json)","")
INFO_JSON_FILES += $(KEYBOARD_PATH_3)/info.json
DD_CONFIG_FILES += $(KEYBOARD_PATH_3)/info.json
endif
ifneq ("$(wildcard $(KEYBOARD_PATH_4)/info.json)","")
INFO_JSON_FILES += $(KEYBOARD_PATH_4)/info.json
DD_CONFIG_FILES += $(KEYBOARD_PATH_4)/info.json
endif
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

CONFIG_H += $(INTERMEDIATE_OUTPUT)/src/info_config.h
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)
$(eval CMD=$(QMK_BIN) generate-config-h --quiet --keyboard $(KEYBOARD) --output $(INTERMEDIATE_OUTPUT)/src/info_config.h)
@$(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)
$(eval CMD=$(QMK_BIN) generate-keyboard-c --quiet --keyboard $(KEYBOARD) --output $(INTERMEDIATE_OUTPUT)/src/default_keyboard.c)
@$(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)
$(eval CMD=$(QMK_BIN) generate-keyboard-h --quiet --keyboard $(KEYBOARD) --include $(FOUND_KEYBOARD_H) --output $(INTERMEDIATE_OUTPUT)/src/default_keyboard.h)
@$(BUILD_CMD)
Expand Down
20 changes: 0 additions & 20 deletions data/templates/keyboard/config.h

This file was deleted.

1 change: 0 additions & 1 deletion data/templates/keyboard/rules.mk

This file was deleted.

3 changes: 0 additions & 3 deletions keyboards/zvecr/zv48/f401/rules.mk

This file was deleted.

3 changes: 2 additions & 1 deletion lib/python/qmk/cli/generate/make_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
@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)
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 = [
'info.json',
'keyboard.json',
'rules.mk',
'post_rules.mk',
'config.h',
Expand Down
2 changes: 1 addition & 1 deletion lib/python/qmk/cli/new/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def new_keyboard(cli):

# merge in infos
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'To start working on things, `cd` into {{fg_cyan}}keyboards/{kb_name}{{fg_reset}},')
Expand Down
15 changes: 13 additions & 2 deletions lib/python/qmk/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,17 @@ def unknown_processor_rules(info_data, rules):
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):
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
new_info_data = json_load(info_file)

Expand Down Expand Up @@ -899,7 +909,7 @@ def find_info_json(keyboard):
base_path = Path('keyboards')
keyboard_path = base_path / keyboard
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
rules = rules_mk(keyboard)
Expand All @@ -911,6 +921,7 @@ def find_info_json(keyboard):
if keyboard_parent == base_path:
break
info_jsons.append(keyboard_parent / 'info.json')
info_jsons.append(keyboard_parent / 'keyboard.json')
keyboard_parent = keyboard_parent.parent

# Return a list of the info.json files that actually exist
Expand Down
10 changes: 6 additions & 4 deletions lib/python/qmk/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ def keyboard_folder_or_all(keyboard):


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):
Expand All @@ -181,8 +181,10 @@ def list_keyboards(resolve_defaults=True):
"""Returns a list of all keyboards - optionally processing any DEFAULT_FOLDER.
"""
# We avoid pathlib here because this is performance critical code.
kb_wildcard = os.path.join(base_path, "**", "rules.mk")
paths = [path for path in glob(kb_wildcard, recursive=True) if os.path.sep + 'keymaps' + os.path.sep not in path]
paths = []
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)
if resolve_defaults:
Expand Down
3 changes: 2 additions & 1 deletion lib/python/qmk/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ def is_keyboard(keyboard_name):
if keyboard_name:
keyboard_path = QMK_FIRMWARE / 'keyboards' / keyboard_name
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'])):
Expand Down