From 1283863c0e423eabfc01a4d3906cefbbf94a512c Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Sun, 19 Feb 2023 13:04:50 +1100 Subject: [PATCH] Add `mass-compile` ability to filter by key existence. (#19885) --- lib/python/qmk/cli/mass_compile.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/python/qmk/cli/mass_compile.py b/lib/python/qmk/cli/mass_compile.py index d8dda0cac34..2821a60c879 100755 --- a/lib/python/qmk/cli/mass_compile.py +++ b/lib/python/qmk/cli/mass_compile.py @@ -60,7 +60,7 @@ def _load_keymap_info(keyboard, keymap): action='append', default=[], help= # noqa: `format-python` and `pytest` don't agree here. - "Filter the list of keyboards based on the supplied value in rules.mk. Matches info.json structure, and accepts the format 'features.rgblight=true'. May be passed multiple times, all filters need to match. Value may include wildcards such as '*' and '?'." # noqa: `format-python` and `pytest` don't agree here. + "Filter the list of keyboards based on the supplied value in rules.mk. Matches info.json structure, and accepts the formats 'features.rgblight=true' or 'exists(matrix_pins.direct)'. May be passed multiple times, all filters need to match. Value may include wildcards such as '*' and '?'." # noqa: `format-python` and `pytest` don't agree here. ) @cli.argument('-km', '--keymap', type=str, default='default', help="The keymap name to build. Default is 'default'.") @cli.argument('-e', '--env', arg_only=True, action='append', default=[], help="Set a variable to be passed to make. May be passed multiple times.") @@ -95,9 +95,10 @@ def mass_compile(cli): cli.log.info('Parsing data for all matching keyboard/keymap combinations...') valid_keymaps = [(e[0], e[1], dotty(e[2])) for e in pool.starmap(_load_keymap_info, target_list)] - filter_re = re.compile(r'^(?P[a-zA-Z0-9_\.]+)\s*=\s*(?P[^#]+)$') + equals_re = re.compile(r'^(?P[a-zA-Z0-9_\.]+)\s*=\s*(?P[^#]+)$') + exists_re = re.compile(r'^exists\((?P[a-zA-Z0-9_\.]+)\)$') for filter_txt in cli.args.filter: - f = filter_re.match(filter_txt) + f = equals_re.match(filter_txt) if f is not None: key = f.group('key') value = f.group('value') @@ -116,6 +117,12 @@ def mass_compile(cli): valid_keymaps = filter(_make_filter(key, value), valid_keymaps) + f = exists_re.match(filter_txt) + if f is not None: + key = f.group('key') + cli.log.info(f'Filtering on condition (exists: "{key}")...') + valid_keymaps = filter(lambda e: e[2].get(key) is not None, valid_keymaps) + targets = [(e[0], e[1]) for e in valid_keymaps] if len(targets) == 0: