mirror of
https://github.com/qmk/qmk_firmware.git
synced 2024-11-24 20:32:58 +00:00
Merge a5fd4fd83e
into d189de24a0
This commit is contained in:
commit
a01416c4d6
36
Makefile
36
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 --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
|
||||
@ -172,15 +191,6 @@ define PARSE_KEYBOARD
|
||||
|
||||
# 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)))
|
||||
@ -242,7 +252,7 @@ endef
|
||||
# if we are going to compile all keyboards, match the rest of the rule
|
||||
# for each of them
|
||||
define PARSE_ALL_KEYBOARDS
|
||||
$$(eval $$(call PARSE_ALL_IN_LIST,PARSE_KEYBOARD,$(shell $(QMK_BIN) list-keyboards --no-resolve-defaults)))
|
||||
$$(eval $$(call PARSE_ALL_IN_LIST,PARSE_KEYBOARD,$(shell $(QMK_BIN) list-keyboards)))
|
||||
endef
|
||||
|
||||
# Prints a list of all known keymaps for the given keyboard
|
||||
@ -434,7 +444,7 @@ git-submodules: git-submodule
|
||||
|
||||
.PHONY: list-keyboards
|
||||
list-keyboards:
|
||||
$(QMK_BIN) list-keyboards --no-resolve-defaults | tr '\n' ' '
|
||||
$(QMK_BIN) list-keyboards | tr '\n' ' '
|
||||
|
||||
.PHONY: list-tests
|
||||
list-tests:
|
||||
@ -442,7 +452,7 @@ list-tests:
|
||||
|
||||
.PHONY: generate-keyboards-file
|
||||
generate-keyboards-file:
|
||||
$(QMK_BIN) list-keyboards --no-resolve-defaults
|
||||
$(QMK_BIN) list-keyboards
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
|
@ -55,5 +55,6 @@
|
||||
// Items we want flagged in lint
|
||||
"CTPC": {"info_key": "_deprecated.ctpc", "deprecated": true, "replace_with": "CONVERT_TO=proton_c"},
|
||||
"CONVERT_TO_PROTON_C": {"info_key": "_deprecated.ctpc", "deprecated": true, "replace_with": "CONVERT_TO=proton_c"},
|
||||
"DEFAULT_FOLDER": {"info_key": "_deprecated.default_folder", "deprecated": true}
|
||||
"VIAL_ENABLE": {"info_key": "_invalid.vial", "invalid": true}
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
DEFAULT_FOLDER = kprepublic/jj40/rev1
|
@ -31,6 +31,7 @@ safe_commands = [
|
||||
]
|
||||
|
||||
subcommands = [
|
||||
'qmk.cli.resolve_alias',
|
||||
'qmk.cli.ci.validate_aliases',
|
||||
'qmk.cli.bux',
|
||||
'qmk.cli.c2json',
|
||||
|
@ -2,7 +2,7 @@
|
||||
"""
|
||||
from milc import cli
|
||||
|
||||
from qmk.keyboard import resolve_keyboard, keyboard_folder, keyboard_alias_definitions
|
||||
from qmk.keyboard import keyboard_folder, keyboard_alias_definitions
|
||||
|
||||
|
||||
def _safe_keyboard_folder(target):
|
||||
@ -17,10 +17,6 @@ def _target_keyboard_exists(target):
|
||||
if not target:
|
||||
return False
|
||||
|
||||
# If the target directory existed but there was no rules.mk or rules.mk was incorrectly parsed, then we can't build it.
|
||||
if not resolve_keyboard(target):
|
||||
return False
|
||||
|
||||
# If the target directory exists but it itself has an invalid alias or invalid rules.mk, then we can't build it either.
|
||||
if not _safe_keyboard_folder(target):
|
||||
return False
|
||||
|
@ -5,10 +5,9 @@ from milc import cli
|
||||
import qmk.keyboard
|
||||
|
||||
|
||||
@cli.argument('--no-resolve-defaults', arg_only=True, action='store_false', help='Ignore any "DEFAULT_FOLDER" within keyboards rules.mk')
|
||||
@cli.subcommand("List the keyboards currently defined within QMK")
|
||||
def list_keyboards(cli):
|
||||
"""List the keyboards currently defined within QMK
|
||||
"""
|
||||
for keyboard_name in qmk.keyboard.list_keyboards(cli.args.no_resolve_defaults):
|
||||
for keyboard_name in qmk.keyboard.list_keyboards():
|
||||
print(keyboard_name)
|
||||
|
@ -6,14 +6,14 @@ from dotty_dict import dotty
|
||||
|
||||
from milc import cli
|
||||
|
||||
from qmk.keyboard import keyboard_completer, keyboard_folder, resolve_keyboard
|
||||
from qmk.keyboard import keyboard_completer, keyboard_folder
|
||||
from qmk.info import info_json, find_info_json
|
||||
from qmk.json_encoders import InfoJSONEncoder
|
||||
from qmk.json_schema import json_load
|
||||
|
||||
|
||||
def _candidate_files(keyboard):
|
||||
kb_dir = Path(resolve_keyboard(keyboard))
|
||||
kb_dir = Path(keyboard)
|
||||
|
||||
cur_dir = Path('keyboards')
|
||||
files = []
|
||||
|
8
lib/python/qmk/cli/resolve_alias.py
Normal file
8
lib/python/qmk/cli/resolve_alias.py
Normal 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))
|
@ -216,12 +216,6 @@ def _validate(keyboard, info_data):
|
||||
def info_json(keyboard, force_layout=None):
|
||||
"""Generate the info.json data for a specific keyboard.
|
||||
"""
|
||||
cur_dir = Path('keyboards')
|
||||
root_rules_mk = parse_rules_mk_file(cur_dir / keyboard / 'rules.mk')
|
||||
|
||||
if 'DEFAULT_FOLDER' in root_rules_mk:
|
||||
keyboard = root_rules_mk['DEFAULT_FOLDER']
|
||||
|
||||
info_data = {
|
||||
'keyboard_name': str(keyboard),
|
||||
'keyboard_folder': str(keyboard),
|
||||
@ -997,11 +991,6 @@ def find_info_json(keyboard):
|
||||
keyboard_parent = keyboard_path.parent
|
||||
info_jsons = [keyboard_path / 'info.json', keyboard_path / 'keyboard.json']
|
||||
|
||||
# Add DEFAULT_FOLDER before parents, if present
|
||||
rules = rules_mk(keyboard)
|
||||
if 'DEFAULT_FOLDER' in rules:
|
||||
info_jsons.append(Path(rules['DEFAULT_FOLDER']) / 'info.json')
|
||||
|
||||
# Add in parent folders for least specific
|
||||
for _ in range(5):
|
||||
if keyboard_parent == base_path:
|
||||
|
@ -72,7 +72,15 @@ base_path = os.path.join(os.getcwd(), "keyboards") + os.path.sep
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def keyboard_alias_definitions():
|
||||
return json_load(Path('data/mappings/keyboard_aliases.hjson'))
|
||||
data = json_load(Path('data/mappings/keyboard_aliases.hjson'))
|
||||
|
||||
# Add fake entries to maintain DEFAULT_FOLDER logic for CLI
|
||||
for kb in list_keyboards(False):
|
||||
res = _resolve_keyboard(kb)
|
||||
if res != kb:
|
||||
data[kb] = {'target': res}
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def is_all_keyboards(keyboard):
|
||||
@ -131,8 +139,6 @@ def keyboard_folder(keyboard):
|
||||
if keyboard == last_keyboard:
|
||||
break
|
||||
|
||||
keyboard = resolve_keyboard(keyboard)
|
||||
|
||||
if not qmk.path.is_keyboard(keyboard):
|
||||
raise ValueError(f'Invalid keyboard: {keyboard}')
|
||||
|
||||
@ -144,7 +150,7 @@ def keyboard_aliases(keyboard):
|
||||
|
||||
Includes the keyboard itself.
|
||||
"""
|
||||
aliases = json_load(Path('data/mappings/keyboard_aliases.hjson'))
|
||||
aliases = keyboard_alias_definitions()
|
||||
|
||||
if keyboard in aliases:
|
||||
keyboard = aliases[keyboard].get('target', keyboard)
|
||||
@ -190,13 +196,13 @@ def list_keyboards(resolve_defaults=True):
|
||||
|
||||
found = map(_find_name, paths)
|
||||
if resolve_defaults:
|
||||
found = map(resolve_keyboard, found)
|
||||
found = map(_resolve_keyboard, found)
|
||||
|
||||
return sorted(set(found))
|
||||
|
||||
|
||||
@lru_cache(maxsize=None)
|
||||
def resolve_keyboard(keyboard):
|
||||
def _resolve_keyboard(keyboard):
|
||||
cur_dir = Path('keyboards')
|
||||
rules = parse_rules_mk_file(cur_dir / keyboard / 'rules.mk')
|
||||
while 'DEFAULT_FOLDER' in rules and keyboard != rules['DEFAULT_FOLDER']:
|
||||
@ -216,7 +222,7 @@ def config_h(keyboard):
|
||||
"""
|
||||
config = {}
|
||||
cur_dir = Path('keyboards')
|
||||
keyboard = Path(resolve_keyboard(keyboard))
|
||||
keyboard = Path(keyboard)
|
||||
|
||||
for dir in keyboard.parts:
|
||||
cur_dir = cur_dir / dir
|
||||
@ -235,7 +241,7 @@ def rules_mk(keyboard):
|
||||
a dictionary representing the content of the entire rules.mk tree for a keyboard
|
||||
"""
|
||||
cur_dir = Path('keyboards')
|
||||
keyboard = Path(resolve_keyboard(keyboard))
|
||||
keyboard = Path(keyboard)
|
||||
rules = parse_rules_mk_file(cur_dir / keyboard / 'rules.mk')
|
||||
|
||||
for i, dir in enumerate(keyboard.parts):
|
||||
|
Loading…
Reference in New Issue
Block a user