Add --cpus to manually specify parallel jobs

This commit is contained in:
2026-02-10 19:51:06 -05:00
parent 5a8e63e280
commit 6ab90ddbac

View File

@@ -22,6 +22,8 @@ print_help() {
--release,-r,--version,-v RELEASE ("snapshot", "22.03.5") --release,-r,--version,-v RELEASE ("snapshot", "22.03.5")
--buildroot,-b PATH --buildroot,-b PATH
Default: location of openwrtbuilder script Default: location of openwrtbuilder script
--cpus,-c NUM
Default: # of host CPUS minus 1
--source[=CLEAN] --source[=CLEAN]
Build image from source, not from Image Builder Build image from source, not from Image Builder
Optional CLEAN runs the given clean mode before building Optional CLEAN runs the given clean mode before building
@@ -50,7 +52,7 @@ print_help() {
# @internal # @internal
init() { init() {
debug "${FUNCNAME[0]}" debug "${FUNCNAME[0]}"
declare -g ID RPM_MGR SCRIPT_DIR DL_TOOL declare -g ID RPM_MGR SCRIPT_DIR DL_TOOL CPUS
((DEBUG)) || echo "To enable debugging output, use --debug or -d" ((DEBUG)) || echo "To enable debugging output, use --debug or -d"
@@ -124,12 +126,12 @@ init() {
parse_input() { parse_input() {
debug "${FUNCNAME[0]}" "$*" debug "${FUNCNAME[0]}" "$*"
declare -ga PROFILES declare -ga PROFILES
declare -gi RESET=0 FROM_SOURCE=0 YES=0 DEBUG=0 FORCE_DEPENDS=0 declare -gi RESET=0 FROM_SOURCE=0 YES=0 DEBUG=0 FORCE_DEPENDS=0 CPUS=0
declare -g USER_RELEASE SSH_UPGRADE_PATH SSH_BACKUP_PATH FLASH_DEV SOURCE_CLEAN declare -g USER_RELEASE SSH_UPGRADE_PATH SSH_BACKUP_PATH FLASH_DEV SOURCE_CLEAN
local long_opts='release:,version:,profile:,buildroot:,source::,' local long_opts='release:,version:,profile:,buildroot:,cpus:,source::,'
long_opts+='ssh-upgrade:,ssh-backup:,flash:,reset,depends,yes,debug,help' long_opts+='ssh-upgrade:,ssh-backup:,flash:,reset,depends,yes,debug,help'
if _input=$(getopt -o +r:v:p:b:sf:ydh -l $long_opts -- "$@"); then if _input=$(getopt -o +r:v:p:b:c:sf:ydh -l $long_opts -- "$@"); then
eval set -- "$_input" eval set -- "$_input"
while true; do while true; do
case "$1" in case "$1" in
@@ -142,6 +144,7 @@ parse_input() {
*) SOURCE_CLEAN="$1"; shift ;; *) SOURCE_CLEAN="$1"; shift ;;
esac esac
;; ;;
--cpus|-c) shift; CPUS="$1" ;;
--ssh-upgrade) shift; SSH_UPGRADE_PATH="$1" ;; --ssh-upgrade) shift; SSH_UPGRADE_PATH="$1" ;;
--ssh-backup) shift; SSH_BACKUP_PATH="$1" ;; --ssh-backup) shift; SSH_BACKUP_PATH="$1" ;;
--flash|-f) shift; FLASH_DEV="$1" ;; --flash|-f) shift; FLASH_DEV="$1" ;;
@@ -441,7 +444,7 @@ make_images() {
debug make "${make_opts[@]}" image BIN_DIR="$BIN_DIR" \ debug make "${make_opts[@]}" image BIN_DIR="$BIN_DIR" \
PROFILE="$DEVICE" PACKAGES="$PACKAGES" \ PROFILE="$DEVICE" PACKAGES="$PACKAGES" \
FILES="$FILES_DIR" --directory="$BUILD_DIR" \ FILES="$FILES_DIR" --directory="$BUILD_DIR" \
--jobs="$(($(nproc) - 1))" --jobs="$JOBS"
make "${make_opts[@]}" image \ make "${make_opts[@]}" image \
BIN_DIR="$BIN_DIR" \ BIN_DIR="$BIN_DIR" \
@@ -449,7 +452,7 @@ make_images() {
PACKAGES="$PACKAGES" \ PACKAGES="$PACKAGES" \
FILES="$FILES_DIR" \ FILES="$FILES_DIR" \
--directory="$BUILD_DIR" \ --directory="$BUILD_DIR" \
--jobs="$(($(nproc) - 1))" \ --jobs="$JOBS" \
> "$BUILD_DIR/make.log" > "$BUILD_DIR/make.log"
} }
@@ -702,8 +705,8 @@ from_source() {
execute make "${make_opts[@]}" "-j1" download execute make "${make_opts[@]}" "-j1" download
# (Optional) Disable multicore make world # (Optional) Disable multicore make world
# ((DEBUG)) && make_opts+=("-j1") || make_opts+=("-j$(($(nproc)-2))") # ((DEBUG)) && make_opts+=("-j1") || make_opts+=("-j$JOBS)")
make_opts+=("-j$(($(nproc)-2))") make_opts+=("-j$JOBS")
# Make image # Make image
if ! execute ionice -c2 -n7 nice -n19 make "${make_opts[@]}" BIN_DIR="$BIN_DIR" world; then if ! execute ionice -c2 -n7 nice -n19 make "${make_opts[@]}" BIN_DIR="$BIN_DIR" world; then
@@ -826,6 +829,15 @@ main() {
[[ -f "$BUILD_ROOT/.dependencies_ib.lock" ]] && rm -f "$BUILD_ROOT/.dependencies_ib.lock" [[ -f "$BUILD_ROOT/.dependencies_ib.lock" ]] && rm -f "$BUILD_ROOT/.dependencies_ib.lock"
fi fi
# Set number of parallel jobs for make and imagebuilder
declare -gi JOBS
if ((CPUS)); then
JOBS="$CPUS" # user overide (--cpus)
else
JOBS=$(nproc || echo 4) # fallback to quad-core if nproc fails
((JOBS > 1)) && JOBS=$((JOBS - 1)) # leave one CPU free
fi
# Run selected profiles # Run selected profiles
for profile in "${PROFILES[@]}"; do for profile in "${PROFILES[@]}"; do
debug "Running profile: $profile" debug "Running profile: $profile"