Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve LAYOUT macro searching #9530

Merged
merged 8 commits into from
Oct 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions lib/python/qmk/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,27 @@
from qmk.constants import ARM_PROCESSORS, AVR_PROCESSORS, VUSB_PROCESSORS
from qmk.c_parse import find_layouts
from qmk.keyboard import config_h, rules_mk
from qmk.makefile import parse_rules_mk_file
from qmk.math import compute


def info_json(keyboard):
"""Generate the info.json data for a specific keyboard.
"""
cur_dir = Path('keyboards')
rules = parse_rules_mk_file(cur_dir / keyboard / 'rules.mk')
if 'DEFAULT_FOLDER' in rules:
keyboard = rules['DEFAULT_FOLDER']
rules = parse_rules_mk_file(cur_dir / keyboard / 'rules.mk', rules)

info_data = {
'keyboard_name': str(keyboard),
'keyboard_folder': str(keyboard),
'layouts': {},
'maintainer': 'qmk',
}

for layout_name, layout_json in _find_all_layouts(keyboard).items():
for layout_name, layout_json in _find_all_layouts(keyboard, rules).items():
if not layout_name.startswith('LAYOUT_kc'):
info_data['layouts'][layout_name] = layout_json

Expand Down Expand Up @@ -99,22 +106,24 @@ def _extract_rules_mk(info_data):
return info_data


def _find_all_layouts(keyboard):
"""Looks for layout macros associated with this keyboard.
"""
layouts = {}
rules = rules_mk(keyboard)
keyboard_path = Path(rules.get('DEFAULT_FOLDER', keyboard))

# Pull in all layouts defined in the standard files
def _search_keyboard_h(path):
current_path = Path('keyboards/')
for directory in keyboard_path.parts:
layouts = {}
for directory in path.parts:
current_path = current_path / directory
keyboard_h = '%s.h' % (directory,)
keyboard_h_path = current_path / keyboard_h
if keyboard_h_path.exists():
layouts.update(find_layouts(keyboard_h_path))

fauxpark marked this conversation as resolved.
Show resolved Hide resolved
return layouts


def _find_all_layouts(keyboard, rules):
"""Looks for layout macros associated with this keyboard.
"""
layouts = _search_keyboard_h(Path(keyboard))

if not layouts:
# If we didn't find any layouts above we widen our search. This is error
# prone which is why we want to encourage people to follow the standard above.
Expand Down