From a5fd4fd83e198a7ff067d8f32cafa64d37afa7be Mon Sep 17 00:00:00 2001 From: zvecr Date: Sat, 10 Aug 2024 14:38:17 +0100 Subject: [PATCH] Resolve alias within Makefile --- Makefile | 21 ++++++++++++++++++++- keyboards/kprepublic/jj40/rules.mk | 1 - lib/python/qmk/cli/__init__.py | 1 + lib/python/qmk/cli/resolve_alias.py | 8 ++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) delete mode 100644 keyboards/kprepublic/jj40/rules.mk create mode 100644 lib/python/qmk/cli/resolve_alias.py diff --git a/Makefile b/Makefile index 92d1ef61832..389b7b6595a 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/keyboards/kprepublic/jj40/rules.mk b/keyboards/kprepublic/jj40/rules.mk deleted file mode 100644 index fa09523958c..00000000000 --- a/keyboards/kprepublic/jj40/rules.mk +++ /dev/null @@ -1 +0,0 @@ -DEFAULT_FOLDER = kprepublic/jj40/rev1 diff --git a/lib/python/qmk/cli/__init__.py b/lib/python/qmk/cli/__init__.py index 0baf19a629d..293af1c0538 100644 --- a/lib/python/qmk/cli/__init__.py +++ b/lib/python/qmk/cli/__init__.py @@ -31,6 +31,7 @@ safe_commands = [ ] subcommands = [ + 'qmk.cli.resolve_alias', 'qmk.cli.ci.validate_aliases', 'qmk.cli.bux', 'qmk.cli.c2json', diff --git a/lib/python/qmk/cli/resolve_alias.py b/lib/python/qmk/cli/resolve_alias.py new file mode 100644 index 00000000000..60edca93eed --- /dev/null +++ b/lib/python/qmk/cli/resolve_alias.py @@ -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))