Allow global setting of compile process limit (#4081)

This commit is contained in:
Jesse Hills 2022-12-01 12:51:01 +13:00 committed by GitHub
parent db0ed055dd
commit 2dd032475b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 3 deletions

View File

@ -22,6 +22,14 @@ if bashio::config.has_value 'relative_url'; then
export ESPHOME_DASHBOARD_RELATIVE_URL=$(bashio::config 'relative_url')
fi
if bashio::config.has_value 'default_compile_process_limit'; then
export ESPHOME_DEFAULT_COMPILE_PROCESS_LIMIT=$(bashio::config 'default_compile_process_limit')
else
if grep -q 'Raspberry Pi 3' /proc/cpuinfo; then
export ESPHOME_DEFAULT_COMPILE_PROCESS_LIMIT=1;
fi
fi
pio_cache_base=/data/cache/platformio
# we can't set core_dir, because the settings file is stored in `core_dir/appstate.json`
# setting `core_dir` would therefore prevent pio from accessing

View File

@ -110,6 +110,15 @@ def validate_version(value: str):
return value
if "ESPHOME_DEFAULT_COMPILE_PROCESS_LIMIT" in os.environ:
_compile_process_limit_default = min(
int(os.environ["ESPHOME_DEFAULT_COMPILE_PROCESS_LIMIT"]),
multiprocessing.cpu_count(),
)
else:
_compile_process_limit_default = cv.UNDEFINED
CONF_ESP8266_RESTORE_FROM_FLASH = "esp8266_restore_from_flash"
CONFIG_SCHEMA = cv.All(
cv.Schema(
@ -153,9 +162,9 @@ CONFIG_SCHEMA = cv.All(
cv.Optional(CONF_MIN_VERSION, default=ESPHOME_VERSION): cv.All(
cv.version_number, validate_version
),
cv.Optional(CONF_COMPILE_PROCESS_LIMIT): cv.int_range(
min=1, max=multiprocessing.cpu_count()
),
cv.Optional(
CONF_COMPILE_PROCESS_LIMIT, default=_compile_process_limit_default
): cv.int_range(min=1, max=multiprocessing.cpu_count()),
}
),
validate_hostname,