summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2020-10-07 10:57:40 +1100
committerGitHub <noreply@github.com>2020-10-06 16:57:40 -0700
commitc9a06965c991a84ac76014d9791e439f88dfb957 (patch)
treed3b3d5d4bddcc4430e841495deeaf9f75a5e86f2
parent2c9ffd47391b8dec98db94bef9b2f5c14a57cf94 (diff)
Improve LAYOUT macro searching (#9530)
* Improve LAYOUT macro searching * Apply suggestions from code review Co-authored-by: Zach White <skullydazed@users.noreply.github.com> * Adjust signature * Try to copy the makefile's handling of DEFAULT_FOLDER * Move it further up, into `info_json()` * Move it even further up so that keyboard_folder is correct * Update lib/python/qmk/info.py Co-authored-by: Zach White <skullydazed@drpepper.org> * Update lib/python/qmk/info.py Co-authored-by: Zach White <skullydazed@drpepper.org> Co-authored-by: Zach White <skullydazed@users.noreply.github.com> Co-authored-by: Zach White <skullydazed@drpepper.org>
-rw-r--r--lib/python/qmk/info.py29
1 files changed, 19 insertions, 10 deletions
diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py
index de7632e378..c780a0ab23 100644
--- a/lib/python/qmk/info.py
+++ b/lib/python/qmk/info.py
@@ -9,12 +9,19 @@ from milc import cli
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),
@@ -22,7 +29,7 @@ def info_json(keyboard):
'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
@@ -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))
+ 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.