summaryrefslogtreecommitdiff
path: root/lib/python/qmk/cli/flash.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/qmk/cli/flash.py')
-rw-r--r--lib/python/qmk/cli/flash.py26
1 files changed, 21 insertions, 5 deletions
diff --git a/lib/python/qmk/cli/flash.py b/lib/python/qmk/cli/flash.py
index d720d42e71..b3827e8003 100644
--- a/lib/python/qmk/cli/flash.py
+++ b/lib/python/qmk/cli/flash.py
@@ -3,7 +3,6 @@
You can compile a keymap already in the repo or using a QMK Configurator export.
A bootloader must be specified.
"""
-import subprocess
from argparse import FileType
from milc import cli
@@ -37,6 +36,9 @@ def print_bootloader_help():
@cli.argument('-km', '--keymap', help='The keymap to build a firmware for. Use this if you dont have a configurator file. Ignored when a configurator file is supplied.')
@cli.argument('-kb', '--keyboard', help='The keyboard to build a firmware for. Use this if you dont have a configurator file. Ignored when a configurator file is supplied.')
@cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't actually build, just show the make command to be run.")
+@cli.argument('-j', '--parallel', type=int, default=1, help="Set the number of parallel make jobs to run.")
+@cli.argument('-e', '--env', arg_only=True, action='append', default=[], help="Set a variable to be passed to make. May be passed multiple times.")
+@cli.argument('-c', '--clean', arg_only=True, action='store_true', help="Remove object files before compiling.")
@cli.subcommand('QMK Flash.')
@automagic_keyboard
@automagic_keymap
@@ -50,6 +52,20 @@ def flash(cli):
If bootloader is omitted the make system will use the configured bootloader for that keyboard.
"""
+ if cli.args.clean and not cli.args.filename and not cli.args.dry_run:
+ command = create_make_command(cli.config.flash.keyboard, cli.config.flash.keymap, 'clean')
+ cli.run(command, capture_output=False)
+
+ # Build the environment vars
+ envs = {}
+ for env in cli.args.env:
+ if '=' in env:
+ key, value = env.split('=', 1)
+ envs[key] = value
+ else:
+ cli.log.warning('Invalid environment variable: %s', env)
+
+ # Determine the compile command
command = ''
if cli.args.bootloaders:
@@ -60,16 +76,16 @@ def flash(cli):
if cli.args.filename:
# Handle compiling a configurator JSON
- user_keymap = parse_configurator_json(cli.args.filename)
+ user_keymap = parse_configurator_json(cli.args.filename, parallel=cli.config.flash.parallel)
keymap_path = qmk.path.keymap(user_keymap['keyboard'])
- command = compile_configurator_json(user_keymap, cli.args.bootloader)
+ command = compile_configurator_json(user_keymap, cli.args.bootloader, **envs)
cli.log.info('Wrote keymap to {fg_cyan}%s/%s/keymap.c', keymap_path, user_keymap['keymap'])
else:
if cli.config.flash.keyboard and cli.config.flash.keymap:
# Generate the make command for a specific keyboard/keymap.
- command = create_make_command(cli.config.flash.keyboard, cli.config.flash.keymap, cli.args.bootloader)
+ command = create_make_command(cli.config.flash.keyboard, cli.config.flash.keymap, cli.args.bootloader, parallel=cli.config.flash.parallel, **envs)
elif not cli.config.flash.keyboard:
cli.log.error('Could not determine keyboard!')
@@ -81,7 +97,7 @@ def flash(cli):
cli.log.info('Compiling keymap with {fg_cyan}%s', ' '.join(command))
if not cli.args.dry_run:
cli.echo('\n')
- compile = subprocess.run(command)
+ compile = cli.run(command, capture_output=False, text=True)
return compile.returncode
else: