logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

validate_aliases.py (1329B)


  1. """Validates the list of keyboard aliases.
  2. """
  3. from milc import cli
  4. from qmk.keyboard import resolve_keyboard, keyboard_folder, keyboard_alias_definitions
  5. def _safe_keyboard_folder(target):
  6. try:
  7. return keyboard_folder(target) # throws ValueError if it's invalid
  8. except Exception:
  9. return None
  10. def _target_keyboard_exists(target):
  11. # If there's no target, then we can't build it.
  12. if not target:
  13. return False
  14. # If the target directory existed but there was no rules.mk or rules.mk was incorrectly parsed, then we can't build it.
  15. if not resolve_keyboard(target):
  16. return False
  17. # If the target directory exists but it itself has an invalid alias or invalid rules.mk, then we can't build it either.
  18. if not _safe_keyboard_folder(target):
  19. return False
  20. # As far as we can tell, we can build it!
  21. return True
  22. @cli.subcommand('Validates the list of keyboard aliases.', hidden=True)
  23. def ci_validate_aliases(cli):
  24. aliases = keyboard_alias_definitions()
  25. success = True
  26. for alias in aliases.keys():
  27. target = aliases[alias].get('target', None)
  28. if not _target_keyboard_exists(target):
  29. cli.log.error(f'Keyboard alias {alias} has a target that doesn\'t exist: {target}')
  30. success = False
  31. return success