diff options
Diffstat (limited to 'lib/python/qmk/info.py')
-rw-r--r-- | lib/python/qmk/info.py | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py index e92c3335b..d73ba8cfb 100644 --- a/lib/python/qmk/info.py +++ b/lib/python/qmk/info.py | |||
@@ -28,6 +28,8 @@ def info_json(keyboard): | |||
28 | 'keyboard_folder': str(keyboard), | 28 | 'keyboard_folder': str(keyboard), |
29 | 'keymaps': {}, | 29 | 'keymaps': {}, |
30 | 'layouts': {}, | 30 | 'layouts': {}, |
31 | 'parse_errors': [], | ||
32 | 'parse_warnings': [], | ||
31 | 'maintainer': 'qmk', | 33 | 'maintainer': 'qmk', |
32 | } | 34 | } |
33 | 35 | ||
@@ -36,7 +38,7 @@ def info_json(keyboard): | |||
36 | info_data['keymaps'][keymap.name] = {'url': f'https://raw.githubusercontent.com/qmk/qmk_firmware/master/{keymap}/keymap.json'} | 38 | info_data['keymaps'][keymap.name] = {'url': f'https://raw.githubusercontent.com/qmk/qmk_firmware/master/{keymap}/keymap.json'} |
37 | 39 | ||
38 | # Populate layout data | 40 | # Populate layout data |
39 | for layout_name, layout_json in _find_all_layouts(keyboard, rules).items(): | 41 | for layout_name, layout_json in _find_all_layouts(info_data, keyboard, rules).items(): |
40 | if not layout_name.startswith('LAYOUT_kc'): | 42 | if not layout_name.startswith('LAYOUT_kc'): |
41 | info_data['layouts'][layout_name] = layout_json | 43 | info_data['layouts'][layout_name] = layout_json |
42 | 44 | ||
@@ -104,14 +106,16 @@ def _extract_rules_mk(info_data): | |||
104 | mcu = rules.get('MCU') | 106 | mcu = rules.get('MCU') |
105 | 107 | ||
106 | if mcu in CHIBIOS_PROCESSORS: | 108 | if mcu in CHIBIOS_PROCESSORS: |
107 | arm_processor_rules(info_data, rules) | 109 | return arm_processor_rules(info_data, rules) |
110 | |||
108 | elif mcu in LUFA_PROCESSORS + VUSB_PROCESSORS: | 111 | elif mcu in LUFA_PROCESSORS + VUSB_PROCESSORS: |
109 | avr_processor_rules(info_data, rules) | 112 | return avr_processor_rules(info_data, rules) |
110 | else: | ||
111 | cli.log.warning("%s: Unknown MCU: %s" % (info_data['keyboard_folder'], mcu)) | ||
112 | unknown_processor_rules(info_data, rules) | ||
113 | 113 | ||
114 | return info_data | 114 | msg = "Unknown MCU: " + str(mcu) |
115 | |||
116 | _log_warning(info_data, msg) | ||
117 | |||
118 | return unknown_processor_rules(info_data, rules) | ||
115 | 119 | ||
116 | 120 | ||
117 | def _search_keyboard_h(path): | 121 | def _search_keyboard_h(path): |
@@ -127,7 +131,7 @@ def _search_keyboard_h(path): | |||
127 | return layouts | 131 | return layouts |
128 | 132 | ||
129 | 133 | ||
130 | def _find_all_layouts(keyboard, rules): | 134 | def _find_all_layouts(info_data, keyboard, rules): |
131 | """Looks for layout macros associated with this keyboard. | 135 | """Looks for layout macros associated with this keyboard. |
132 | """ | 136 | """ |
133 | layouts = _search_keyboard_h(Path(keyboard)) | 137 | layouts = _search_keyboard_h(Path(keyboard)) |
@@ -135,7 +139,7 @@ def _find_all_layouts(keyboard, rules): | |||
135 | if not layouts: | 139 | if not layouts: |
136 | # If we didn't find any layouts above we widen our search. This is error | 140 | # If we didn't find any layouts above we widen our search. This is error |
137 | # prone which is why we want to encourage people to follow the standard above. | 141 | # prone which is why we want to encourage people to follow the standard above. |
138 | cli.log.warning('%s: Falling back to searching for KEYMAP/LAYOUT macros.' % (keyboard)) | 142 | _log_warning(info_data, 'Falling back to searching for KEYMAP/LAYOUT macros.') |
139 | for file in glob('keyboards/%s/*.h' % keyboard): | 143 | for file in glob('keyboards/%s/*.h' % keyboard): |
140 | if file.endswith('.h'): | 144 | if file.endswith('.h'): |
141 | these_layouts = find_layouts(file) | 145 | these_layouts = find_layouts(file) |
@@ -153,11 +157,25 @@ def _find_all_layouts(keyboard, rules): | |||
153 | supported_layouts.remove(layout_name) | 157 | supported_layouts.remove(layout_name) |
154 | 158 | ||
155 | if supported_layouts: | 159 | if supported_layouts: |
156 | cli.log.error('%s: Missing LAYOUT() macro for %s' % (keyboard, ', '.join(supported_layouts))) | 160 | _log_error(info_data, 'Missing LAYOUT() macro for %s' % (', '.join(supported_layouts))) |
157 | 161 | ||
158 | return layouts | 162 | return layouts |
159 | 163 | ||
160 | 164 | ||
165 | def _log_error(info_data, message): | ||
166 | """Send an error message to both JSON and the log. | ||
167 | """ | ||
168 | info_data['parse_errors'].append(message) | ||
169 | cli.log.error('%s: %s', info_data.get('keyboard_folder', 'Unknown Keyboard!'), message) | ||
170 | |||
171 | |||
172 | def _log_warning(info_data, message): | ||
173 | """Send a warning message to both JSON and the log. | ||
174 | """ | ||
175 | info_data['parse_warnings'].append(message) | ||
176 | cli.log.warning('%s: %s', info_data.get('keyboard_folder', 'Unknown Keyboard!'), message) | ||
177 | |||
178 | |||
161 | def arm_processor_rules(info_data, rules): | 179 | def arm_processor_rules(info_data, rules): |
162 | """Setup the default info for an ARM board. | 180 | """Setup the default info for an ARM board. |
163 | """ | 181 | """ |
@@ -216,7 +234,7 @@ def merge_info_jsons(keyboard, info_data): | |||
216 | new_info_data = json.load(info_fd) | 234 | new_info_data = json.load(info_fd) |
217 | 235 | ||
218 | if not isinstance(new_info_data, dict): | 236 | if not isinstance(new_info_data, dict): |
219 | cli.log.error("Invalid file %s, root object should be a dictionary.", str(info_file)) | 237 | _log_error(info_data, "Invalid file %s, root object should be a dictionary.", str(info_file)) |
220 | continue | 238 | continue |
221 | 239 | ||
222 | # Copy whitelisted keys into `info_data` | 240 | # Copy whitelisted keys into `info_data` |
@@ -230,7 +248,8 @@ def merge_info_jsons(keyboard, info_data): | |||
230 | # Only pull in layouts we have a macro for | 248 | # Only pull in layouts we have a macro for |
231 | if layout_name in info_data['layouts']: | 249 | if layout_name in info_data['layouts']: |
232 | if info_data['layouts'][layout_name]['key_count'] != len(json_layout['layout']): | 250 | if info_data['layouts'][layout_name]['key_count'] != len(json_layout['layout']): |
233 | cli.log.error('%s: %s: Number of elements in info.json does not match! info.json:%s != %s:%s', info_data['keyboard_folder'], layout_name, len(json_layout['layout']), layout_name, len(info_data['layouts'][layout_name]['layout'])) | 251 | msg = '%s: Number of elements in info.json does not match! info.json:%s != %s:%s' |
252 | _log_error(info_data, msg % (layout_name, len(json_layout['layout']), layout_name, len(info_data['layouts'][layout_name]['layout']))) | ||
234 | else: | 253 | else: |
235 | for i, key in enumerate(info_data['layouts'][layout_name]['layout']): | 254 | for i, key in enumerate(info_data['layouts'][layout_name]['layout']): |
236 | key.update(json_layout['layout'][i]) | 255 | key.update(json_layout['layout'][i]) |