diff options
| author | Joel Challis <git@zvecr.com> | 2025-07-17 13:36:04 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-17 13:36:04 +0100 |
| commit | 865c29f4dec268da53ccc290217c957307275a93 (patch) | |
| tree | 037983afb09e5e0960147e43503667b880f87c58 /lib/python/qmk/cli/ci/validate_aliases.py | |
| parent | 507c948ed8bb927096c6951ef75d8398fae040f9 (diff) | |
Ensure keyboard aliases do not point to themselves (#25500)
Diffstat (limited to 'lib/python/qmk/cli/ci/validate_aliases.py')
| -rw-r--r-- | lib/python/qmk/cli/ci/validate_aliases.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/python/qmk/cli/ci/validate_aliases.py b/lib/python/qmk/cli/ci/validate_aliases.py index 8b062dbe56..4f2fe6c941 100644 --- a/lib/python/qmk/cli/ci/validate_aliases.py +++ b/lib/python/qmk/cli/ci/validate_aliases.py | |||
| @@ -25,6 +25,21 @@ def _target_keyboard_exists(target): | |||
| 25 | return True | 25 | return True |
| 26 | 26 | ||
| 27 | 27 | ||
| 28 | def _alias_not_self(alias): | ||
| 29 | """Check if alias points to itself, either directly or within a circular reference | ||
| 30 | """ | ||
| 31 | aliases = keyboard_alias_definitions() | ||
| 32 | |||
| 33 | found = set() | ||
| 34 | while alias in aliases: | ||
| 35 | found.add(alias) | ||
| 36 | alias = aliases[alias].get('target', alias) | ||
| 37 | if alias in found: | ||
| 38 | return False | ||
| 39 | |||
| 40 | return True | ||
| 41 | |||
| 42 | |||
| 28 | @cli.subcommand('Validates the list of keyboard aliases.', hidden=True) | 43 | @cli.subcommand('Validates the list of keyboard aliases.', hidden=True) |
| 29 | def ci_validate_aliases(cli): | 44 | def ci_validate_aliases(cli): |
| 30 | aliases = keyboard_alias_definitions() | 45 | aliases = keyboard_alias_definitions() |
| @@ -32,7 +47,11 @@ def ci_validate_aliases(cli): | |||
| 32 | success = True | 47 | success = True |
| 33 | for alias in aliases.keys(): | 48 | for alias in aliases.keys(): |
| 34 | target = aliases[alias].get('target', None) | 49 | target = aliases[alias].get('target', None) |
| 35 | if not _target_keyboard_exists(target): | 50 | if not _alias_not_self(alias): |
| 51 | cli.log.error(f'Keyboard alias {alias} should not point to itself') | ||
| 52 | success = False | ||
| 53 | |||
| 54 | elif not _target_keyboard_exists(target): | ||
| 36 | cli.log.error(f'Keyboard alias {alias} has a target that doesn\'t exist: {target}') | 55 | cli.log.error(f'Keyboard alias {alias} has a target that doesn\'t exist: {target}') |
| 37 | success = False | 56 | success = False |
| 38 | 57 | ||
