Skip to content

Commit 360eb05

Browse files
feat(usability): add -j/--jobs optional argument (#1854)
1 parent 9bf0f4f commit 360eb05

File tree

3 files changed

+88
-32
lines changed

3 files changed

+88
-32
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ chmod u+x nodebuilder
5858

5959
| Short | Long Version | Description | Arguments |
6060
|:-----:|:-------------|:------------|:----------|
61-
| `-b` | `--bitcoin-version` | Specify the Bitcoin version. | One argument<br>For example: `-b 28.0` |
61+
| `-b` | `--bitcoin-version` | Specify the Bitcoin version. | One argument<br>E.g.: `-b 28.0` |
6262
| `-c` | `--compile` | Build Bitcoin from source. | No arguments |
6363
| `-h` | `--help` | Display the help message. | No arguments<br>_Supersedes other arguments._ |
64-
| `-p` | `--prune` | Set a prune value in MiB. | One argument<br>For example: `-p 50000` |
64+
| `-j` | `--jobs` | Set the number of compile jobs. | One argument<br>E.g.: `-j 1` |
65+
| `-p` | `--prune` | Set a prune value in MiB. | One argument<br>E.g.: `-p 50000` |
6566
| `-q` | `--quiet` | Suppress output unless unexpected behavior is detected. | No arguments |
6667
| `-r` | `--skip-reboot` | Skip reboot after installing system update. | No arguments |
6768
| `-s` | `--skip-update` | Skip installation of system updates. | No arguments |

nodebuilder

Lines changed: 54 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ ensure_curl_dependency()
486486
sudo dnf install --allowerasing --assumeyes curl > /dev/null
487487
;;
488488
gentoo)
489-
emerge --jobs "${SYS_CORES_COUNT}" --load-average "${SYS_CORES_PLUS_ONE}" --quiet --quiet-build --quiet-fail net-misc/curl
489+
emerge --jobs "${compile_num_jobs:-SYS_CORES_COUNT}" --load-average "${compile_num_jobs:-SYS_CORES_PLUS_ONE}" --quiet --quiet-build --quiet-fail net-misc/curl
490490
;;
491491
arch | endeavouros | garuda | manjaro)
492492
sudo pacman -Syu --needed --noconfirm curl > /dev/null
@@ -553,7 +553,7 @@ ensure_sudo_dependency()
553553
;;
554554
gentoo)
555555
emerge --sync --quiet
556-
emerge --jobs "${SYS_CORES_COUNT}" --load-average "${SYS_CORES_PLUS_ONE}" --quiet --quiet-build --quiet-fail app-admin/sudo
556+
emerge --jobs "${compile_num_jobs:-SYS_CORES_COUNT}" --load-average "${compile_num_jobs:-SYS_CORES_PLUS_ONE}" --quiet --quiet-build --quiet-fail app-admin/sudo
557557
;;
558558
arch | endeavouros | garuda | manjaro)
559559
pacman -Syu --needed --noconfirm sudo > /dev/null
@@ -615,7 +615,7 @@ ensure_xargs_dependency()
615615
;;
616616
gentoo)
617617
emerge --sync --quiet
618-
emerge --jobs "${SYS_CORES_COUNT}" --load-average "${SYS_CORES_PLUS_ONE}" --quiet --quiet-build --quiet-fail sys-apps/findutils
618+
emerge --jobs "${compile_num_jobs:-SYS_CORES_COUNT}" --load-average "${compile_num_jobs:-SYS_CORES_PLUS_ONE}" --quiet --quiet-build --quiet-fail sys-apps/findutils
619619
;;
620620
arch | endeavouros | garuda | manjaro)
621621
pacman -Syu --needed --noconfirm findutils > /dev/null
@@ -862,12 +862,12 @@ install_build_dependencies_emerge()
862862
dependencies=$(curl --fail --silent --show-error --location --retry 5 "${BUILD_DEPENDENCIES_URL}")
863863
[ -z "${dependencies:-}" ] && throw_error 'The list of dependencies is empty.'
864864
if ! printf '%s\n' "${dependencies}" | xargs emerge --autounmask-write \
865-
--jobs "${SYS_CORES_COUNT}" --load-average "${SYS_CORES_PLUS_ONE}" --quiet --quiet-build --quiet-fail; then
865+
--jobs "${compile_num_jobs:-SYS_CORES_COUNT}" --load-average "${SYS_CORES_PLUS_ONE}" --quiet --quiet-build --quiet-fail; then
866866
etc-update --automode -5
867-
emerge --update --jobs "${SYS_CORES_COUNT}" --load-average "${SYS_CORES_PLUS_ONE}" --quiet --quiet-build --quiet-fail --deep --newuse @world
867+
emerge --update --jobs "${compile_num_jobs:-SYS_CORES_COUNT}" --load-average "${SYS_CORES_PLUS_ONE}" --quiet --quiet-build --quiet-fail --deep --newuse @world
868868
# Run the install command again
869869
printf '%s\n' "${dependencies}" | xargs emerge --autounmask-write \
870-
--jobs "${SYS_CORES_COUNT}" --load-average "${SYS_CORES_PLUS_ONE}" --quiet --quiet-build --quiet-fail
870+
--jobs "${compile_num_jobs:-SYS_CORES_COUNT}" --load-average "${SYS_CORES_PLUS_ONE}" --quiet --quiet-build --quiet-fail
871871
fi
872872
}
873873

