Add core config option to limit compile process count (#3952)

This commit is contained in:
Jesse Hills 2022-10-27 12:17:21 +13:00 committed by GitHub
parent 991fc54994
commit 85faecb2fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 2 deletions

View file

@ -116,6 +116,7 @@ CONF_COMMAND_RETAIN = "command_retain"
CONF_COMMAND_TOPIC = "command_topic" CONF_COMMAND_TOPIC = "command_topic"
CONF_COMMENT = "comment" CONF_COMMENT = "comment"
CONF_COMMIT = "commit" CONF_COMMIT = "commit"
CONF_COMPILE_PROCESS_LIMIT = "compile_process_limit"
CONF_COMPONENT_ID = "component_id" CONF_COMPONENT_ID = "component_id"
CONF_COMPONENTS = "components" CONF_COMPONENTS = "components"
CONF_CONDITION = "condition" CONF_CONDITION = "condition"

View file

@ -1,4 +1,5 @@
import logging import logging
import multiprocessing
import os import os
import re import re
@ -11,6 +12,7 @@ from esphome.const import (
CONF_BOARD_FLASH_MODE, CONF_BOARD_FLASH_MODE,
CONF_BUILD_PATH, CONF_BUILD_PATH,
CONF_COMMENT, CONF_COMMENT,
CONF_COMPILE_PROCESS_LIMIT,
CONF_ESPHOME, CONF_ESPHOME,
CONF_FRAMEWORK, CONF_FRAMEWORK,
CONF_INCLUDES, CONF_INCLUDES,
@ -151,6 +153,9 @@ CONFIG_SCHEMA = cv.All(
cv.Optional(CONF_MIN_VERSION, default=ESPHOME_VERSION): cv.All( cv.Optional(CONF_MIN_VERSION, default=ESPHOME_VERSION): cv.All(
cv.version_number, validate_version cv.version_number, validate_version
), ),
cv.Optional(CONF_COMPILE_PROCESS_LIMIT): cv.int_range(
min=1, max=multiprocessing.cpu_count()
),
} }
), ),
validate_hostname, validate_hostname,

View file

@ -8,7 +8,7 @@ import os
import re import re
import subprocess import subprocess
from esphome.const import KEY_CORE from esphome.const import CONF_COMPILE_PROCESS_LIMIT, CONF_ESPHOME, KEY_CORE
from esphome.core import CORE, EsphomeError from esphome.core import CORE, EsphomeError
from esphome.util import run_external_command, run_external_process from esphome.util import run_external_command, run_external_process
@ -103,7 +103,10 @@ def run_platformio_cli_run(config, verbose, *args, **kwargs) -> Union[str, int]:
def run_compile(config, verbose): def run_compile(config, verbose):
return run_platformio_cli_run(config, verbose) args = []
if CONF_COMPILE_PROCESS_LIMIT in config[CONF_ESPHOME]:
args += [f"-j{config[CONF_ESPHOME][CONF_COMPILE_PROCESS_LIMIT]}"]
return run_platformio_cli_run(config, verbose, *args)
def _run_idedata(config): def _run_idedata(config):