keyboard stuff
1# Copyright 2023-2024 Nick Brassel (@tzarc)
2# SPDX-License-Identifier: GPL-2.0-or-later
3from pathlib import Path
4from milc import cli
5
6from qmk.constants import QMK_USERSPACE, HAS_QMK_USERSPACE
7from qmk.commands import build_environment
8from qmk.userspace import UserspaceDefs
9from qmk.build_targets import JsonKeymapBuildTarget
10from qmk.search import search_keymap_targets
11from qmk.cli.mass_compile import mass_compile_targets
12from qmk.util import maybe_exit_config
13
14
15def _extra_arg_setter(target, extra_args):
16 target.extra_args = extra_args
17
18
19@cli.argument('-t', '--no-temp', arg_only=True, action='store_true', help="Remove temporary files during build.")
20@cli.argument('-j', '--parallel', type=int, default=1, help="Set the number of parallel make jobs; 0 means unlimited.")
21@cli.argument('-c', '--clean', arg_only=True, action='store_true', help="Remove object files before compiling.")
22@cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't actually build, just show the commands to be run.")
23@cli.argument('-p', '--print-failures', arg_only=True, action='store_true', help="Print failed builds.")
24@cli.argument('-e', '--env', arg_only=True, action='append', default=[], help="Set a variable to be passed to make. May be passed multiple times.")
25@cli.subcommand('Compiles the build targets specified in userspace `qmk.json`.')
26def userspace_compile(cli):
27 if not HAS_QMK_USERSPACE:
28 cli.log.error('Could not determine QMK userspace location. Please run `qmk doctor` or `qmk userspace-doctor` to diagnose.')
29 return False
30
31 maybe_exit_config(should_exit=False, should_reraise=True)
32
33 userspace = UserspaceDefs(QMK_USERSPACE / 'qmk.json')
34
35 build_targets = []
36 keyboard_keymap_targets = []
37 for e in userspace.build_targets:
38 if isinstance(e, Path):
39 build_targets.append(JsonKeymapBuildTarget(e))
40 elif isinstance(e, dict):
41 f = e['env'] if 'env' in e else None
42 keyboard_keymap_targets.append((e['keyboard'], e['keymap'], f))
43 if len(keyboard_keymap_targets) > 0:
44 build_targets.extend(search_keymap_targets(keyboard_keymap_targets))
45
46 return mass_compile_targets(list(set(build_targets)), cli.args.clean, cli.args.dry_run, cli.config.userspace_compile.no_temp, cli.config.userspace_compile.parallel, cli.args.print_failures, **build_environment(cli.args.env))