1
0
Fork 0

Defer the expensive search for layout macros until info.json has been processed (#14007)

* defer the expensive search for layout macros until info.json has been processed

* fixup names
This commit is contained in:
Zach White 2021-08-15 13:30:58 -07:00 committed by GitHub
parent f56c202fb3
commit fd340f8957
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -49,7 +49,7 @@ def info_json(keyboard):
info_data['keymaps'][keymap.name] = {'url': f'https://raw.githubusercontent.com/qmk/qmk_firmware/master/{keymap}/keymap.json'} info_data['keymaps'][keymap.name] = {'url': f'https://raw.githubusercontent.com/qmk/qmk_firmware/master/{keymap}/keymap.json'}
# Populate layout data # Populate layout data
layouts, aliases = _find_all_layouts(info_data, keyboard) layouts, aliases = _search_keyboard_h(keyboard)
if aliases: if aliases:
info_data['layout_aliases'] = aliases info_data['layout_aliases'] = aliases
@ -77,6 +77,9 @@ def info_json(keyboard):
exit(1) exit(1)
# Make sure we have at least one layout # Make sure we have at least one layout
if not info_data.get('layouts'):
_find_missing_layouts(info_data, keyboard)
if not info_data.get('layouts'): if not info_data.get('layouts'):
_log_error(info_data, 'No LAYOUTs defined! Need at least one layout defined in the keyboard.h or info.json.') _log_error(info_data, 'No LAYOUTs defined! Need at least one layout defined in the keyboard.h or info.json.')
@ -417,12 +420,13 @@ def _merge_layouts(info_data, new_info_data):
return info_data return info_data
def _search_keyboard_h(path): def _search_keyboard_h(keyboard):
keyboard = Path(keyboard)
current_path = Path('keyboards/') current_path = Path('keyboards/')
aliases = {} aliases = {}
layouts = {} layouts = {}
for directory in path.parts: for directory in keyboard.parts:
current_path = current_path / directory current_path = current_path / directory
keyboard_h = '%s.h' % (directory,) keyboard_h = '%s.h' % (directory,)
keyboard_h_path = current_path / keyboard_h keyboard_h_path = current_path / keyboard_h
@ -437,27 +441,28 @@ def _search_keyboard_h(path):
return layouts, aliases return layouts, aliases
def _find_all_layouts(info_data, keyboard): def _find_missing_layouts(info_data, keyboard):
"""Looks for layout macros associated with this keyboard. """Looks for layout macros when they aren't found other places.
"""
layouts, aliases = _search_keyboard_h(Path(keyboard))
if not layouts: If we don't find any layouts from info.json or keyboard.h we widen our search. This is error prone which is why we want to encourage people to follow the standard above.
# If we don't find any layouts from info.json or keyboard.h we widen our search. This is error prone which is why we want to encourage people to follow the standard above. """
info_data['parse_warnings'].append('%s: Falling back to searching for KEYMAP/LAYOUT macros.' % (keyboard)) _log_warning(info_data, '%s: Falling back to searching for KEYMAP/LAYOUT macros.' % (keyboard))
for file in glob('keyboards/%s/*.h' % keyboard): for file in glob('keyboards/%s/*.h' % keyboard):
if file.endswith('.h'):
these_layouts, these_aliases = find_layouts(file) these_layouts, these_aliases = find_layouts(file)
if these_layouts: if these_layouts:
layouts.update(these_layouts) for layout_name, layout_json in these_layouts.items():
if not layout_name.startswith('LAYOUT_kc'):
layout_json['c_macro'] = True
info_data['layouts'][layout_name] = layout_json
for alias, alias_text in these_aliases.items(): for alias, alias_text in these_aliases.items():
if alias_text in layouts: if alias_text in these_layouts:
aliases[alias] = alias_text if 'layout_aliases' not in info_data:
info_data['layout_aliases'] = {}
return layouts, aliases info_data['layout_aliases'][alias] = alias_text
def _log_error(info_data, message): def _log_error(info_data, message):