Resolve keyboard_aliases when processing keyboard make targets (#24834)

This commit is contained in:
Joel Challis 2025-01-29 19:22:05 +00:00 committed by GitHub
parent db68fd88bd
commit 0c14fc3a21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 41 additions and 12 deletions

View File

@ -113,6 +113,29 @@ endef
# Make it easier to call TRY_TO_MATCH_RULE_FROM_LIST
TRY_TO_MATCH_RULE_FROM_LIST = $(eval $(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER,$1))$(RULE_FOUND)
# As TRY_TO_MATCH_RULE_FROM_LIST_HELPER, but with additional
# resolution of DEFAULT_FOLDER and keyboard_aliases.hjson for provided rule
define TRY_TO_MATCH_RULE_FROM_LIST_HELPER_KB
# Split on ":", padding with empty strings to avoid indexing issues
TOKEN1:=$$(shell python3 -c "import sys; print((sys.argv[1].split(':',1)+[''])[0])" $$(RULE))
TOKENr:=$$(shell python3 -c "import sys; print((sys.argv[1].split(':',1)+[''])[1])" $$(RULE))
TOKEN1:=$$(shell $(QMK_BIN) resolve-alias --allow-unknown $$(TOKEN1))
FOUNDx:=$$(shell echo $1 | tr " " "\n" | grep -Fx $$(TOKEN1))
ifneq ($$(FOUNDx),)
RULE := $$(TOKENr)
RULE_FOUND := true
MATCHED_ITEM := $$(TOKEN1)
else
RULE_FOUND := false
MATCHED_ITEM :=
endif
endef
# Make it easier to call TRY_TO_MATCH_RULE_FROM_LIST_KB
TRY_TO_MATCH_RULE_FROM_LIST_KB = $(eval $(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER_KB,$1))$(RULE_FOUND)
define ALL_IN_LIST_LOOP
OLD_RULE$1 := $$(RULE)
$$(eval $$(call $1,$$(ITEM$1)))
@ -138,7 +161,7 @@ define PARSE_RULE
$$(eval $$(call PARSE_TEST))
# If the rule starts with the name of a known keyboard, then continue
# the parsing from PARSE_KEYBOARD
else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(shell $(QMK_BIN) list-keyboards --no-resolve-defaults)),true)
else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST_KB,$$(shell $(QMK_BIN) list-keyboards)),true)
KEYBOARD_RULE=$$(MATCHED_ITEM)
$$(eval $$(call PARSE_KEYBOARD,$$(MATCHED_ITEM)))
else
@ -170,17 +193,6 @@ define PARSE_KEYBOARD
# include the correct makefile to determine the actual name of it
CURRENT_KB := $1
# KEYBOARD_FOLDERS := $$(subst /, , $(CURRENT_KB))
DEFAULT_FOLDER := $$(CURRENT_KB)
# We assume that every rules.mk will contain the full default value
$$(eval include $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/rules.mk)
ifneq ($$(DEFAULT_FOLDER),$$(CURRENT_KB))
$$(eval include $(ROOT_DIR)/keyboards/$$(DEFAULT_FOLDER)/rules.mk)
endif
CURRENT_KB := $$(DEFAULT_FOLDER)
# 5/4/3/2/1
KEYBOARD_FOLDER_PATH_1 := $$(CURRENT_KB)
KEYBOARD_FOLDER_PATH_2 := $$(patsubst %/,%,$$(dir $$(KEYBOARD_FOLDER_PATH_1)))

View File

@ -82,6 +82,7 @@ subcommands = [
'qmk.cli.new.keymap',
'qmk.cli.painter',
'qmk.cli.pytest',
'qmk.cli.resolve_alias',
'qmk.cli.test.c',
'qmk.cli.userspace.add',
'qmk.cli.userspace.compile',

View File

@ -0,0 +1,16 @@
from qmk.keyboard import keyboard_folder
from milc import cli
@cli.argument('--allow-unknown', arg_only=True, action='store_true', help="Return original if rule is not a valid keyboard.")
@cli.argument('keyboard', arg_only=True, help='The keyboard\'s name')
@cli.subcommand('Resolve DEFAULT_FOLDER and any keyboard_aliases for provided rule')
def resolve_alias(cli):
try:
print(keyboard_folder(cli.args.keyboard))
except ValueError:
if cli.args.allow_unknown:
print(cli.args.keyboard)
else:
raise