@@ -1098,7 +1098,7 @@ install_runtime_dependencies_emerge()
10981098
dependencies=$(torsocks curl --fail --silent --show-error --location --retry 2 "${RUNTIME_DEPENDENCIES_URL}") ||
10991099
dependencies=$(curl --fail --silent --show-error --location --retry 5 "${RUNTIME_DEPENDENCIES_URL}")
11001100
[ -z "${dependencies}" ] && throw_error 'The list of dependencies is empty.'
1101-
printf '%s\n' "${dependencies}" | xargs emerge --autounmask-write --jobs "${SYS_CORES_COUNT}" --load-average "${SYS_CORES_PLUS_ONE}" --quiet --quiet-build --quiet-fail
1101+
printf '%s\n' "${dependencies}" | xargs emerge --autounmask-write --jobs "${compile_num_jobs:-SYS_CORES_COUNT}" --load-average "${compile_num_jobs:-SYS_CORES_PLUS_ONE}" --quiet --quiet-build --quiet-fail
11021102
}
11031103

11041104
install_runtime_dependencies_freebsd()
@@ -1262,7 +1262,7 @@ install_system_updates_dnf()
12621262
install_system_updates_emerge()
12631263
{
12641264
readonly GENTOO_EBUILD_REPOSITORY='/var/db/repos/gentoo'
1265-
readonly EMERGE_UPDATE_COMMAND="emerge --update --jobs ${SYS_CORES_COUNT} --load-average ${SYS_CORES_PLUS_ONE} --quiet --quiet-build --quiet-fail --deep --newuse @world"
1265+
readonly EMERGE_UPDATE_COMMAND="emerge --update --jobs ${compile_num_jobs:-SYS_CORES_COUNT} --load-average ${compile_num_jobs:-SYS_CORES_PLUS_ONE} --quiet --quiet-build --quiet-fail --deep --newuse @world"
12661266
readonly EMERGE_MAX_RETRIES='3'
12671267
printf '\n'
12681268

@@ -1402,6 +1402,7 @@ print_usage()
14021402
printf '%s\n' '-b, --bitcoin-version Specify the Bitcoin version'
14031403
printf '%s\n' '-c, --compile Build Bitcoin from source'
14041404
printf '%s\n' '-h, --help Display this help message'
1405+
printf '%s\n' '-j, --jobs Set the number of compile jobs'
14051406
printf '%s\n' '-p, --prune Set a prune value in MiB'
14061407
printf '%s\n' '-q, --quiet Suppress standard output'
14071408
printf '%s\n' '-r, --skip-reboot Skip reboot on system updates'
@@ -1506,9 +1507,12 @@ readonly VALID_BITCOIN_VERSION_LIST='0.9.5 0.10.0 0.10.1 0.10.2 0.10.3 0.10.4 \
15061507
0.20.0 0.20.1 0.20.2 0.21.0 0.21.1 0.21.2 22.0 22.1 23.0 23.1 23.2 24.0 \
15071508
24.0.1 24.1 24.2 25.0 25.1 25.2 26.0 26.1 26.2 27.0 27.1 27.2 28.0 28.1'
15081509

1510+
# Bump this variable for new Bitcoin Core releases
15091511
target_bitcoin_version='28.1'
15101512

1513+
# Instantiate the parameter variables
15111514
compile_bitcoin_flag='false'
1515+
compile_num_jobs=''
15121516
prune_value='-1'
15131517
quiet_output='false'
15141518
skip_system_update='false'
@@ -1536,11 +1540,31 @@ while [ $# -gt 0 ]; do
15361540
print_usage
15371541
exit 0
15381542
;;
1543+
-j | --jobs)
1544+
# ensure at leaset one additional argument is passed
1545+
if [ $# -eq 1 ]; then
1546+
throw_error '-j/--jobs requires one argumenet'
1547+
fi
1548+
1549+
# ensure the argument is a positive integer
1550+
case "$2" in
1551+
0)
1552+
throw_error 'Cannot compile with 0 jobs'
1553+
;;
1554+
'' | *[!0-9]*)
1555+
throw_error "$2 is not a number"
1556+
;;
1557+
*)
1558+
compile_num_jobs="$2"
1559+
;;
1560+
esac
1561+
shift
1562+
;;
15391563
-p | --prune)
15401564
if [ $# -eq 1 ]; then
15411565
throw_error '-p/--prune requires an argument'
15421566
fi
1543-
case $2 in
1567+
case "$2" in
15441568
*[!0-9]*) # if $2 contains any non-numeric characters
15451569
throw_error "The prune value '$2' must be a positive integer or zero to disable pruning"
15461570
;;
@@ -1609,25 +1633,27 @@ else
16091633
fi
16101634
readonly TEMP_DIRECTORY
16111635

