Allow for disabling of parallel processing of qmk find and qmk mass-compile.

This commit is contained in:
Nick Brassel 2023-09-29 10:13:54 +10:00
parent c5706ef791
commit 6c0740bb8c
No known key found for this signature in database
3 changed files with 36 additions and 18 deletions

View File

@ -15,6 +15,7 @@ from qmk.search import search_keymap_targets
) )
@cli.argument('-p', '--print', arg_only=True, action='append', default=[], help="For each matched target, print the value of the supplied info.json key. May be passed multiple times.") @cli.argument('-p', '--print', arg_only=True, action='append', default=[], help="For each matched target, print the value of the supplied info.json key. May be passed multiple times.")
@cli.argument('-km', '--keymap', type=str, default='default', help="The keymap name to build. Default is 'default'.") @cli.argument('-km', '--keymap', type=str, default='default', help="The keymap name to build. Default is 'default'.")
@cli.argument('-x', '--disable-parallel-parsing', arg_only=True, action='store_true', help="Disables parallel parsing of files, useful for debugging stalls.")
@cli.subcommand('Find builds which match supplied search criteria.') @cli.subcommand('Find builds which match supplied search criteria.')
def find(cli): def find(cli):
"""Search through all keyboards and keymaps for a given search criteria. """Search through all keyboards and keymaps for a given search criteria.
@ -23,7 +24,7 @@ def find(cli):
if len(cli.args.filter) == 0 and len(cli.args.print) > 0: if len(cli.args.filter) == 0 and len(cli.args.print) > 0:
cli.log.warning('No filters supplied -- keymaps not parsed, unable to print requested values.') cli.log.warning('No filters supplied -- keymaps not parsed, unable to print requested values.')
targets = search_keymap_targets(cli.args.keymap, cli.args.filter, cli.args.print) targets = search_keymap_targets(cli.args.keymap, cli.args.filter, cli.args.print, parallel=not cli.args.disable_parallel_parsing)
for keyboard, keymap, print_vals in targets: for keyboard, keymap, print_vals in targets:
print(f'{keyboard}:{keymap}') print(f'{keyboard}:{keymap}')

View File

