aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Brassel <nick@tzarc.org>2021-05-10 01:06:44 +1000
committerGitHub <noreply@github.com>2021-05-09 17:06:44 +0200
commit1426ffc0ee64c1d6de072ffc9d7fd9d1291f4f86 (patch)
treeb23c47fd1d2c31b11f48346df090665f4cf2b098
parentf544b60aaa60eea3349eb5fbbae8ba3fd3c1b755 (diff)
downloadqmk_firmware-1426ffc0ee64c1d6de072ffc9d7fd9d1291f4f86.tar.gz
qmk_firmware-1426ffc0ee64c1d6de072ffc9d7fd9d1291f4f86.zip
Add script to perform parallel builds. (#12497)
Co-authored-by: Erovia <Erovia@users.noreply.github.com>
-rw-r--r--lib/python/qmk/cli/__init__.py1
-rwxr-xr-xlib/python/qmk/cli/info.py14
-rwxr-xr-xlib/python/qmk/cli/multibuild.py75
3 files changed, 89 insertions, 1 deletions
diff --git a/lib/python/qmk/cli/__init__.py b/lib/python/qmk/cli/__init__.py
index f7df90811..008e57f76 100644
--- a/lib/python/qmk/cli/__init__.py
+++ b/lib/python/qmk/cli/__init__.py
@@ -24,6 +24,7 @@ from . import json2c
24from . import lint 24from . import lint
25from . import list 25from . import list
26from . import kle2json 26from . import kle2json
27from . import multibuild
27from . import new 28from . import new
28from . import pyformat 29from . import pyformat
29from . import pytest 30from . import pytest
diff --git a/lib/python/qmk/cli/info.py b/lib/python/qmk/cli/info.py
index 6115e8f87..0d08d242c 100755
--- a/lib/python/qmk/cli/info.py
+++ b/lib/python/qmk/cli/info.py
@@ -10,7 +10,7 @@ from milc import cli
10from qmk.json_encoders import InfoJSONEncoder 10from qmk.json_encoders import InfoJSONEncoder
11from qmk.constants import COL_LETTERS, ROW_LETTERS 11from qmk.constants import COL_LETTERS, ROW_LETTERS
12from qmk.decorators import automagic_keyboard, automagic_keymap 12from qmk.decorators import automagic_keyboard, automagic_keymap
13from qmk.keyboard import keyboard_completer, keyboard_folder, render_layouts, render_layout 13from qmk.keyboard import keyboard_completer, keyboard_folder, render_layouts, render_layout, rules_mk
14from qmk.keymap import locate_keymap 14from qmk.keymap import locate_keymap
15from qmk.info import info_json 15from qmk.info import info_json
16from qmk.path import is_keyboard 16from qmk.path import is_keyboard
@@ -124,12 +124,20 @@ def print_text_output(kb_info_json):
124 show_keymap(kb_info_json, False) 124 show_keymap(kb_info_json, False)
125 125
126 126
127def print_parsed_rules_mk(keyboard_name):
128 rules = rules_mk(keyboard_name)
129 for k in sorted(rules.keys()):
130 print('%s = %s' % (k, rules[k]))
131 return
132
133
127@cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='Keyboard to show info for.') 134@cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='Keyboard to show info for.')
128@cli.argument('-km', '--keymap', help='Show the layers for a JSON keymap too.') 135@cli.argument('-km', '--keymap', help='Show the layers for a JSON keymap too.')
129@cli.argument('-l', '--layouts', action='store_true', help='Render the layouts.') 136@cli.argument('-l', '--layouts', action='store_true', help='Render the layouts.')
130@cli.argument('-m', '--matrix', action='store_true', help='Render the layouts with matrix information.') 137@cli.argument('-m', '--matrix', action='store_true', help='Render the layouts with matrix information.')
131@cli.argument('-f', '--format', default='friendly', arg_only=True, help='Format to display the data in (friendly, text, json) (Default: friendly).') 138@cli.argument('-f', '--format', default='friendly', arg_only=True, help='Format to display the data in (friendly, text, json) (Default: friendly).')
132@cli.argument('--ascii', action='store_true', default=not UNICODE_SUPPORT, help='Render layout box drawings in ASCII only.') 139@cli.argument('--ascii', action='store_true', default=not UNICODE_SUPPORT, help='Render layout box drawings in ASCII only.')
140@cli.argument('-r', '--rules-mk', action='store_true', help='Render the parsed values of the keyboard\'s rules.mk file.')
133@cli.subcommand('Keyboard information.') 141@cli.subcommand('Keyboard information.')
134@automagic_keyboard 142@automagic_keyboard
135@automagic_keymap 143@automagic_keymap
@@ -146,6 +154,10 @@ def info(cli):
146 cli.log.error('Invalid keyboard: "%s"', cli.config.info.keyboard) 154 cli.log.error('Invalid keyboard: "%s"', cli.config.info.keyboard)
147 return False 155 return False
148 156
157 if bool(cli.args.rules_mk):
158 print_parsed_rules_mk(cli.config.info.keyboard)
159 return False
160
149 # Build the info.json file 161 # Build the info.json file
150 kb_info_json = info_json(cli.config.info.keyboard) 162 kb_info_json = info_json(cli.config.info.keyboard)
151 163
diff --git a/lib/python/qmk/cli/multibuild.py b/lib/python/qmk/cli/multibuild.py
new file mode 100755
index 000000000..1f3a09770
--- /dev/null
+++ b/lib/python/qmk/cli/multibuild.py
@@ -0,0 +1,75 @@
1"""Compile all keyboards.
2
3This will compile everything in parallel, for testing purposes.
4"""
5import re
6from pathlib import Path
7
8from milc import cli
9
10from qmk.constants import QMK_FIRMWARE
11from qmk.commands import _find_make
12import qmk.keyboard
13
14
15def _make_rules_mk_filter(key, value):
16 def _rules_mk_filter(keyboard_name):
17 rules_mk = qmk.keyboard.rules_mk(keyboard_name)
18 return True if key in rules_mk and rules_mk[key].lower() == str(value).lower() else False
19 return _rules_mk_filter
20
21
22def _is_split(keyboard_name):
23 rules_mk = qmk.keyboard.rules_mk(keyboard_name)
24 return True if 'SPLIT_KEYBOARD' in rules_mk and rules_mk['SPLIT_KEYBOARD'].lower() == 'yes' else False
25
26
27@cli.argument('-j', '--parallel', type=int, default=1, help="Set the number of parallel make jobs to run.")
28@cli.argument('-c', '--clean', arg_only=True, action='store_true', help="Remove object files before compiling.")
29@cli.argument('-f', '--filter', arg_only=True, action='append', default=[], help="Filter the list of keyboards based on the supplied value in rules.mk. Supported format is 'SPLIT_KEYBOARD=yes'. May be passed multiple times.")
30@cli.subcommand('Compile QMK Firmware for all keyboards.', hidden=False if cli.config.user.developer else True)
31def multibuild(cli):
32 """Compile QMK Firmware against all keyboards.
33 """
34
35 make_cmd = _find_make()
36 if cli.args.clean:
37 cli.run([make_cmd, 'clean'], capture_output=False, text=False)
38
39 builddir = Path(QMK_FIRMWARE) / '.build'
40 makefile = builddir / 'parallel_kb_builds.mk'
41
42 keyboard_list = qmk.keyboard.list_keyboards()
43
44 filter_re = re.compile(r'^(?P<key>[A-Z0-9_]+)\s*=\s*(?P<value>[^#]+)$')
45 for filter_txt in cli.args.filter:
46 f = filter_re.match(filter_txt)
47 if f is not None:
48 keyboard_list = filter(_make_rules_mk_filter(f.group('key'), f.group('value')), keyboard_list)
49
50 keyboard_list = list(sorted(keyboard_list))
51
52 if len(keyboard_list) == 0:
53 return
54
55 builddir.mkdir(parents=True, exist_ok=True)
56 with open(makefile, "w") as f:
57 for keyboard_name in keyboard_list:
58 keyboard_safe = keyboard_name.replace('/', '_')
59 f.write(
60 f"""\
61all: {keyboard_safe}_binary
62{keyboard_safe}_binary:
63 @rm -f "{QMK_FIRMWARE}/.build/failed.log.{keyboard_safe}" || true
64 +@$(MAKE) -C "{QMK_FIRMWARE}" -f "{QMK_FIRMWARE}/build_keyboard.mk" KEYBOARD="{keyboard_name}" KEYMAP="default" REQUIRE_PLATFORM_KEY= COLOR=true SILENT=false \\
65 >>"{QMK_FIRMWARE}/.build/build.log.{keyboard_safe}" 2>&1 \\
66 || cp "{QMK_FIRMWARE}/.build/build.log.{keyboard_safe}" "{QMK_FIRMWARE}/.build/failed.log.{keyboard_safe}"
67 @{{ grep '\[ERRORS\]' "{QMK_FIRMWARE}/.build/build.log.{keyboard_safe}" >/dev/null 2>&1 && printf "Build %-64s \e[1;31m[ERRORS]\e[0m\\n" "{keyboard_name}:default" ; }} \\
68 || {{ grep '\[WARNINGS\]' "{QMK_FIRMWARE}/.build/build.log.{keyboard_safe}" >/dev/null 2>&1 && printf "Build %-64s \e[1;33m[WARNINGS]\e[0m\\n" "{keyboard_name}:default" ; }} \\
69 || printf "Build %-64s \e[1;32m[OK]\e[0m\\n" "{keyboard_name}:default"
70 @rm -f "{QMK_FIRMWARE}/.build/build.log.{keyboard_safe}" || true
71
72""" # noqa: yapf should not care about the formatting of the Makefile
73 )
74
75 cli.run([make_cmd, '-j', str(cli.args.parallel), '-f', makefile, 'all'], capture_output=False, text=False)