1612-
case "${TARGET_KERNEL}" in
1613-
Linux | FreeBSD)
1614-
SYS_CORES_COUNT="$(nproc)"
1615-
;;
1616-
Darwin)
1617-
SYS_CORES_COUNT="$(sysctl -n hw.physicalcpu)"
1618-
;;
1619-
NetBSD | OpenBSD)
1620-
SYS_CORES_COUNT="$(sysctl -n hw.ncpu)"
1621-
;;
1622-
MINGW* | Cygwin)
1623-
throw_error 'Windows is not supported. Use Linux, macOS, or Windows Subsystem for Linux instead.'
1624-
;;
1625-
*)
1626-
throw_error "${TARGET_KERNEL} is not supported. Please run on Linux or macOS."
1627-
;;
1628-
esac
1629-
readonly SYS_CORES_COUNT
1630-
readonly SYS_CORES_PLUS_ONE="$((SYS_CORES_COUNT + 1))"
1636+
if [ -z "${compile_num_jobs}" ]; then
1637+
case "${TARGET_KERNEL}" in
1638+
Linux | FreeBSD)
1639+
SYS_CORES_COUNT="$(nproc)"
1640+
;;
1641+
Darwin)
1642+
SYS_CORES_COUNT="$(sysctl -n hw.physicalcpu)"
1643+
;;
1644+
NetBSD | OpenBSD)
1645+
SYS_CORES_COUNT="$(sysctl -n hw.ncpu)"
1646+
;;
1647+
MINGW* | Cygwin)
1648+
throw_error 'Windows is not supported. Use Linux, macOS, or Windows Subsystem for Linux instead.'
1649+
;;
1650+
*)
1651+
throw_error "${TARGET_KERNEL} is not supported. Please run on Linux or macOS."
1652+
;;
1653+
esac
1654+
readonly SYS_CORES_COUNT
1655+
readonly SYS_CORES_PLUS_ONE="$((SYS_CORES_COUNT + 1))"
1656+
fi
16311657

