diff options
author | Zach White <skullydazed@gmail.com> | 2021-01-16 15:21:06 -0800 |
---|---|---|
committer | Zach White <skullydazed@gmail.com> | 2021-01-16 15:21:06 -0800 |
commit | 5abe66674921094c2686b98a4c0d188088e43bb3 (patch) | |
tree | e4580fa1e8b29f138e652e2db76e1c5b76646ded /lib/python/qmk/cli | |
parent | f35b1127fa3662285f37a12632be385bd84b79d3 (diff) | |
parent | d9785ec31339d7f80279fd3d1005f76689ed2f6a (diff) | |
download | qmk_firmware-5abe66674921094c2686b98a4c0d188088e43bb3.tar.gz qmk_firmware-5abe66674921094c2686b98a4c0d188088e43bb3.zip |
Merge remote-tracking branch 'origin/master' into develop
Diffstat (limited to 'lib/python/qmk/cli')
-rwxr-xr-x | lib/python/qmk/cli/compile.py | 27 | ||||
-rw-r--r-- | lib/python/qmk/cli/flash.py | 26 |
2 files changed, 43 insertions, 10 deletions
diff --git a/lib/python/qmk/cli/compile.py b/lib/python/qmk/cli/compile.py index daee597d8..322ce6a25 100755 --- a/lib/python/qmk/cli/compile.py +++ b/lib/python/qmk/cli/compile.py | |||
@@ -2,7 +2,6 @@ | |||
2 | 2 | ||
3 | You can compile a keymap already in the repo or using a QMK Configurator export. | 3 | You can compile a keymap already in the repo or using a QMK Configurator export. |
4 | """ | 4 | """ |
5 | import subprocess | ||
6 | from argparse import FileType | 5 | from argparse import FileType |
7 | 6 | ||
8 | from milc import cli | 7 | from milc import cli |
@@ -15,6 +14,9 @@ from qmk.commands import compile_configurator_json, create_make_command, parse_c | |||
15 | @cli.argument('-kb', '--keyboard', help='The keyboard to build a firmware for. Ignored when a configurator export is supplied.') | 14 | @cli.argument('-kb', '--keyboard', help='The keyboard to build a firmware for. Ignored when a configurator export is supplied.') |
16 | @cli.argument('-km', '--keymap', help='The keymap to build a firmware for. Ignored when a configurator export is supplied.') | 15 | @cli.argument('-km', '--keymap', help='The keymap to build a firmware for. Ignored when a configurator export is supplied.') |
17 | @cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't actually build, just show the make command to be run.") | 16 | @cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't actually build, just show the make command to be run.") |
17 | @cli.argument('-j', '--parallel', type=int, default=1, help="Set the number of parallel make jobs to run.") | ||
18 | @cli.argument('-e', '--env', arg_only=True, action='append', default=[], help="Set a variable to be passed to make. May be passed multiple times.") | ||
19 | @cli.argument('-c', '--clean', arg_only=True, action='store_true', help="Remove object files before compiling.") | ||
18 | @cli.subcommand('Compile a QMK Firmware.') | 20 | @cli.subcommand('Compile a QMK Firmware.') |
19 | @automagic_keyboard | 21 | @automagic_keyboard |
20 | @automagic_keymap | 22 | @automagic_keymap |
@@ -25,18 +27,32 @@ def compile(cli): | |||
25 | 27 | ||
26 | If a keyboard and keymap are provided this command will build a firmware based on that. | 28 | If a keyboard and keymap are provided this command will build a firmware based on that. |
27 | """ | 29 | """ |
30 | if cli.args.clean and not cli.args.filename and not cli.args.dry_run: | ||
31 | command = create_make_command(cli.config.compile.keyboard, cli.config.compile.keymap, 'clean') | ||
32 | # FIXME(skullydazed/anyone): Remove text=False once milc 1.0.11 has had enough time to be installed everywhere. | ||
33 | cli.run(command, capture_output=False, text=False) | ||
34 | |||
35 | # Build the environment vars | ||
36 | envs = {} | ||
37 | for env in cli.args.env: | ||
38 | if '=' in env: | ||
39 | key, value = env.split('=', 1) | ||
40 | envs[key] = value | ||
41 | else: | ||
42 | cli.log.warning('Invalid environment variable: %s', env) | ||
43 | |||
44 | # Determine the compile command | ||
28 | command = None | 45 | command = None |
29 | 46 | ||
30 | if cli.args.filename: | 47 | if cli.args.filename: |
31 | # If a configurator JSON was provided generate a keymap and compile it | 48 | # If a configurator JSON was provided generate a keymap and compile it |
32 | # FIXME(skullydazed): add code to check and warn if the keymap already exists when compiling a json keymap. | ||
33 | user_keymap = parse_configurator_json(cli.args.filename) | 49 | user_keymap = parse_configurator_json(cli.args.filename) |
34 | command = compile_configurator_json(user_keymap) | 50 | command = compile_configurator_json(user_keymap, parallel=cli.config.compile.parallel, **envs) |
35 | 51 | ||
36 | else: | 52 | else: |
37 | if cli.config.compile.keyboard and cli.config.compile.keymap: | 53 | if cli.config.compile.keyboard and cli.config.compile.keymap: |
38 | # Generate the make command for a specific keyboard/keymap. | 54 | # Generate the make command for a specific keyboard/keymap. |
39 | command = create_make_command(cli.config.compile.keyboard, cli.config.compile.keymap) | 55 | command = create_make_command(cli.config.compile.keyboard, cli.config.compile.keymap, parallel=cli.config.compile.parallel, **envs) |
40 | 56 | ||
41 | elif not cli.config.compile.keyboard: | 57 | elif not cli.config.compile.keyboard: |
42 | cli.log.error('Could not determine keyboard!') | 58 | cli.log.error('Could not determine keyboard!') |
@@ -48,7 +64,8 @@ def compile(cli): | |||
48 | cli.log.info('Compiling keymap with {fg_cyan}%s', ' '.join(command)) | 64 | cli.log.info('Compiling keymap with {fg_cyan}%s', ' '.join(command)) |
49 | if not cli.args.dry_run: | 65 | if not cli.args.dry_run: |
50 | cli.echo('\n') | 66 | cli.echo('\n') |
51 | compile = subprocess.run(command) | 67 | # FIXME(skullydazed/anyone): Remove text=False once milc 1.0.11 has had enough time to be installed everywhere. |
68 | compile = cli.run(command, capture_output=False, text=False) | ||
52 | return compile.returncode | 69 | return compile.returncode |
53 | 70 | ||
54 | else: | 71 | else: |
diff --git a/lib/python/qmk/cli/flash.py b/lib/python/qmk/cli/flash.py index d720d42e7..b3827e800 100644 --- a/lib/python/qmk/cli/flash.py +++ b/lib/python/qmk/cli/flash.py | |||
@@ -3,7 +3,6 @@ | |||
3 | You can compile a keymap already in the repo or using a QMK Configurator export. | 3 | You can compile a keymap already in the repo or using a QMK Configurator export. |
4 | A bootloader must be specified. | 4 | A bootloader must be specified. |
5 | """ | 5 | """ |
6 | import subprocess | ||
7 | from argparse import FileType | 6 | from argparse import FileType |
8 | 7 | ||
9 | from milc import cli | 8 | from milc import cli |
@@ -37,6 +36,9 @@ def print_bootloader_help(): | |||
37 | @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.') | 36 | @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.') |
38 | @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.') | 37 | @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.') |
39 | @cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't actually build, just show the make command to be run.") | 38 | @cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't actually build, just show the make command to be run.") |
39 | @cli.argument('-j', '--parallel', type=int, default=1, help="Set the number of parallel make jobs to run.") | ||
40 | @cli.argument('-e', '--env', arg_only=True, action='append', default=[], help="Set a variable to be passed to make. May be passed multiple times.") | ||
41 | @cli.argument('-c', '--clean', arg_only=True, action='store_true', help="Remove object files before compiling.") | ||
40 | @cli.subcommand('QMK Flash.') | 42 | @cli.subcommand('QMK Flash.') |
41 | @automagic_keyboard | 43 | @automagic_keyboard |
42 | @automagic_keymap | 44 | @automagic_keymap |
@@ -50,6 +52,20 @@ def flash(cli): | |||
50 | 52 | ||
51 | If bootloader is omitted the make system will use the configured bootloader for that keyboard. | 53 | If bootloader is omitted the make system will use the configured bootloader for that keyboard. |
52 | """ | 54 | """ |
55 | if cli.args.clean and not cli.args.filename and not cli.args.dry_run: | ||
56 | command = create_make_command(cli.config.flash.keyboard, cli.config.flash.keymap, 'clean') | ||
57 | cli.run(command, capture_output=False) | ||
58 | |||
59 | # Build the environment vars | ||
60 | envs = {} | ||
61 | for env in cli.args.env: | ||
62 | if '=' in env: | ||
63 | key, value = env.split('=', 1) | ||
64 | envs[key] = value | ||
65 | else: | ||
66 | cli.log.warning('Invalid environment variable: %s', env) | ||
67 | |||
68 | # Determine the compile command | ||
53 | command = '' | 69 | command = '' |
54 | 70 | ||
55 | if cli.args.bootloaders: | 71 | if cli.args.bootloaders: |
@@ -60,16 +76,16 @@ def flash(cli): | |||
60 | 76 | ||
61 | if cli.args.filename: | 77 | if cli.args.filename: |
62 | # Handle compiling a configurator JSON | 78 | # Handle compiling a configurator JSON |
63 | user_keymap = parse_configurator_json(cli.args.filename) | 79 | user_keymap = parse_configurator_json(cli.args.filename, parallel=cli.config.flash.parallel) |
64 | keymap_path = qmk.path.keymap(user_keymap['keyboard']) | 80 | keymap_path = qmk.path.keymap(user_keymap['keyboard']) |
65 | command = compile_configurator_json(user_keymap, cli.args.bootloader) | 81 | command = compile_configurator_json(user_keymap, cli.args.bootloader, **envs) |
66 | 82 | ||
67 | cli.log.info('Wrote keymap to {fg_cyan}%s/%s/keymap.c', keymap_path, user_keymap['keymap']) | 83 | cli.log.info('Wrote keymap to {fg_cyan}%s/%s/keymap.c', keymap_path, user_keymap['keymap']) |
68 | 84 | ||
69 | else: | 85 | else: |
70 | if cli.config.flash.keyboard and cli.config.flash.keymap: | 86 | if cli.config.flash.keyboard and cli.config.flash.keymap: |
71 | # Generate the make command for a specific keyboard/keymap. | 87 | # Generate the make command for a specific keyboard/keymap. |
72 | command = create_make_command(cli.config.flash.keyboard, cli.config.flash.keymap, cli.args.bootloader) | 88 | command = create_make_command(cli.config.flash.keyboard, cli.config.flash.keymap, cli.args.bootloader, parallel=cli.config.flash.parallel, **envs) |
73 | 89 | ||
74 | elif not cli.config.flash.keyboard: | 90 | elif not cli.config.flash.keyboard: |
75 | cli.log.error('Could not determine keyboard!') | 91 | cli.log.error('Could not determine keyboard!') |
@@ -81,7 +97,7 @@ def flash(cli): | |||
81 | cli.log.info('Compiling keymap with {fg_cyan}%s', ' '.join(command)) | 97 | cli.log.info('Compiling keymap with {fg_cyan}%s', ' '.join(command)) |
82 | if not cli.args.dry_run: | 98 | if not cli.args.dry_run: |
83 | cli.echo('\n') | 99 | cli.echo('\n') |
84 | compile = subprocess.run(command) | 100 | compile = cli.run(command, capture_output=False, text=True) |
85 | return compile.returncode | 101 | return compile.returncode |
86 | 102 | ||
87 | else: | 103 | else: |