diff options
| author | Ryan <fauxpark@gmail.com> | 2020-10-07 10:57:40 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-06 16:57:40 -0700 |
| commit | c9a06965c991a84ac76014d9791e439f88dfb957 (patch) | |
| tree | d3b3d5d4bddcc4430e841495deeaf9f75a5e86f2 /lib | |
| parent | 2c9ffd47391b8dec98db94bef9b2f5c14a57cf94 (diff) | |
| download | qmk_firmware-c9a06965c991a84ac76014d9791e439f88dfb957.tar.gz qmk_firmware-c9a06965c991a84ac76014d9791e439f88dfb957.zip | |
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>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/python/qmk/info.py | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py index de7632e37..c780a0ab2 100644 --- a/lib/python/qmk/info.py +++ b/lib/python/qmk/info.py | |||
| @@ -9,12 +9,19 @@ from milc import cli | |||
| 9 | from qmk.constants import ARM_PROCESSORS, AVR_PROCESSORS, VUSB_PROCESSORS | 9 | from qmk.constants import ARM_PROCESSORS, AVR_PROCESSORS, VUSB_PROCESSORS |
| 10 | from qmk.c_parse import find_layouts | 10 | from qmk.c_parse import find_layouts |
| 11 | from qmk.keyboard import config_h, rules_mk | 11 | from qmk.keyboard import config_h, rules_mk |
| 12 | from qmk.makefile import parse_rules_mk_file | ||
| 12 | from qmk.math import compute | 13 | from qmk.math import compute |
| 13 | 14 | ||
| 14 | 15 | ||
| 15 | def info_json(keyboard): | 16 | def info_json(keyboard): |
| 16 | """Generate the info.json data for a specific keyboard. | 17 | """Generate the info.json data for a specific keyboard. |
| 17 | """ | 18 | """ |
| 19 | cur_dir = Path('keyboards') | ||
| 20 | rules = parse_rules_mk_file(cur_dir / keyboard / 'rules.mk') | ||
| 21 | if 'DEFAULT_FOLDER' in rules: | ||
| 22 | keyboard = rules['DEFAULT_FOLDER'] | ||
| 23 | rules = parse_rules_mk_file(cur_dir / keyboard / 'rules.mk', rules) | ||
| 24 | |||
| 18 | info_data = { | 25 | info_data = { |
| 19 | 'keyboard_name': str(keyboard), | 26 | 'keyboard_name': str(keyboard), |
| 20 | 'keyboard_folder': str(keyboard), | 27 | 'keyboard_folder': str(keyboard), |
| @@ -22,7 +29,7 @@ def info_json(keyboard): | |||
| 22 | 'maintainer': 'qmk', | 29 | 'maintainer': 'qmk', |
| 23 | } | 30 | } |
| 24 | 31 | ||
| 25 | for layout_name, layout_json in _find_all_layouts(keyboard).items(): | 32 | for layout_name, layout_json in _find_all_layouts(keyboard, rules).items(): |
| 26 | if not layout_name.startswith('LAYOUT_kc'): | 33 | if not layout_name.startswith('LAYOUT_kc'): |
| 27 | info_data['layouts'][layout_name] = layout_json | 34 | info_data['layouts'][layout_name] = layout_json |
| 28 | 35 | ||
| @@ -99,22 +106,24 @@ def _extract_rules_mk(info_data): | |||
| 99 | return info_data | 106 | return info_data |
| 100 | 107 | ||
| 101 | 108 | ||
| 102 | def _find_all_layouts(keyboard): | 109 | def _search_keyboard_h(path): |
| 103 | """Looks for layout macros associated with this keyboard. | ||
| 104 | """ | ||
| 105 | layouts = {} | ||
| 106 | rules = rules_mk(keyboard) | ||
| 107 | keyboard_path = Path(rules.get('DEFAULT_FOLDER', keyboard)) | ||
| 108 | |||
| 109 | # Pull in all layouts defined in the standard files | ||
| 110 | current_path = Path('keyboards/') | 110 | current_path = Path('keyboards/') |
| 111 | for directory in keyboard_path.parts: | 111 | layouts = {} |
| 112 | for directory in path.parts: | ||
| 112 | current_path = current_path / directory | 113 | current_path = current_path / directory |
| 113 | keyboard_h = '%s.h' % (directory,) | 114 | keyboard_h = '%s.h' % (directory,) |
| 114 | keyboard_h_path = current_path / keyboard_h | 115 | keyboard_h_path = current_path / keyboard_h |
| 115 | if keyboard_h_path.exists(): | 116 | if keyboard_h_path.exists(): |
| 116 | layouts.update(find_layouts(keyboard_h_path)) | 117 | layouts.update(find_layouts(keyboard_h_path)) |
| 117 | 118 | ||
| 119 | return layouts | ||
| 120 | |||
| 121 | |||
| 122 | def _find_all_layouts(keyboard, rules): | ||
| 123 | """Looks for layout macros associated with this keyboard. | ||
| 124 | """ | ||
| 125 | layouts = _search_keyboard_h(Path(keyboard)) | ||
| 126 | |||
| 118 | if not layouts: | 127 | if not layouts: |
| 119 | # If we didn't find any layouts above we widen our search. This is error | 128 | # If we didn't find any layouts above we widen our search. This is error |
| 120 | # prone which is why we want to encourage people to follow the standard above. | 129 | # prone which is why we want to encourage people to follow the standard above. |