16321658
ensure_sudo_dependency
16331659
ensure_xargs_dependency

test/test_nodebuilder

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ print_usage()
6666
printf '%s\n' 'Options:'
6767
printf '%s\n' '-b, --bitcoin-version Specify the Bitcoin version'
6868
printf '%s\n' '-c, --compile Build Bitcoin from source'
69+
printf '%s\n' '-j, --jobs Specify number of compile jobs'
6970
printf '%s\n' '-h, --help Display this help message'
7071
printf '%s\n' '-r, --ref Choose a git tef to test'
7172
}
@@ -120,6 +121,26 @@ while [ $# -gt 0 ]; do
120121
print_usage
121122
exit 0
122123
;;
124+
-j | --jobs)
125+
# ensure at leaset one additional argument is passed
126+
if [ $# -eq 1 ]; then
127+
throw_error '-j/--jobs requires one argumenet'
128+
fi
129+
130+
# ensure the argument is a positive integer
131+
case "$2" in
132+
0)
133+
throw_error 'Cannot compile with 0 jobs'
134+
;;
135+
'' | *[!0-9]*)
136+
throw_error "--jobs requires a positive integer, but $2 is not one."
137+
;;
138+
*)
139+
readonly NUMBER_OF_COMPILE_JOBS="$2"
140+
;;
141+
esac
142+
shift
143+
;;
123144
-r | --ref)
124145
[ -z "$2" ] && throw_error 'No argument supplied for -r|--ref.' "${LINENO}"
125146
readonly GIT_REF_SHORT_NAME="$2"
@@ -168,15 +189,23 @@ bitcoind_pid_path="${bitcoin_data_directory}/bitcoind.pid"
168189
[ -f nodebuilder ] || wget --no-verbose "${NODEBUILDER_BINARY_URL}"
169190
[ -x nodebuilder ] || chmod u+x nodebuilder
170191

171-
nodebuilder_args=""
192+
nodebuilder_args=''
172193
[ -n "${TARGET_BITCOIN_VERSION}" ] && nodebuilder_args="${nodebuilder_args} --bitcoin-version ${TARGET_BITCOIN_VERSION}"
173-
[ "${COMPILE_BITCOIN}" = 'true' ] && nodebuilder_args="${nodebuilder_args} --compile"
194+
if [ "${COMPILE_BITCOIN}" = 'true' ]; then
195+
if [ -z "${NUMBER_OF_COMPILE_JOBS:-}" ]; then
196+
nodebuilder_args="${nodebuilder_args} --compile"
197+
else
198+
nodebuilder_args="${nodebuilder_args} --compile --jobs ${NUMBER_OF_COMPILE_JOBS}"
199+
fi
200+
fi
174201

175202
if [ -n "${nodebuilder_args}" ]; then
203+
# remove extra whitespace from arguments
176204
readonly NODEBUILDER_ARGS_TRIMMED="$(printf '%s' "${nodebuilder_args}" | sed -e 's/^[[:space:]]*//')"
177205
printf "Running nodebuilder with '%s' args\n" "${NODEBUILDER_ARGS_TRIMMED}"
178206
readonly RUN_NODEBUILDER_COMMAND="./nodebuilder ${NODEBUILDER_ARGS_TRIMMED:-}"
179207
else
208+
printf 'Running nodebuilder with no args\n'
180209
readonly RUN_NODEBUILDER_COMMAND="./nodebuilder"
181210
fi
182211

0 commit comments

Comments
 (0)