Resolve alias within Makefile

This commit is contained in:
zvecr 2024-08-10 14:38:17 +01:00
parent af1f965c82
commit a5fd4fd83e
4 changed files with 29 additions and 2 deletions

View File

@ -110,8 +110,27 @@ define TRY_TO_MATCH_RULE_FROM_LIST_HELPER
endif
endef
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 $$(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
TRY_TO_MATCH_RULE_FROM_LIST = $(eval $(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER,$1))$(RULE_FOUND)
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)
@ -138,7 +157,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)),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

View File

@ -1 +0,0 @@
DEFAULT_FOLDER = kprepublic/jj40/rev1

View File

@ -31,6 +31,7 @@ safe_commands = [
]
subcommands = [
'qmk.cli.resolve_alias',
'qmk.cli.ci.validate_aliases',
'qmk.cli.bux',
'qmk.cli.c2json',

View File

@ -0,0 +1,8 @@
from qmk.keyboard import keyboard_folder
from milc import cli
@cli.argument('keyboard', arg_only=True, help='TODO.')
@cli.subcommand('TODO')
def resolve_alias(cli):
print(keyboard_folder(cli.args.keyboard))