diff options
Diffstat (limited to 'lib/python/qmk')
| -rw-r--r-- | lib/python/qmk/cli/clean.py | 8 | ||||
| -rw-r--r-- | lib/python/qmk/commands.py | 34 |
2 files changed, 30 insertions, 12 deletions
diff --git a/lib/python/qmk/cli/clean.py b/lib/python/qmk/cli/clean.py index ec6501b76..9096529fd 100644 --- a/lib/python/qmk/cli/clean.py +++ b/lib/python/qmk/cli/clean.py | |||
| @@ -1,16 +1,12 @@ | |||
| 1 | """Clean the QMK firmware folder of build artifacts. | 1 | """Clean the QMK firmware folder of build artifacts. |
| 2 | """ | 2 | """ |
| 3 | from qmk.commands import run | 3 | from qmk.commands import run, create_make_target |
| 4 | from milc import cli | 4 | from milc import cli |
| 5 | 5 | ||
| 6 | import shutil | ||
| 7 | |||
| 8 | 6 | ||
| 9 | @cli.argument('-a', '--all', arg_only=True, action='store_true', help='Remove *.hex and *.bin files in the QMK root as well.') | 7 | @cli.argument('-a', '--all', arg_only=True, action='store_true', help='Remove *.hex and *.bin files in the QMK root as well.') |
| 10 | @cli.subcommand('Clean the QMK firmware folder of build artifacts.') | 8 | @cli.subcommand('Clean the QMK firmware folder of build artifacts.') |
| 11 | def clean(cli): | 9 | def clean(cli): |
| 12 | """Runs `make clean` (or `make distclean` if --all is passed) | 10 | """Runs `make clean` (or `make distclean` if --all is passed) |
| 13 | """ | 11 | """ |
| 14 | make_cmd = 'gmake' if shutil.which('gmake') else 'make' | 12 | run(create_make_target('distclean' if cli.args.all else 'clean')) |
| 15 | |||
| 16 | run([make_cmd, 'distclean' if cli.args.all else 'clean']) | ||
diff --git a/lib/python/qmk/commands.py b/lib/python/qmk/commands.py index d742f6756..97774001a 100644 --- a/lib/python/qmk/commands.py +++ b/lib/python/qmk/commands.py | |||
| @@ -29,6 +29,33 @@ def _find_make(): | |||
| 29 | return make_cmd | 29 | return make_cmd |
| 30 | 30 | ||
| 31 | 31 | ||
| 32 | def create_make_target(target, parallel=1, **env_vars): | ||
| 33 | """Create a make command | ||
| 34 | |||
| 35 | Args: | ||
| 36 | |||
| 37 | target | ||
| 38 | Usually a make rule, such as 'clean' or 'all'. | ||
| 39 | |||
| 40 | parallel | ||
| 41 | The number of make jobs to run in parallel | ||
| 42 | |||
| 43 | **env_vars | ||
| 44 | Environment variables to be passed to make. | ||
| 45 | |||
| 46 | Returns: | ||
| 47 | |||
| 48 | A command that can be run to make the specified keyboard and keymap | ||
| 49 | """ | ||
| 50 | env = [] | ||
| 51 | make_cmd = _find_make() | ||
| 52 | |||
| 53 | for key, value in env_vars.items(): | ||
| 54 | env.append(f'{key}={value}') | ||
| 55 | |||
| 56 | return [make_cmd, '-j', str(parallel), *env, target] | ||
| 57 | |||
| 58 | |||
| 32 | def create_make_command(keyboard, keymap, target=None, parallel=1, **env_vars): | 59 | def create_make_command(keyboard, keymap, target=None, parallel=1, **env_vars): |
| 33 | """Create a make compile command | 60 | """Create a make compile command |
| 34 | 61 | ||
| @@ -53,17 +80,12 @@ def create_make_command(keyboard, keymap, target=None, parallel=1, **env_vars): | |||
| 53 | 80 | ||
| 54 | A command that can be run to make the specified keyboard and keymap | 81 | A command that can be run to make the specified keyboard and keymap |
| 55 | """ | 82 | """ |
| 56 | env = [] | ||
| 57 | make_args = [keyboard, keymap] | 83 | make_args = [keyboard, keymap] |
| 58 | make_cmd = _find_make() | ||
| 59 | 84 | ||
| 60 | if target: | 85 | if target: |
| 61 | make_args.append(target) | 86 | make_args.append(target) |
| 62 | 87 | ||
| 63 | for key, value in env_vars.items(): | 88 | return create_make_target(':'.join(make_args), parallel, **env_vars) |
| 64 | env.append(f'{key}={value}') | ||
| 65 | |||
| 66 | return [make_cmd, '-j', str(parallel), *env, ':'.join(make_args)] | ||
| 67 | 89 | ||
| 68 | 90 | ||
| 69 | def get_git_version(repo_dir='.', check_dir='.'): | 91 | def get_git_version(repo_dir='.', check_dir='.'): |