@ -79,6 +79,7 @@ all: {keyboard_safe}_{keymap_name}_binary
@cli.argument('-j', '--parallel', type=int, default=1, help="Set the number of parallel make jobs; 0 means unlimited.") @cli.argument('-j', '--parallel', type=int, default=1, help="Set the number of parallel make jobs; 0 means unlimited.")
@cli.argument('-c', '--clean', arg_only=True, action='store_true', help="Remove object files before compiling.") @cli.argument('-c', '--clean', arg_only=True, action='store_true', help="Remove object files before compiling.")
@cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't actually build, just show the commands to be run.") @cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't actually build, just show the commands to be run.")
@cli.argument('-x', '--disable-parallel-parsing', arg_only=True, action='store_true', help="Disables parallel parsing of files, useful for debugging stalls.")
@cli.argument( @cli.argument(
'-f', '-f',
'--filter', '--filter',
@ -95,8 +96,8 @@ def mass_compile(cli):
"""Compile QMK Firmware against all keyboards. """Compile QMK Firmware against all keyboards.
""" """
if len(cli.args.builds) > 0: if len(cli.args.builds) > 0:
targets = search_make_targets(cli.args.builds, cli.args.filter) targets = search_make_targets(cli.args.builds, cli.args.filter, parallel=not cli.args.disable_parallel_parsing)
else: else:
targets = search_keymap_targets(cli.args.keymap, cli.args.filter) targets = search_keymap_targets(cli.args.keymap, cli.args.filter, parallel=not cli.args.disable_parallel_parsing)
return mass_compile_targets(targets, cli.args.clean, cli.args.dry_run, cli.args.no_temp, cli.args.parallel, cli.args.env) return mass_compile_targets(targets, cli.args.clean, cli.args.dry_run, cli.args.no_temp, cli.args.parallel, cli.args.env)

View File

@ -54,7 +54,7 @@ def _load_keymap_info(kb_km):
return (kb_km[0], kb_km[1], keymap_json(kb_km[0], kb_km[1])) return (kb_km[0], kb_km[1], keymap_json(kb_km[0], kb_km[1]))
def expand_make_targets(targets: List[str]) -> List[Tuple[str, str]]: def expand_make_targets(targets: List[str], parallel=True) -> List[Tuple[str, str]]:
"""Expand a list of make targets into a list of (keyboard, keymap) tuples. """Expand a list of make targets into a list of (keyboard, keymap) tuples.
Caters for 'all' in either keyboard or keymap, or both. Caters for 'all' in either keyboard or keymap, or both.
@ -66,10 +66,10 @@ def expand_make_targets(targets: List[str]) -> List[Tuple[str, str]]:
cli.log.error(f"Invalid build target: {target}") cli.log.error(f"Invalid build target: {target}")
return [] return []
split_targets.append((split_target[0], split_target[1])) split_targets.append((split_target[0], split_target[1]))
return expand_keymap_targets(split_targets) return expand_keymap_targets(split_targets, parallel)
def _expand_keymap_target(keyboard: str, keymap: str, all_keyboards: List[str] = None) -> List[Tuple[str, str]]: def _expand_keymap_target(keyboard: str, keymap: str, all_keyboards: List[str] = None, parallel=True) -> List[Tuple[str, str]]:
"""Expand a keyboard input and keymap input into a list of (keyboard, keymap) tuples. """Expand a keyboard input and keymap input into a list of (keyboard, keymap) tuples.
Caters for 'all' in either keyboard or keymap, or both. Caters for 'all' in either keyboard or keymap, or both.
@ -78,17 +78,25 @@ def _expand_keymap_target(keyboard: str, keymap: str, all_keyboards: List[str] =
all_keyboards = qmk.keyboard.list_keyboards() all_keyboards = qmk.keyboard.list_keyboards()
if keyboard == 'all': if keyboard == 'all':
with multiprocessing.Pool() as pool:
def _inner_func(pool):
_map_func = pool.imap_unordered if pool is not None else map
if keymap == 'all': if keymap == 'all':
cli.log.info('Retrieving list of all keyboards and keymaps...') cli.log.info('Retrieving list of all keyboards and keymaps...')
targets = [] targets = []
for kb in pool.imap_unordered(_all_keymaps, all_keyboards): for kb in _map_func(_all_keymaps, all_keyboards):
targets.extend(kb) targets.extend(kb)
return targets return targets
else: else:
cli.log.info(f'Retrieving list of keyboards with keymap "{keymap}"...') cli.log.info(f'Retrieving list of keyboards with keymap "{keymap}"...')
keyboard_filter = functools.partial(_keymap_exists, keymap=keymap) keyboard_filter = functools.partial(_keymap_exists, keymap=keymap)
return [(kb, keymap) for kb in filter(lambda e: e is not None, pool.imap_unordered(keyboard_filter, all_keyboards))] return [(kb, keymap) for kb in filter(lambda e: e is not None, _map_func(keyboard_filter, all_keyboards))]
if parallel:
with multiprocessing.Pool() as pool:
return _inner_func(pool)
return _inner_func(None)
else: else:
if keymap == 'all': if keymap == 'all':
keyboard = qmk.keyboard.resolve_keyboard(keyboard) keyboard = qmk.keyboard.resolve_keyboard(keyboard)
@ -98,17 +106,17 @@ def _expand_keymap_target(keyboard: str, keymap: str, all_keyboards: List[str] =
return [(qmk.keyboard.resolve_keyboard(keyboard), keymap)] return [(qmk.keyboard.resolve_keyboard(keyboard), keymap)]
def expand_keymap_targets(targets: List[Tuple[str, str]]) -> List[Tuple[str, str]]: def expand_keymap_targets(targets: List[Tuple[str, str]], parallel=True) -> List[Tuple[str, str]]:
"""Expand a list of (keyboard, keymap) tuples inclusive of 'all', into a list of explicit (keyboard, keymap) tuples. """Expand a list of (keyboard, keymap) tuples inclusive of 'all', into a list of explicit (keyboard, keymap) tuples.
""" """
overall_targets = [] overall_targets = []
all_keyboards = qmk.keyboard.list_keyboards() all_keyboards = qmk.keyboard.list_keyboards()
for target in targets: for target in targets:
overall_targets.extend(_expand_keymap_target(target[0], target[1], all_keyboards)) overall_targets.extend(_expand_keymap_target(target[0], target[1], all_keyboards, parallel))
return list(sorted(set(overall_targets))) return list(sorted(set(overall_targets)))
def _filter_keymap_targets(target_list: List[Tuple[str, str]], filters: List[str] = [], print_vals: List[str] = []) -> List[Tuple[str, str, List[Tuple[str, str]]]]: def _filter_keymap_targets(target_list: List[Tuple[str, str]], filters: List[str] = [], print_vals: List[str] = [], parallel=True) -> List[Tuple[str, str, List[Tuple[str, str]]]]:
"""Filter a list of (keyboard, keymap) tuples based on the supplied filters. """Filter a list of (keyboard, keymap) tuples based on the supplied filters.
Optionally includes the values of the queried info.json keys. Optionally includes the values of the queried info.json keys.
@ -117,8 +125,16 @@ def _filter_keymap_targets(target_list: List[Tuple[str, str]], filters: List[str
targets = [(kb, km, {}) for kb, km in target_list] targets = [(kb, km, {}) for kb, km in target_list]
else: else:
cli.log.info('Parsing data for all matching keyboard/keymap combinations...') cli.log.info('Parsing data for all matching keyboard/keymap combinations...')
def _inner_func(pool):
_map_func = pool.imap_unordered if pool is not None else map
return [(e[0], e[1], dotty(e[2])) for e in _map_func(_load_keymap_info, target_list)]
if parallel:
with multiprocessing.Pool() as pool: with multiprocessing.Pool() as pool:
valid_keymaps = [(e[0], e[1], dotty(e[2])) for e in pool.imap_unordered(_load_keymap_info, target_list)] valid_keymaps = _inner_func(pool)
else:
valid_keymaps = _inner_func(None)
function_re = re.compile(r'^(?P<function>[a-zA-Z]+)\((?P<key>[a-zA-Z0-9_\.]+)(,\s*(?P<value>[^#]+))?\)$') function_re = re.compile(r'^(?P<function>[a-zA-Z]+)\((?P<key>[a-zA-Z0-9_\.]+)(,\s*(?P<value>[^#]+))?\)$')
equals_re = re.compile(r'^(?P<key>[a-zA-Z0-9_\.]+)\s*=\s*(?P<value>[^#]+)$') equals_re = re.compile(r'^(?P<key>[a-zA-Z0-9_\.]+)\s*=\s*(?P<value>[^#]+)$')
@ -179,13 +195,13 @@ def _filter_keymap_targets(target_list: List[Tuple[str, str]], filters: List[str
return targets return targets
def search_keymap_targets(keymap='default', filters: List[str] = [], print_vals: List[str] = []) -> List[Tuple[str, str, List[Tuple[str, str]]]]: def search_keymap_targets(keymap='default', filters: List[str] = [], print_vals: List[str] = [], parallel=True) -> List[Tuple[str, str, List[Tuple[str, str]]]]:
"""Search for build targets matching the supplied criteria. """Search for build targets matching the supplied criteria.
""" """
return list(sorted(_filter_keymap_targets(expand_keymap_targets([('all', keymap)]), filters, print_vals), key=lambda e: (e[0], e[1]))) return list(sorted(_filter_keymap_targets(expand_keymap_targets([('all', keymap)], parallel), filters, print_vals, parallel), key=lambda e: (e[0], e[1])))
def search_make_targets(targets: List[str], filters: List[str] = [], print_vals: List[str] = []) -> List[Tuple[str, str, List[Tuple[str, str]]]]: def search_make_targets(targets: List[str], filters: List[str] = [], print_vals: List[str] = [], parallel=True) -> List[Tuple[str, str, List[Tuple[str, str]]]]:
"""Search for build targets matching the supplied criteria. """Search for build targets matching the supplied criteria.
""" """
return list(sorted(_filter_keymap_targets(expand_make_targets(targets), filters, print_vals), key=lambda e: (e[0], e[1]))) return list(sorted(_filter_keymap_targets(expand_make_targets(targets, parallel), filters, print_vals, parallel), key=lambda e: (e[0], e[1])))