summaryrefslogtreecommitdiffhomepage
path: root/subr
diff options
context:
space:
mode:
authorLucio Andrés Illanes Albornoz (arab, vxp) <lucio@lucioillanes.de>2017-12-05 00:47:08 +0000
committerLucio Andrés Illanes Albornoz (arab, vxp) <lucio@lucioillanes.de>2017-12-05 01:44:06 +0000
commit807f5fcd8b8d5e661986e16a271d94b165c53b59 (patch)
treef855af33bd4009373d8e2908eb25a3ae0ac8695c /subr
parentb169d7a3cd5abdf490eece47782004196bfae4bf (diff)
downloadmidipix_build-807f5fcd8b8d5e661986e16a271d94b165c53b59.tar.bz2
midipix_build-807f5fcd8b8d5e661986e16a271d94b165c53b59.tar.xz
vars/build.vars:{native_packages_*,dist_minipix}: enables parallelisation.
vars/env.vars:${DEFAULT_BUILD_VARS}: adds ${PKG_PARALLELISE}. subr/ex_pkg_dispatch.subr: implements parallelisation.
Diffstat (limited to 'subr')
-rw-r--r--subr/ex_pkg_dispatch.subr91
1 files changed, 52 insertions, 39 deletions
diff --git a/subr/ex_pkg_dispatch.subr b/subr/ex_pkg_dispatch.subr
index 7a8a95d2..4fbc2b17 100644
--- a/subr/ex_pkg_dispatch.subr
+++ b/subr/ex_pkg_dispatch.subr
@@ -9,7 +9,7 @@
ex_pkg_dispatch() {
local _tgt_name="${1}" _restart="${2}" _restart_at="${3}" \
_dispatch_fn="${4}" _tgt_name_uc \
- _pkg_names _pkg_name _pkg_name_uc \
+ _pkg_names _njob _njobs _njobs_max _pkg_name _pkg_name_uc \
_pipe_path _stderrout_path _pipe_msg _script_rc;
ex_rtl_fileop mkdir "${BUILD_WORKDIR}";
_pipe_path="${BUILD_WORKDIR}/build.fifo";
@@ -20,47 +20,60 @@ ex_pkg_dispatch() {
&& [ "${_restart}" != ALL ]; then
_pkg_names="$(ex_rtl_lfilter "${_pkg_names}" "${_restart}")";
fi;
- for _pkg_name in ${_pkg_names}; do
- _pkg_name_uc="$(ex_rtl_toupper "${_pkg_name}")";
- if [ -n "$(ex_rtl_get_var_unsafe PKG_${_pkg_name_uc}_DISABLED)" ]; then
- "${_dispatch_fn}" disabled_pkg "${_pkg_name}" "${_tgt_name}";
- continue;
- elif ex_pkg_state_test "${_pkg_name}" finish\
- && [ -z "${_restart_at}" ]; then
- "${_dispatch_fn}" skipped_pkg "${_pkg_name}" "${_tgt_name}";
- continue;
+ set -- ${_pkg_names};
+ while [ ${#} -gt 0 ]; do
+ _script_rc=0; _njobs=0;
+ if [ "$(ex_rtl_get_var_unsafe ${_tgt_name_uc}_PARALLELISE)" = 1 ]; then
+ _njobs_max="${DEFAULT_BUILD_CPUS}";
else
- ex_rtl_fileop mkfifo "${_pipe_path}";
- _stderrout_path="${BUILD_WORKDIR}/${_pkg_name}_stderrout.log";
- _script_rc=1;
- "${_dispatch_fn}" start_pkg "${_pkg_name}" "${_tgt_name}";
+ _njobs_max=1;
fi;
- (set -o errexit -o noglob;
- ex_pkg_env "${_pkg_name}" "${_tgt_name}" "${_restart_at}";
- trap "if [ \${?} -eq 0 ]; then \
- echo \"done ${PKG_NAME}\" >&3; \
- else \
- echo \"fail ${PKG_NAME}\" >&3; \
- fi;" EXIT HUP INT TERM USR1 USR2;
- ex_pkg_exec "${_pkg_name}" "${_tgt_name}" "${_restart_at}" \
- "${_dispatch_fn}";) 1>"${_stderrout_path}" 2>&1 3>"${_pipe_path}" &
- while read _pipe_msg; do
- case "${_pipe_msg%% *}" in
- done) _script_rc=0;
- "${_dispatch_fn}" finish_pkg "${_pkg_name}" "${_tgt_name}";
- break; ;;
- fail) _script_rc=1;
- "${_dispatch_fn}" fail_pkg "${_pkg_name}" "${_tgt_name}";
- break; ;;
- step) "${_dispatch_fn}" step_pkg ${_pipe_msg#step }; ;;
- *) _script_rc=1;
- "${_dispatch_fn}" fail_pkg "${_pkg_name}" "${_tgt_name}";
- break; ;;
- esac; done <"${_pipe_path}";
- ex_rtl_fileop rm "${_pipe_path}";
- if [ "${_script_rc:-1}" -eq 1 ]; then
- return 1;
+ ex_rtl_fileop mkfifo "${_pipe_path}";
+ for _njob in $(seq 1 ${_njobs_max}); do
+ if [ ${#} -eq 0 ]; then
+ break;
+ else
+ _pkg_name="${1}"; shift;
+ _pkg_name_uc="$(ex_rtl_toupper "${_pkg_name}")";
+ fi;
+ if [ -n "$(ex_rtl_get_var_unsafe PKG_${_pkg_name_uc}_DISABLED)" ]; then
+ "${_dispatch_fn}" disabled_pkg "${_pkg_name}" "${_tgt_name}";
+ continue;
+ elif ex_pkg_state_test "${_pkg_name}" finish\
+ && [ -z "${_restart_at}" ]; then
+ "${_dispatch_fn}" skipped_pkg "${_pkg_name}" "${_tgt_name}";
+ continue;
+ else
+ _stderrout_path="${BUILD_WORKDIR}/${_pkg_name}_stderrout.log";
+ "${_dispatch_fn}" start_pkg "${_pkg_name}" "${_tgt_name}";
+ fi;
+ (set -o errexit -o noglob;
+ ex_pkg_env "${_pkg_name}" "${_tgt_name}" "${_restart_at}";
+ trap "if [ \${?} -eq 0 ]; then \
+ echo \"done ${_pkg_name} ${_tgt_name}\" >&3; \
+ else \
+ echo \"fail ${_pkg_name} ${_tgt_name}\" >&3; \
+ fi;" EXIT HUP INT TERM USR1 USR2;
+ ex_pkg_exec "${_pkg_name}" "${_tgt_name}" "${_restart_at}" \
+ "${_dispatch_fn}";) 1>"${_stderrout_path}" 2>&1 3>"${_pipe_path}" &
+ : $((_njobs+=1));
+ done;
+ if [ "${_njobs:-0}" -gt 0 ]; then
+ while read _pipe_msg; do
+ case "${_pipe_msg%% *}" in
+ done) "${_dispatch_fn}" finish_pkg ${_pipe_msg#done };
+ [ $((_njobs-=1)) -eq 0 ] && break; ;;
+ fail) _script_rc=1;
+ "${_dispatch_fn}" fail_pkg ${_pipe_msg#fail };
+ [ $((_njobs-=1)) -eq 0 ] && break; ;;
+ step) "${_dispatch_fn}" step_pkg ${_pipe_msg#step };
+ esac; done <"${_pipe_path}";
+ if [ "${_script_rc:-1}" -eq 1 ]; then
+ ex_rtl_fileop rm "${_pipe_path}";
+ return 1;
+ fi;
fi;
+ ex_rtl_fileop rm "${_pipe_path}";
done;
"${_dispatch_fn}" finish_target "" "${_tgt_name}";
};