diff options
| author | ruro <ruro.ruro@ya.ru> | 2021-08-18 01:46:59 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-18 08:46:59 +1000 |
| commit | 3b28178deb7a42a2df8c19b9bf190bb5da732b33 (patch) | |
| tree | bbffcc4752948a0f5a52c31930f3ada863e67f44 | |
| parent | 999391f3ae6bab3fe1784d0f53bffd0320a9e076 (diff) | |
| download | qmk_firmware-3b28178deb7a42a2df8c19b9bf190bb5da732b33.tar.gz qmk_firmware-3b28178deb7a42a2df8c19b9bf190bb5da732b33.zip | |
`--parallel` improvements (#13800)
* improve make parallel jobs support
* document the --parallel option
* disable the output-sync for interactive targets
| -rw-r--r-- | docs/cli_commands.md | 17 | ||||
| -rwxr-xr-x | lib/python/qmk/cli/compile.py | 2 | ||||
| -rw-r--r-- | lib/python/qmk/cli/flash.py | 2 | ||||
| -rwxr-xr-x | lib/python/qmk/cli/multibuild.py | 6 | ||||
| -rw-r--r-- | lib/python/qmk/commands.py | 23 | ||||
| -rw-r--r-- | message.mk | 4 | ||||
| -rw-r--r-- | platforms/arm_atsam/flash.mk | 2 | ||||
| -rw-r--r-- | platforms/avr/flash.mk | 14 | ||||
| -rw-r--r-- | platforms/chibios/flash.mk | 10 |
9 files changed, 56 insertions, 24 deletions
diff --git a/docs/cli_commands.md b/docs/cli_commands.md index c7468eb5e..8fa7ad41d 100644 --- a/docs/cli_commands.md +++ b/docs/cli_commands.md | |||
| @@ -17,7 +17,7 @@ qmk compile [-c] <configuratorExport.json> | |||
| 17 | **Usage for Keymaps**: | 17 | **Usage for Keymaps**: |
| 18 | 18 | ||
| 19 | ``` | 19 | ``` |
| 20 | qmk compile [-c] [-e <var>=<value>] -kb <keyboard_name> -km <keymap_name> | 20 | qmk compile [-c] [-e <var>=<value>] [-j <num_jobs>] -kb <keyboard_name> -km <keymap_name> |
| 21 | ``` | 21 | ``` |
| 22 | 22 | ||
| 23 | **Usage in Keyboard Directory**: | 23 | **Usage in Keyboard Directory**: |
| @@ -73,6 +73,17 @@ $ qmk compile -kb dz60 | |||
| 73 | ... | 73 | ... |
| 74 | ``` | 74 | ``` |
| 75 | 75 | ||
| 76 | **Parallel Compilation**: | ||
| 77 | |||
| 78 | It is possible to speed up compilation by adding the `-j`/`--parallel` flag. | ||
| 79 | ``` | ||
| 80 | qmk compile -j <num_jobs> -kb <keyboard_name> | ||
| 81 | ``` | ||
| 82 | The `num_jobs` argument determines the maximum number of jobs that can be used. Setting it to zero will enable parallel compilation without limiting the maximum number of jobs. | ||
| 83 | ``` | ||
| 84 | qmk compile -j 0 -kb <keyboard_name> | ||
| 85 | ``` | ||
| 86 | |||
| 76 | ## `qmk flash` | 87 | ## `qmk flash` |
| 77 | 88 | ||
| 78 | This command is similar to `qmk compile`, but can also target a bootloader. The bootloader is optional, and is set to `:flash` by default. To specify a different bootloader, use `-bl <bootloader>`. Visit the [Flashing Firmware](flashing.md) guide for more details of the available bootloaders. | 89 | This command is similar to `qmk compile`, but can also target a bootloader. The bootloader is optional, and is set to `:flash` by default. To specify a different bootloader, use `-bl <bootloader>`. Visit the [Flashing Firmware](flashing.md) guide for more details of the available bootloaders. |
| @@ -82,13 +93,13 @@ This command is directory aware. It will automatically fill in KEYBOARD and/or K | |||
| 82 | **Usage for Configurator Exports**: | 93 | **Usage for Configurator Exports**: |
| 83 | 94 | ||
| 84 | ``` | 95 | ``` |
| 85 | qmk flash [-bl <bootloader>] [-c] [-e <var>=<value>] <configuratorExport.json> | 96 | qmk flash [-bl <bootloader>] [-c] [-e <var>=<value>] [-j <num_jobs>] <configuratorExport.json> |
| 86 | ``` | 97 | ``` |
| 87 | 98 | ||
| 88 | **Usage for Keymaps**: | 99 | **Usage for Keymaps**: |
| 89 | 100 | ||
| 90 | ``` | 101 | ``` |
| 91 | qmk flash -kb <keyboard_name> -km <keymap_name> [-bl <bootloader>] [-c] [-e <var>=<value>] | 102 | qmk flash -kb <keyboard_name> -km <keymap_name> [-bl <bootloader>] [-c] [-e <var>=<value>] [-j <num_jobs>] |
| 92 | ``` | 103 | ``` |
| 93 | 104 | ||
| 94 | **Listing the Bootloaders** | 105 | **Listing the Bootloaders** |
diff --git a/lib/python/qmk/cli/compile.py b/lib/python/qmk/cli/compile.py index 7a45e7721..acbd77864 100755 --- a/lib/python/qmk/cli/compile.py +++ b/lib/python/qmk/cli/compile.py | |||
| @@ -18,7 +18,7 @@ from qmk.keymap import keymap_completer | |||
| 18 | @cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='The keyboard to build a firmware for. Ignored when a configurator export is supplied.') | 18 | @cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='The keyboard to build a firmware for. Ignored when a configurator export is supplied.') |
| 19 | @cli.argument('-km', '--keymap', completer=keymap_completer, help='The keymap to build a firmware for. Ignored when a configurator export is supplied.') | 19 | @cli.argument('-km', '--keymap', completer=keymap_completer, help='The keymap to build a firmware for. Ignored when a configurator export is supplied.') |
| 20 | @cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't actually build, just show the make command to be run.") | 20 | @cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't actually build, just show the make command to be run.") |
| 21 | @cli.argument('-j', '--parallel', type=int, default=1, help="Set the number of parallel make jobs to run.") | 21 | @cli.argument('-j', '--parallel', type=int, default=1, help="Set the number of parallel make jobs; 0 means unlimited.") |
| 22 | @cli.argument('-e', '--env', arg_only=True, action='append', default=[], help="Set a variable to be passed to make. May be passed multiple times.") | 22 | @cli.argument('-e', '--env', arg_only=True, action='append', default=[], help="Set a variable to be passed to make. May be passed multiple times.") |
| 23 | @cli.argument('-c', '--clean', arg_only=True, action='store_true', help="Remove object files before compiling.") | 23 | @cli.argument('-c', '--clean', arg_only=True, action='store_true', help="Remove object files before compiling.") |
| 24 | @cli.subcommand('Compile a QMK Firmware.') | 24 | @cli.subcommand('Compile a QMK Firmware.') |
diff --git a/lib/python/qmk/cli/flash.py b/lib/python/qmk/cli/flash.py index 1b2932a5b..c2d9e09c6 100644 --- a/lib/python/qmk/cli/flash.py +++ b/lib/python/qmk/cli/flash.py | |||
| @@ -38,7 +38,7 @@ def print_bootloader_help(): | |||
| 38 | @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('-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.') |
| 39 | @cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, 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('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='The keyboard to build a firmware for. Use this if you dont have a configurator file. Ignored when a configurator file is supplied.') |
| 40 | @cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't actually build, just show the make command to be run.") | 40 | @cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't actually build, just show the make command to be run.") |
| 41 | @cli.argument('-j', '--parallel', type=int, default=1, help="Set the number of parallel make jobs to run.") | 41 | @cli.argument('-j', '--parallel', type=int, default=1, help="Set the number of parallel make jobs; 0 means unlimited.") |
| 42 | @cli.argument('-e', '--env', arg_only=True, action='append', default=[], help="Set a variable to be passed to make. May be passed multiple times.") | 42 | @cli.argument('-e', '--env', arg_only=True, action='append', default=[], help="Set a variable to be passed to make. May be passed multiple times.") |
| 43 | @cli.argument('-c', '--clean', arg_only=True, action='store_true', help="Remove object files before compiling.") | 43 | @cli.argument('-c', '--clean', arg_only=True, action='store_true', help="Remove object files before compiling.") |
| 44 | @cli.subcommand('QMK Flash.') | 44 | @cli.subcommand('QMK Flash.') |
diff --git a/lib/python/qmk/cli/multibuild.py b/lib/python/qmk/cli/multibuild.py index bdb0b493c..85ed0fa1e 100755 --- a/lib/python/qmk/cli/multibuild.py +++ b/lib/python/qmk/cli/multibuild.py | |||
| @@ -10,7 +10,7 @@ from subprocess import DEVNULL | |||
| 10 | from milc import cli | 10 | from milc import cli |
| 11 | 11 | ||
| 12 | from qmk.constants import QMK_FIRMWARE | 12 | from qmk.constants import QMK_FIRMWARE |
| 13 | from qmk.commands import _find_make | 13 | from qmk.commands import _find_make, get_make_parallel_args |
| 14 | import qmk.keyboard | 14 | import qmk.keyboard |
| 15 | import qmk.keymap | 15 | import qmk.keymap |
| 16 | 16 | ||
| @@ -28,7 +28,7 @@ def _is_split(keyboard_name): | |||
| 28 | return True if 'SPLIT_KEYBOARD' in rules_mk and rules_mk['SPLIT_KEYBOARD'].lower() == 'yes' else False | 28 | return True if 'SPLIT_KEYBOARD' in rules_mk and rules_mk['SPLIT_KEYBOARD'].lower() == 'yes' else False |
| 29 | 29 | ||
| 30 | 30 | ||
| 31 | @cli.argument('-j', '--parallel', type=int, default=1, help="Set the number of parallel make jobs to run.") | 31 | @cli.argument('-j', '--parallel', type=int, default=1, help="Set the number of parallel make jobs; 0 means unlimited.") |
| 32 | @cli.argument('-c', '--clean', arg_only=True, action='store_true', help="Remove object files before compiling.") | 32 | @cli.argument('-c', '--clean', arg_only=True, action='store_true', help="Remove object files before compiling.") |
| 33 | @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.") | 33 | @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.") |
| 34 | @cli.argument('-km', '--keymap', type=str, default='default', help="The keymap name to build. Default is 'default'.") | 34 | @cli.argument('-km', '--keymap', type=str, default='default', help="The keymap name to build. Default is 'default'.") |
| @@ -80,7 +80,7 @@ all: {keyboard_safe}_binary | |||
| 80 | ) | 80 | ) |
| 81 | # yapf: enable | 81 | # yapf: enable |
| 82 | 82 | ||
| 83 | cli.run([make_cmd, '-j', str(cli.args.parallel), '-f', makefile.as_posix(), 'all'], capture_output=False, stdin=DEVNULL) | 83 | cli.run([make_cmd, *get_make_parallel_args(cli.args.parallel), '-f', makefile.as_posix(), 'all'], capture_output=False, stdin=DEVNULL) |
| 84 | 84 | ||
| 85 | # Check for failures | 85 | # Check for failures |
| 86 | failures = [f for f in builddir.glob(f'failed.log.{os.getpid()}.*')] | 86 | failures = [f for f in builddir.glob(f'failed.log.{os.getpid()}.*')] |
diff --git a/lib/python/qmk/commands.py b/lib/python/qmk/commands.py index 8c66228b2..421453d83 100644 --- a/lib/python/qmk/commands.py +++ b/lib/python/qmk/commands.py | |||
| @@ -52,7 +52,7 @@ def create_make_target(target, parallel=1, **env_vars): | |||
| 52 | for key, value in env_vars.items(): | 52 | for key, value in env_vars.items(): |
| 53 | env.append(f'{key}={value}') | 53 | env.append(f'{key}={value}') |
| 54 | 54 | ||
| 55 | return [make_cmd, '-j', str(parallel), *env, target] | 55 | return [make_cmd, *get_make_parallel_args(parallel), *env, target] |
| 56 | 56 | ||
| 57 | 57 | ||
| 58 | def create_make_command(keyboard, keymap, target=None, parallel=1, **env_vars): | 58 | def create_make_command(keyboard, keymap, target=None, parallel=1, **env_vars): |
| @@ -112,6 +112,24 @@ def get_git_version(current_time, repo_dir='.', check_dir='.'): | |||
| 112 | return current_time | 112 | return current_time |
| 113 | 113 | ||
| 114 | 114 | ||
| 115 | def get_make_parallel_args(parallel=1): | ||
| 116 | """Returns the arguments for running the specified number of parallel jobs. | ||
| 117 | """ | ||
| 118 | parallel_args = [] | ||
| 119 | |||
| 120 | if int(parallel) <= 0: | ||
| 121 | # 0 or -1 means -j without argument (unlimited jobs) | ||
| 122 | parallel_args.append('--jobs') | ||
| 123 | else: | ||
| 124 | parallel_args.append('--jobs=' + str(parallel)) | ||
| 125 | |||
| 126 | if int(parallel) != 1: | ||
| 127 | # If more than 1 job is used, synchronize parallel output by target | ||
| 128 | parallel_args.append('--output-sync=target') | ||
| 129 | |||
| 130 | return parallel_args | ||
| 131 | |||
| 132 | |||
| 115 | def create_version_h(skip_git=False, skip_all=False): | 133 | def create_version_h(skip_git=False, skip_all=False): |
| 116 | """Generate version.h contents | 134 | """Generate version.h contents |
| 117 | """ | 135 | """ |
| @@ -185,8 +203,7 @@ def compile_configurator_json(user_keymap, bootloader=None, parallel=1, **env_va | |||
| 185 | make_command.append('-s') | 203 | make_command.append('-s') |
| 186 | 204 | ||
| 187 | make_command.extend([ | 205 | make_command.extend([ |
| 188 | '-j', | 206 | *get_make_parallel_args(parallel), |
| 189 | str(parallel), | ||
| 190 | '-r', | 207 | '-r', |
| 191 | '-R', | 208 | '-R', |
| 192 | '-f', | 209 | '-f', |
diff --git a/message.mk b/message.mk index dcd47e550..419e3f5f3 100644 --- a/message.mk +++ b/message.mk | |||
| @@ -36,6 +36,10 @@ PRINT_OK = $(SILENT) || printf " $(OK_STRING)" | $(AWK_STATUS) | |||
| 36 | BUILD_CMD = LOG=$$($(CMD) 2>&1) ; if [ $$? -gt 0 ]; then $(PRINT_ERROR); elif [ "$$LOG" != "" ] ; then $(PRINT_WARNING); else $(PRINT_OK); fi; | 36 | BUILD_CMD = LOG=$$($(CMD) 2>&1) ; if [ $$? -gt 0 ]; then $(PRINT_ERROR); elif [ "$$LOG" != "" ] ; then $(PRINT_WARNING); else $(PRINT_OK); fi; |
| 37 | MAKE_MSG_FORMAT = $(AWK) '{ printf "%-118s", $$0;}' | 37 | MAKE_MSG_FORMAT = $(AWK) '{ printf "%-118s", $$0;}' |
| 38 | 38 | ||
| 39 | # The UNSYNC_OUTPUT_CMD command disables the `--output-sync` for the current command, if the `--output-sync` granularity is `target` or lower. | ||
| 40 | # This is achieved by telling make to treat the current command as if it invokes a recursive make subcommand (as if by calling `$(MAKE)`). | ||
| 41 | UNSYNC_OUTPUT_CMD = +true | ||
| 42 | |||
| 39 | # Define Messages | 43 | # Define Messages |
| 40 | # English | 44 | # English |
| 41 | MSG_ERRORS_NONE = Errors: none | 45 | MSG_ERRORS_NONE = Errors: none |
diff --git a/platforms/arm_atsam/flash.mk b/platforms/arm_atsam/flash.mk index 444ba77f5..f31d4b4d9 100644 --- a/platforms/arm_atsam/flash.mk +++ b/platforms/arm_atsam/flash.mk | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | 5 | ||
| 6 | flash: bin | 6 | flash: bin |
| 7 | ifneq ($(strip $(PROGRAM_CMD)),) | 7 | ifneq ($(strip $(PROGRAM_CMD)),) |
| 8 | $(PROGRAM_CMD) | 8 | $(UNSYNC_OUTPUT_CMD) && $(PROGRAM_CMD) |
| 9 | else | 9 | else |
| 10 | $(PRINT_OK); $(SILENT) || printf "$(MSG_FLASH_ARCH)" | 10 | $(PRINT_OK); $(SILENT) || printf "$(MSG_FLASH_ARCH)" |
| 11 | endif | 11 | endif |
diff --git a/platforms/avr/flash.mk b/platforms/avr/flash.mk index e679bf0ac..8eef5fbb0 100644 --- a/platforms/avr/flash.mk +++ b/platforms/avr/flash.mk | |||
| @@ -161,19 +161,19 @@ hid_bootloader: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware | |||
| 161 | 161 | ||
| 162 | flash: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware | 162 | flash: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware |
| 163 | ifneq ($(strip $(PROGRAM_CMD)),) | 163 | ifneq ($(strip $(PROGRAM_CMD)),) |
| 164 | $(PROGRAM_CMD) | 164 | $(UNSYNC_OUTPUT_CMD) && $(PROGRAM_CMD) |
| 165 | else ifeq ($(strip $(BOOTLOADER)), caterina) | 165 | else ifeq ($(strip $(BOOTLOADER)), caterina) |
| 166 | $(call EXEC_AVRDUDE) | 166 | $(UNSYNC_OUTPUT_CMD) && $(call EXEC_AVRDUDE) |
| 167 | else ifeq ($(strip $(BOOTLOADER)), halfkay) | 167 | else ifeq ($(strip $(BOOTLOADER)), halfkay) |
| 168 | $(call EXEC_TEENSY) | 168 | $(UNSYNC_OUTPUT_CMD) && $(call EXEC_TEENSY) |
| 169 | else ifeq (dfu,$(findstring dfu,$(BOOTLOADER))) | 169 | else ifeq (dfu,$(findstring dfu,$(BOOTLOADER))) |
| 170 | $(call EXEC_DFU) | 170 | $(UNSYNC_OUTPUT_CMD) && $(call EXEC_DFU) |
| 171 | else ifeq ($(strip $(BOOTLOADER)), USBasp) | 171 | else ifeq ($(strip $(BOOTLOADER)), USBasp) |
| 172 | $(call EXEC_USBASP) | 172 | $(UNSYNC_OUTPUT_CMD) && $(call EXEC_USBASP) |
| 173 | else ifeq ($(strip $(BOOTLOADER)), bootloadHID) | 173 | else ifeq ($(strip $(BOOTLOADER)), bootloadHID) |
| 174 | $(call EXEC_BOOTLOADHID) | 174 | $(UNSYNC_OUTPUT_CMD) && $(call EXEC_BOOTLOADHID) |
| 175 | else ifeq ($(strip $(BOOTLOADER)), qmk-hid) | 175 | else ifeq ($(strip $(BOOTLOADER)), qmk-hid) |
| 176 | $(call EXEC_HID_LUFA) | 176 | $(UNSYNC_OUTPUT_CMD) && $(call EXEC_HID_LUFA) |
| 177 | else | 177 | else |
| 178 | $(PRINT_OK); $(SILENT) || printf "$(MSG_FLASH_BOOTLOADER)" | 178 | $(PRINT_OK); $(SILENT) || printf "$(MSG_FLASH_BOOTLOADER)" |
| 179 | endif | 179 | endif |
diff --git a/platforms/chibios/flash.mk b/platforms/chibios/flash.mk index 46aff6e4b..c0b32c2f2 100644 --- a/platforms/chibios/flash.mk +++ b/platforms/chibios/flash.mk | |||
| @@ -73,15 +73,15 @@ teensy: $(BUILD_DIR)/$(TARGET).hex cpfirmware sizeafter | |||
| 73 | 73 | ||
| 74 | flash: $(BUILD_DIR)/$(TARGET).bin cpfirmware sizeafter | 74 | flash: $(BUILD_DIR)/$(TARGET).bin cpfirmware sizeafter |
| 75 | ifneq ($(strip $(PROGRAM_CMD)),) | 75 | ifneq ($(strip $(PROGRAM_CMD)),) |
| 76 | $(PROGRAM_CMD) | 76 | $(UNSYNC_OUTPUT_CMD) && $(PROGRAM_CMD) |
| 77 | else ifeq ($(strip $(BOOTLOADER)),kiibohd) | 77 | else ifeq ($(strip $(BOOTLOADER)),kiibohd) |
| 78 | $(call EXEC_DFU_UTIL) | 78 | $(UNSYNC_OUTPUT_CMD) && $(call EXEC_DFU_UTIL) |
| 79 | else ifeq ($(strip $(MCU_FAMILY)),KINETIS) | 79 | else ifeq ($(strip $(MCU_FAMILY)),KINETIS) |
| 80 | $(call EXEC_TEENSY) | 80 | $(UNSYNC_OUTPUT_CMD) && $(call EXEC_TEENSY) |
| 81 | else ifeq ($(strip $(MCU_FAMILY)),MIMXRT1062) | 81 | else ifeq ($(strip $(MCU_FAMILY)),MIMXRT1062) |
| 82 | $(call EXEC_TEENSY) | 82 | $(UNSYNC_OUTPUT_CMD) && $(call EXEC_TEENSY) |
| 83 | else ifeq ($(strip $(MCU_FAMILY)),STM32) | 83 | else ifeq ($(strip $(MCU_FAMILY)),STM32) |
| 84 | $(call EXEC_DFU_UTIL) | 84 | $(UNSYNC_OUTPUT_CMD) && $(call EXEC_DFU_UTIL) |
| 85 | else | 85 | else |
| 86 | $(PRINT_OK); $(SILENT) || printf "$(MSG_FLASH_BOOTLOADER)" | 86 | $(PRINT_OK); $(SILENT) || printf "$(MSG_FLASH_BOOTLOADER)" |
| 87 | endif | 87 | endif |
