diff options
Diffstat (limited to 'lib/python/qmk/cli/compile.py')
-rwxr-xr-x | lib/python/qmk/cli/compile.py | 57 |
1 files changed, 20 insertions, 37 deletions
diff --git a/lib/python/qmk/cli/compile.py b/lib/python/qmk/cli/compile.py index 95118e6687..9e7629906f 100755 --- a/lib/python/qmk/cli/compile.py +++ b/lib/python/qmk/cli/compile.py @@ -2,14 +2,13 @@ You can compile a keymap already in the repo or using a QMK Configurator export. """ -from subprocess import DEVNULL - from argcomplete.completers import FilesCompleter + from milc import cli import qmk.path from qmk.decorators import automagic_keyboard, automagic_keymap -from qmk.commands import compile_configurator_json, create_make_command, parse_configurator_json +from qmk.commands import compile_configurator_json, create_make_command, parse_configurator_json, build_environment from qmk.keyboard import keyboard_completer, keyboard_folder from qmk.keymap import keymap_completer @@ -31,48 +30,32 @@ def compile(cli): If a keyboard and keymap are provided this command will build a firmware based on that. """ - if cli.args.clean and not cli.args.filename and not cli.args.dry_run: - if cli.config.compile.keyboard and cli.config.compile.keymap: - command = create_make_command(cli.config.compile.keyboard, cli.config.compile.keymap, 'clean') - cli.run(command, capture_output=False, stdin=DEVNULL) - # 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) + envs = build_environment(cli.args.env) # Determine the compile command - command = None + commands = [] if cli.args.filename: # If a configurator JSON was provided generate a keymap and compile it user_keymap = parse_configurator_json(cli.args.filename) - command = compile_configurator_json(user_keymap, parallel=cli.config.compile.parallel, **envs) + commands = [compile_configurator_json(user_keymap, parallel=cli.config.compile.parallel, clean=cli.args.clean, **envs)] - else: - if cli.config.compile.keyboard and cli.config.compile.keymap: - # Generate the make command for a specific keyboard/keymap. - command = create_make_command(cli.config.compile.keyboard, cli.config.compile.keymap, parallel=cli.config.compile.parallel, **envs) + elif cli.config.compile.keyboard and cli.config.compile.keymap: + # Generate the make command for a specific keyboard/keymap. + if cli.args.clean: + commands.append(create_make_command(cli.config.compile.keyboard, cli.config.compile.keymap, 'clean', **envs)) + commands.append(create_make_command(cli.config.compile.keyboard, cli.config.compile.keymap, parallel=cli.config.compile.parallel, **envs)) - elif not cli.config.compile.keyboard: - cli.log.error('Could not determine keyboard!') - elif not cli.config.compile.keymap: - cli.log.error('Could not determine keymap!') - - # Compile the firmware, if we're able to - if command: - cli.log.info('Compiling keymap with {fg_cyan}%s', ' '.join(command)) - if not cli.args.dry_run: - cli.echo('\n') - # FIXME(skullydazed/anyone): Remove text=False once milc 1.0.11 has had enough time to be installed everywhere. - compile = cli.run(command, capture_output=False, text=False) - return compile.returncode - - else: + if not commands: cli.log.error('You must supply a configurator export, both `--keyboard` and `--keymap`, or be in a directory for a keyboard or keymap.') - cli.echo('usage: qmk compile [-h] [-b] [-kb KEYBOARD] [-km KEYMAP] [filename]') + cli.print_help() return False + + cli.log.info('Compiling keymap with {fg_cyan}%s', ' '.join(commands[-1])) + if not cli.args.dry_run: + cli.echo('\n') + for command in commands: + ret = cli.run(command, capture_output=False) + if ret.returncode: + return ret.returncode |