From 9d57f835dd1abe6008e19e040917d5943f379d55 Mon Sep 17 00:00:00 2001 From: Lucio Andrés Illanes Albornoz Date: May 15 2020 09:38:04 +0000 Subject: Include percentage and package counts in build status informationals. --- diff --git a/build.sh b/build.sh index dfbdeef..efb1ecc 100755 --- a/build.sh +++ b/build.sh @@ -68,14 +68,14 @@ buildp_dispatch_pkg_state() { missing_pkg) rtl_log_msg fatalexit "Error: unknown package \`%s'." "${_pkg_name}"; ;; msg_pkg) shift 3; rtl_log_msg verbose "%s/%s: %s" "${_group_name}" "${_pkg_name}" "${*}"; ;; skipped_pkg) : $((BUILD_NSKIP+=1)); rtl_log_msg verbose "Skipping finished package \`%s'." "${_pkg_name}"; ;; - start_pkg) rtl_log_msg info "[% 3d%%] [%03d/%03d] Starting \`%s' build..." "$(((100*${4} + ${5}/2)/${5}))" "${4}" "${5}" "${_pkg_name}"; ;; + start_pkg) rtl_log_msg info "[% 3d%%] [%03d/%03d] Starting \`%s' build..." "${6}" "${4}" "${5}" "${_pkg_name}"; ;; step_pkg) rtl_log_msg verbose "Finished build step %s of package \`%s'." "${4}" "${_pkg_name}"; ;; finish_pkg) : $((BUILD_NFINI+=1)); if [ "${ARG_VERBOSE:-0}" -ge 2 ]; then cat "${BUILD_WORKDIR}/${_pkg_name}_stderrout.log"; fi; - rtl_log_msg info_end "Finished \`%s' build." "${_pkg_name}"; ;; + rtl_log_msg info_end "[% 3d%%] [%03d/%03d] Finished \`%s' build." "${6}" "${4}" "${5}" "${_pkg_name}"; ;; start_pkg_child) if [ "${PKG_NO_LOG_VARS:-0}" -eq 0 ]; then rtl_log_env_vars "build" $(rtl_get_vars_fast "^PKG_"); diff --git a/subr/ex_pkg_dispatch.subr b/subr/ex_pkg_dispatch.subr index 4d4574d..3145ab2 100644 --- a/subr/ex_pkg_dispatch.subr +++ b/subr/ex_pkg_dispatch.subr @@ -61,14 +61,18 @@ exp_pkg_dispatch_expand_packages() { exp_pkg_dispatch_group() { local _build_steps_default="${1}" _build_vars_default="${2}" _checkfl="${3}" \ _dispatch_fn="${4}" _group_name="${5}" _njobs_max="${6}" _pipe_path="${7}" \ - _restart_at="${8}" _workdir="${9}" _pipe_msg="" _pkg_name="" _rc=0; + _restart_at="${8}" _workdir="${9}" _pipe_msg="" _pkg_name="" _rc=0 _status_percentage=""; rtl_fileop mkfifo "${_pipe_path}"; while true; do while [ "${EXP_PKG_DISPATCH_NJOBS:-0}" -gt 0 ] && read _pipe_msg; do case "${_pipe_msg%% *}" in done) _pkg_name="${_pipe_msg#done * }"; : $((EXP_PKG_DISPATCH_NJOBS-=1)); EX_PKG_FINISHED="$(rtl_lconcat "${EX_PKG_FINISHED}" "${_pkg_name}")"; - "${_dispatch_fn}" finish_pkg ${_pipe_msg#done }; + _status_percentage="$(((100 * ${EXP_PKG_DISPATCH_COUNT} + ${EXP_PKG_DISPATCH_COUNT_MAX} / 2)))"; + if [ "${_status_percentage}" -gt 0 ]; then + _status_percentage="$((${_status_percentage} / ${EXP_PKG_DISPATCH_COUNT_MAX}))"; + fi; + "${_dispatch_fn}" finish_pkg ${_pipe_msg#done } "${EXP_PKG_DISPATCH_COUNT_MAX}" "${_status_percentage}"; EX_PKG_NAMES="$(rtl_lfilter "${EX_PKG_NAMES}" "${_pkg_name}")"; EX_PKG_DISPATCH_WAIT="$(rtl_lfilter "${EX_PKG_DISPATCH_WAIT}" "${_pkg_name}")"; if [ -n "${EX_PKG_NAMES}" ] && [ "${_rc}" -eq 0 ]; then @@ -84,7 +88,7 @@ exp_pkg_dispatch_group() { break; fi; ;; fail) : $((EXP_PKG_DISPATCH_NJOBS-=1)); _rc=1; - "${_dispatch_fn}" fail_pkg ${_pipe_msg#fail }; ;; + "${_dispatch_fn}" fail_pkg ${_pipe_msg#fail } "${EXP_PKG_DISPATCH_COUNT_MAX}"; ;; msg_pkg) "${_dispatch_fn}" msg_pkg ${_pipe_msg#msg_pkg }; ;; step) "${_dispatch_fn}" step_pkg ${_pipe_msg#step }; ;; @@ -119,15 +123,19 @@ exp_pkg_dispatch_group() { # Return: zero (0) on success, non-zero (>0) on failure, ${EXP_PKG_DISPATCH_NJOBS}, ${EXP_PKG_DISPATCH_COUNT}, ${EX_PKG_NAMES}, and ${EX_PKG_DISPATCH_WAIT} may be mutated post-return. # exp_pkg_dispatch_package() { - local _build_steps_default="${1}" _build_vars_default="${2}" _dispatch_fn="${3}" \ - _group_name="${4}" _pkg_name="${5}" _restart_at="${6}" _workdir="${7}"; - if "${_dispatch_fn}" start_pkg "${_group_name}" "${_pkg_name}" "$((${EXP_PKG_DISPATCH_COUNT}+1))" "${EXP_PKG_DISPATCH_COUNT_MAX}"; then + local _build_steps_default="${1}" _build_vars_default="${2}" _dispatch_fn="${3}"\ + _group_name="${4}" _pkg_name="${5}" _restart_at="${6}" _workdir="${7}"\ + _status_percentage="$((100 * ${EXP_PKG_DISPATCH_COUNT} + (${EXP_PKG_DISPATCH_COUNT_MAX} / 2)))"; + if [ "${_status_percentage}" -gt 0 ]; then + _status_percentage="$((${_status_percentage} / ${EXP_PKG_DISPATCH_COUNT_MAX}))"; + fi; + if "${_dispatch_fn}" start_pkg "${_group_name}" "${_pkg_name}" "$((${EXP_PKG_DISPATCH_COUNT}+1))" "${EXP_PKG_DISPATCH_COUNT_MAX}" "${_status_percentage}"; then : $((EXP_PKG_DISPATCH_NJOBS+=1)); : $((EXP_PKG_DISPATCH_COUNT+=1)); EX_PKG_DISPATCH_WAIT="$(rtl_lconcat "${EX_PKG_DISPATCH_WAIT}" "${_pkg_name}")"; - (trap "if [ \${?} -eq 0 ]; then \ - printf \"done %s %s\n\" \"${_group_name}\" \"${_pkg_name}\" >&3; \ - else \ - printf \"fail %s %s\n\" \"${_group_name}\" \"${_pkg_name}\" >&3; \ - pkill -U "${$}"; \ + (trap "if [ \${?} -eq 0 ]; then \ + printf \"done %s %s %d\n\" \"${_group_name}\" \"${_pkg_name}\" \"${EXP_PKG_DISPATCH_COUNT}\" >&3; \ + else \ + printf \"fail %s %s %d\n\" \"${_group_name}\" \"${_pkg_name}\" \"${EXP_PKG_DISPATCH_COUNT}\" >&3; \ + pkill -U "${$}"; \ fi;" EXIT HUP INT TERM USR1 USR2; set +o errexit -o noglob -o nounset; BUILD_IS_PARENT=0; rtl_log_set_fname ""; rtl_log_set_no_attr 1; if ex_pkg_env "${_build_steps_default}" "${_build_vars_default}" \