Skip to content

Commit a7ff755

Browse files
zvecrArdakilic
authored andcommitted
Enable 'keyboard.json' as a build target (qmk#22891)
1 parent c2be9c1 commit a7ff755

File tree

12 files changed

+53
-45
lines changed

12 files changed

+53
-45
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ quantum/version.h
3737

3838
# DD config at wrong location
3939
/keyboards/**/keymaps/*/info.json
40+
/keyboards/**/keymaps/*/keyboard.json
4041

4142
# Old-style QMK Makefiles
4243
/keyboards/**/Makefile

builddefs/build_keyboard.mk

+28-12
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ MAIN_KEYMAP_PATH_3 := $(KEYBOARD_PATH_3)/keymaps/$(KEYMAP)
119119
MAIN_KEYMAP_PATH_4 := $(KEYBOARD_PATH_4)/keymaps/$(KEYMAP)
120120
MAIN_KEYMAP_PATH_5 := $(KEYBOARD_PATH_5)/keymaps/$(KEYMAP)
121121

122-
# Pull in rules from info.json
122+
# Pull in rules from DD keyboard config
123123
INFO_RULES_MK = $(shell $(QMK_BIN) generate-rules-mk --quiet --escape --keyboard $(KEYBOARD) --output $(INTERMEDIATE_OUTPUT)/src/info_rules.mk)
124124
include $(INFO_RULES_MK)
125125

@@ -221,7 +221,7 @@ include $(BUILDDEFS_PATH)/converters.mk
221221
MCU_ORIG := $(MCU)
222222
include $(wildcard $(PLATFORM_PATH)/*/mcu_selection.mk)
223223

224-
# PLATFORM_KEY should be detected in info.json via key 'processor' (or rules.mk 'MCU')
224+
# PLATFORM_KEY should be detected in DD keyboard config via key 'processor' (or rules.mk 'MCU')
225225
ifeq ($(PLATFORM_KEY),)
226226
$(call CATASTROPHIC_ERROR,Platform not defined)
227227
endif
@@ -335,38 +335,54 @@ ifneq ("$(wildcard $(KEYBOARD_PATH_5)/post_config.h)","")
335335
POST_CONFIG_H += $(KEYBOARD_PATH_5)/post_config.h
336336
endif
337337

338-
# Pull in stuff from info.json
339-
INFO_JSON_FILES :=
338+
# Create dependencies on DD keyboard config - structure validated elsewhere
339+
DD_CONFIG_FILES :=
340340
ifneq ("$(wildcard $(KEYBOARD_PATH_1)/info.json)","")
341-
INFO_JSON_FILES += $(KEYBOARD_PATH_1)/info.json
341+
DD_CONFIG_FILES += $(KEYBOARD_PATH_1)/info.json
342342
endif
343343
ifneq ("$(wildcard $(KEYBOARD_PATH_2)/info.json)","")
344-
INFO_JSON_FILES += $(KEYBOARD_PATH_2)/info.json
344+
DD_CONFIG_FILES += $(KEYBOARD_PATH_2)/info.json
345345
endif
346346
ifneq ("$(wildcard $(KEYBOARD_PATH_3)/info.json)","")
347-
INFO_JSON_FILES += $(KEYBOARD_PATH_3)/info.json
347+
DD_CONFIG_FILES += $(KEYBOARD_PATH_3)/info.json
348348
endif
349349
ifneq ("$(wildcard $(KEYBOARD_PATH_4)/info.json)","")
350-
INFO_JSON_FILES += $(KEYBOARD_PATH_4)/info.json
350+
DD_CONFIG_FILES += $(KEYBOARD_PATH_4)/info.json
351351
endif
352352
ifneq ("$(wildcard $(KEYBOARD_PATH_5)/info.json)","")
353-
INFO_JSON_FILES += $(KEYBOARD_PATH_5)/info.json
353+
DD_CONFIG_FILES += $(KEYBOARD_PATH_5)/info.json
354+
endif
355+
356+
ifneq ("$(wildcard $(KEYBOARD_PATH_1)/keyboard.json)","")
357+
DD_CONFIG_FILES += $(KEYBOARD_PATH_1)/keyboard.json
358+
endif
359+
ifneq ("$(wildcard $(KEYBOARD_PATH_2)/keyboard.json)","")
360+
DD_CONFIG_FILES += $(KEYBOARD_PATH_2)/keyboard.json
361+
endif
362+
ifneq ("$(wildcard $(KEYBOARD_PATH_3)/keyboard.json)","")
363+
DD_CONFIG_FILES += $(KEYBOARD_PATH_3)/keyboard.json
364+
endif
365+
ifneq ("$(wildcard $(KEYBOARD_PATH_4)/keyboard.json)","")
366+
DD_CONFIG_FILES += $(KEYBOARD_PATH_4)/keyboard.json
367+
endif
368+
ifneq ("$(wildcard $(KEYBOARD_PATH_5)/keyboard.json)","")
369+
DD_CONFIG_FILES += $(KEYBOARD_PATH_5)/keyboard.json
354370
endif
355371

356372
CONFIG_H += $(INTERMEDIATE_OUTPUT)/src/info_config.h
357373
KEYBOARD_SRC += $(INTERMEDIATE_OUTPUT)/src/default_keyboard.c
358374

359-
$(INTERMEDIATE_OUTPUT)/src/info_config.h: $(INFO_JSON_FILES)
375+
$(INTERMEDIATE_OUTPUT)/src/info_config.h: $(DD_CONFIG_FILES)
360376
@$(SILENT) || printf "$(MSG_GENERATING) $@" | $(AWK_CMD)
361377
$(eval CMD=$(QMK_BIN) generate-config-h --quiet --keyboard $(KEYBOARD) --output $(INTERMEDIATE_OUTPUT)/src/info_config.h)
362378
@$(BUILD_CMD)
363379

364-
$(INTERMEDIATE_OUTPUT)/src/default_keyboard.c: $(INFO_JSON_FILES)
380+
$(INTERMEDIATE_OUTPUT)/src/default_keyboard.c: $(DD_CONFIG_FILES)
365381
@$(SILENT) || printf "$(MSG_GENERATING) $@" | $(AWK_CMD)
366382
$(eval CMD=$(QMK_BIN) generate-keyboard-c --quiet --keyboard $(KEYBOARD) --output $(INTERMEDIATE_OUTPUT)/src/default_keyboard.c)
367383
@$(BUILD_CMD)
368384

369-
$(INTERMEDIATE_OUTPUT)/src/default_keyboard.h: $(INFO_JSON_FILES)
385+
$(INTERMEDIATE_OUTPUT)/src/default_keyboard.h: $(DD_CONFIG_FILES)
370386
@$(SILENT) || printf "$(MSG_GENERATING) $@" | $(AWK_CMD)
371387
$(eval CMD=$(QMK_BIN) generate-keyboard-h --quiet --keyboard $(KEYBOARD) --include $(FOUND_KEYBOARD_H) --output $(INTERMEDIATE_OUTPUT)/src/default_keyboard.h)
372388
@$(BUILD_CMD)

data/templates/keyboard/config.h

-20
This file was deleted.
File renamed without changes.

data/templates/keyboard/rules.mk

-1
This file was deleted.
File renamed without changes.

keyboards/zvecr/zv48/f401/rules.mk

-3
This file was deleted.

lib/python/qmk/cli/generate/make_dependencies.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
@cli.argument('-km', '--keymap', completer=keymap_completer, help='The keymap to build a firmware for. Ignored when a configurator export is supplied.')
1919
@cli.subcommand('Generates the list of dependencies associated with a keyboard build and its generated files.', hidden=True)
2020
def generate_make_dependencies(cli):
21-
"""Generates the list of dependent info.json, rules.mk, and config.h files for a keyboard.
21+
"""Generates the list of dependent config files for a keyboard.
2222
"""
2323
interesting_files = [
2424
'info.json',
25+
'keyboard.json',
2526
'rules.mk',
2627
'post_rules.mk',
2728
'config.h',

lib/python/qmk/cli/new/keyboard.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def new_keyboard(cli):
251251

252252
# merge in infos
253253
community_info = Path(COMMUNITY / f'{default_layout}/info.json')
254-
augment_community_info(community_info, keyboard(kb_name) / community_info.name)
254+
augment_community_info(community_info, keyboard(kb_name) / 'keyboard.json')
255255

256256
cli.log.info(f'{{fg_green}}Created a new keyboard called {{fg_cyan}}{kb_name}{{fg_green}}.{{fg_reset}}')
257257
cli.log.info(f"Build Command: {{fg_yellow}}qmk compile -kb {kb_name} -km default{{fg_reset}}.")

lib/python/qmk/info.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,17 @@ def unknown_processor_rules(info_data, rules):
868868
def merge_info_jsons(keyboard, info_data):
869869
"""Return a merged copy of all the info.json files for a keyboard.
870870
"""
871-
for info_file in find_info_json(keyboard):
871+
config_files = find_info_json(keyboard)
872+
873+
# keyboard.json can only exist at the deepest part of the tree
874+
keyboard_json_count = 0
875+
for index, info_file in enumerate(config_files):
876+
if Path(info_file).name == 'keyboard.json':
877+
keyboard_json_count += 1
878+
if index != 0 or keyboard_json_count > 1:
879+
_log_error(info_data, f'Invalid keyboard.json location detected: {info_file}.')
880+
881+
for info_file in config_files:
872882
# Load and validate the JSON data
873883
new_info_data = json_load(info_file)
874884

@@ -926,7 +936,7 @@ def find_info_json(keyboard):
926936
base_path = Path('keyboards')
927937
keyboard_path = base_path / keyboard
928938
keyboard_parent = keyboard_path.parent
929-
info_jsons = [keyboard_path / 'info.json']
939+
info_jsons = [keyboard_path / 'info.json', keyboard_path / 'keyboard.json']
930940

931941
# Add DEFAULT_FOLDER before parents, if present
932942
rules = rules_mk(keyboard)
@@ -938,6 +948,7 @@ def find_info_json(keyboard):
938948
if keyboard_parent == base_path:
939949
break
940950
info_jsons.append(keyboard_parent / 'info.json')
951+
info_jsons.append(keyboard_parent / 'keyboard.json')
941952
keyboard_parent = keyboard_parent.parent
942953

943954
# Return a list of the info.json files that actually exist

lib/python/qmk/keyboard.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ def keyboard_folder_or_all(keyboard):
166166

167167

168168
def _find_name(path):
169-
"""Determine the keyboard name by stripping off the base_path and rules.mk.
169+
"""Determine the keyboard name by stripping off the base_path and filename.
170170
"""
171-
return path.replace(base_path, "").replace(os.path.sep + "rules.mk", "")
171+
return path.replace(base_path, "").rsplit(os.path.sep, 1)[0]
172172

173173

174174
def keyboard_completer(prefix, action, parser, parsed_args):
@@ -181,8 +181,10 @@ def list_keyboards(resolve_defaults=True):
181181
"""Returns a list of all keyboards - optionally processing any DEFAULT_FOLDER.
182182
"""
183183
# We avoid pathlib here because this is performance critical code.
184-
kb_wildcard = os.path.join(base_path, "**", "rules.mk")
185-
paths = [path for path in glob(kb_wildcard, recursive=True) if os.path.sep + 'keymaps' + os.path.sep not in path]
184+
paths = []
185+
for marker in ['rules.mk', 'keyboard.json']:
186+
kb_wildcard = os.path.join(base_path, "**", marker)
187+
paths += [path for path in glob(kb_wildcard, recursive=True) if os.path.sep + 'keymaps' + os.path.sep not in path]
186188

187189
found = map(_find_name, paths)
188190
if resolve_defaults:

lib/python/qmk/path.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ def is_keyboard(keyboard_name):
2323

2424
keyboard_path = QMK_FIRMWARE / 'keyboards' / keyboard_name
2525
rules_mk = keyboard_path / 'rules.mk'
26+
keyboard_json = keyboard_path / 'keyboard.json'
2627

27-
return rules_mk.exists()
28+
return rules_mk.exists() or keyboard_json.exists()
2829

2930

3031
def under_qmk_firmware(path=Path(os.environ['ORIG_CWD'])):

0 commit comments

Comments
 (0)