summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorQMK Bot <hello@qmk.fm>2023-10-05 23:35:02 +0000
committerQMK Bot <hello@qmk.fm>2023-10-05 23:35:02 +0000
commit0ca60eb759d567878024eaabc613d6193f560745 (patch)
tree7ddbd6335f67a067a02053b041186aecef2cbfad /lib
parenta7406a429eb726731fe2a69e284282994dc9cd0c (diff)
parent127560ae223255d0e081b932e902d2da242abf06 (diff)
Merge remote-tracking branch 'origin/master' into develop
Diffstat (limited to 'lib')
-rw-r--r--lib/python/qmk/cli/__init__.py1
-rw-r--r--lib/python/qmk/cli/ci/__init__.py0
-rw-r--r--lib/python/qmk/cli/ci/validate_aliases.py46
-rw-r--r--lib/python/qmk/commands.py11
-rw-r--r--lib/python/qmk/keyboard.py5
5 files changed, 58 insertions, 5 deletions
diff --git a/lib/python/qmk/cli/__init__.py b/lib/python/qmk/cli/__init__.py
index 9c3decf4f7..b8bc99aa0d 100644
--- a/lib/python/qmk/cli/__init__.py
+++ b/lib/python/qmk/cli/__init__.py
@@ -31,6 +31,7 @@ safe_commands = [
]
subcommands = [
+ 'qmk.cli.ci.validate_aliases',
'qmk.cli.bux',
'qmk.cli.c2json',
'qmk.cli.cd',
diff --git a/lib/python/qmk/cli/ci/__init__.py b/lib/python/qmk/cli/ci/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/lib/python/qmk/cli/ci/__init__.py
diff --git a/lib/python/qmk/cli/ci/validate_aliases.py b/lib/python/qmk/cli/ci/validate_aliases.py
new file mode 100644
index 0000000000..a205d03cff
--- /dev/null
+++ b/lib/python/qmk/cli/ci/validate_aliases.py
@@ -0,0 +1,46 @@
+"""Validates the list of keyboard aliases.
+"""
+from pathlib import Path
+
+from milc import cli
+
+from qmk.json_schema import json_load
+from qmk.keyboard import resolve_keyboard, keyboard_folder
+
+
+def _safe_keyboard_folder(target):
+ try:
+ return keyboard_folder(target) # throws ValueError if it's invalid
+ except Exception:
+ return None
+
+
+def _target_keyboard_exists(target):
+ # If there's no target, then we can't build it.
+ 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
+
+ # As far as we can tell, we can build it!
+ return True
+
+
+@cli.subcommand('Validates the list of keyboard aliases.', hidden=True)
+def ci_validate_aliases(cli):
+ aliases = json_load(Path('data/mappings/keyboard_aliases.hjson'))
+
+ success = True
+ for alias in aliases.keys():
+ target = aliases[alias].get('target', None)
+ if not _target_keyboard_exists(target):
+ cli.log.error(f'Keyboard alias {alias} has a target that doesn\'t exist: {target}')
+ success = False
+
+ return success
diff --git a/lib/python/qmk/commands.py b/lib/python/qmk/commands.py
index 660b2ff72e..34696e3793 100644
--- a/lib/python/qmk/commands.py
+++ b/lib/python/qmk/commands.py
@@ -212,13 +212,16 @@ def parse_configurator_json(configurator_file):
cli.log.error(f'Invalid JSON keymap: {configurator_file} : {e.message}')
exit(1)
- orig_keyboard = user_keymap['keyboard']
+ keyboard = user_keymap['keyboard']
aliases = json_load(Path('data/mappings/keyboard_aliases.hjson'))
- if orig_keyboard in aliases:
- if 'target' in aliases[orig_keyboard]:
- user_keymap['keyboard'] = aliases[orig_keyboard]['target']
+ while keyboard in aliases:
+ last_keyboard = keyboard
+ keyboard = aliases[keyboard].get('target', keyboard)
+ if keyboard == last_keyboard:
+ break
+ user_keymap['keyboard'] = keyboard
return user_keymap
diff --git a/lib/python/qmk/keyboard.py b/lib/python/qmk/keyboard.py
index 18ca5a9534..9826f3f887 100644
--- a/lib/python/qmk/keyboard.py
+++ b/lib/python/qmk/keyboard.py
@@ -92,8 +92,11 @@ def keyboard_folder(keyboard):
"""
aliases = json_load(Path('data/mappings/keyboard_aliases.hjson'))
- if keyboard in aliases:
+ while keyboard in aliases:
+ last_keyboard = keyboard
keyboard = aliases[keyboard].get('target', keyboard)
+ if keyboard == last_keyboard:
+ break
rules_mk_file = Path(base_path, keyboard, 'rules.mk')