From ec19f02f81c206f54a89ef7e1f49715e90470c31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz=20=28arab=2C=20vx?= =?UTF-8?q?p=29?= Date: Sun, 3 Dec 2017 16:10:05 +0000 Subject: Separate front end (build.sh, subr/build_*) from dispatcher. --- subr/ex_pkg_dispatch.subr | 94 +++++++++++++++++++++++++++-------------------- 1 file changed, 54 insertions(+), 40 deletions(-) (limited to 'subr/ex_pkg_dispatch.subr') diff --git a/subr/ex_pkg_dispatch.subr b/subr/ex_pkg_dispatch.subr index f099dd6a..90a23717 100644 --- a/subr/ex_pkg_dispatch.subr +++ b/subr/ex_pkg_dispatch.subr @@ -3,47 +3,61 @@ # ex_pkg_dispatch() { - local _tgt_name="${1}" _pkg_name="${2}" \ - _restart="${3}" _restart_at="${4}" \ - _stdout_path _stderr_path \ - _pipe_path _pipe_msg _script_rc=1; - if ex_pkg_state_test "${_pkg_name}" finish \ - && [ -z "${_restart}" ] \ - && [ "${_tgt_name}" != "INVARIANTS" ]; then - return 0; - else - _pipe_path="${WORKDIR}/${_pkg_name}_build.fifo"; - ex_build_fileop rm "${_pipe_path}"; mkfifo "${_pipe_path}"; - _stderr_path="${WORKDIR}/${_pkg_name}_stderr.log"; - _stdout_path="${WORKDIR}/${_pkg_name}_stdout.log"; - ex_build_fileop rm "${_stderr_path}" "${_stdout_path}"; + local _tgt_name="${1}" _restart="${2}" _restart_at="${3}" \ + _dispatch_fn="${4}" _tgt_name_uc \ + _pkg_names _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"; + _tgt_name_uc="$(ex_rtl_toupper "${_tgt_name}")"; + "${_dispatch_fn}" start_target "" "${_tgt_name}"; + _pkg_names="$(ex_rtl_get_var_unsafe ${_tgt_name_uc}_PACKAGES)"; + if [ -n "${_restart}" ]; then + _pkg_names="$(ex_rtl_lfilter "${_pkg_names}" "${_restart}")"; fi; - (set -o errexit -o noglob; - trap "if [ \${?} -eq 0 ]; then \ - echo \"done ${PKG_NAME}\" >&3; \ - else \ - echo \"fail ${PKG_NAME}\" >&3; \ - fi;" EXIT HUP INT TERM USR1 USR2; - if [ "${ARG_XTRACE:-0}" -eq 1 ]; then - set -o xtrace; - fi; - ex_pkg_vars; - if [ "${PKG_DISABLED:-0}" -eq 1 ]; then - ex_log_msg vnfo "Skipping disabled package \`${PKG_NAME}.'"; - else - ex_pkg_env; - ex_pkg_steps "${_tgt_name}" "${_pkg_name}" \ - "${_restart}" "${_restart_at}"; - fi;) 1>"${_stdout_path}" 2>"${_stderr_path}" \ - 3>"${_pipe_path}" & - while read _pipe_msg; do - case "${_pipe_msg%% *}" in - done) _script_rc=0; break; ;; - fail) _script_rc=1; break; ;; - *) _script_rc=1; break; ;; - esac; done <"${_pipe_path}"; - ex_build_fileop rm "${_pipe_path}"; - return "${_script_rc:-1}"; + 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; + 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}"; + 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; + fi; + done; + "${_dispatch_fn}" finish_target "" "${_tgt_name}"; }; # vim:filetype=sh -- cgit v1.2.3