aboutsummaryrefslogtreecommitdiff
path: root/lib/python
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2021-05-09 11:57:49 +0100
committerGitHub <noreply@github.com>2021-05-09 12:57:49 +0200
commit7725d813c9cf1a47863e325457b13a4542984eda (patch)
tree4b51c7e3b6c10328467207bfe4683c3bcff78526 /lib/python
parent60a39f4f5d192625ea03daf8cd26bc89aa1a91c2 (diff)
downloadqmk_firmware-7725d813c9cf1a47863e325457b13a4542984eda.tar.gz
qmk_firmware-7725d813c9cf1a47863e325457b13a4542984eda.zip
Allow MAKE environment override for 'qmk clean' (#12473)
Diffstat (limited to 'lib/python')
-rw-r--r--lib/python/qmk/cli/clean.py8
-rw-r--r--lib/python/qmk/commands.py34
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"""
3from qmk.commands import run 3from qmk.commands import run, create_make_target
4from milc import cli 4from milc import cli
5 5
6import 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.')
11def clean(cli): 9def 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
32def 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
32def create_make_command(keyboard, keymap, target=None, parallel=1, **env_vars): 59def 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
69def get_git_version(repo_dir='.', check_dir='.'): 91def get_git_version(repo_dir='.', check_dir='.'):