Blame subr/ex_pkg_dispatch.subr

Lucio Andrés Illanes Albornoz (arab, vxp) 1da591
#
Lucio Andrés Illanes Albornoz (arab, vxp) 0185bc
# set -o noglob is assumed.
Lucio Andrés Illanes Albornoz (arab, vxp) 0185bc
# WARNING: ex_pkg_dispatch(), its caller, and its callers must _NOT_ be executed
Lucio Andrés Illanes Albornoz (arab, vxp) 0185bc
# as part of conditional evaluation, e.g. if, until, while, !, or && and ||, as
Lucio Andrés Illanes Albornoz (arab, vxp) 0185bc
# doing so would inhibit set -o errexit during execution of this function and its
Lucio Andrés Illanes Albornoz (arab, vxp) 0185bc
# subshell(!).  Instead, call ex_pkg_dispatch() and subsequently evaluate ${?}.
Lucio Andrés Illanes Albornoz (arab, vxp) 1da591
#
Lucio Andrés Illanes Albornoz (arab, vxp) 1da591
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
ex_pkg_dispatch() {
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	local _tgt_name="${1}" _restart="${2}" _restart_at="${3}"		\
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		_dispatch_fn="${4}" _tgt_name_uc				\
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		_pkg_names _pkg_name _pkg_name_uc				\
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		_pipe_path _stderrout_path _pipe_msg _script_rc;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	ex_rtl_fileop mkdir "${BUILD_WORKDIR}";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	_pipe_path="${BUILD_WORKDIR}/build.fifo";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	_tgt_name_uc="$(ex_rtl_toupper "${_tgt_name}")";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	"${_dispatch_fn}" start_target "" "${_tgt_name}";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	_pkg_names="$(ex_rtl_get_var_unsafe ${_tgt_name_uc}_PACKAGES)";
Lucio Andrés Illanes Albornoz (arab, vxp) 8227a8
	if [ -n "${_restart}" ]\
Lucio Andrés Illanes Albornoz (arab, vxp) 8227a8
	&& [ "${_restart}" != ALL ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		_pkg_names="$(ex_rtl_lfilter "${_pkg_names}" "${_restart}")";
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	for _pkg_name in ${_pkg_names}; do
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		_pkg_name_uc="$(ex_rtl_toupper "${_pkg_name}")";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		if [ -n "$(ex_rtl_get_var_unsafe PKG_${_pkg_name_uc}_DISABLED)" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			"${_dispatch_fn}" disabled_pkg "${_pkg_name}" "${_tgt_name}";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			continue;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		elif ex_pkg_state_test "${_pkg_name}" finish\
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		&& [ -z "${_restart_at}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			"${_dispatch_fn}" skipped_pkg "${_pkg_name}" "${_tgt_name}";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			continue;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		else
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			ex_rtl_fileop mkfifo "${_pipe_path}";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			_stderrout_path="${BUILD_WORKDIR}/${_pkg_name}_stderrout.log";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			_script_rc=1;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			"${_dispatch_fn}" start_pkg "${_pkg_name}" "${_tgt_name}";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		(set -o errexit -o noglob;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		ex_pkg_env "${_pkg_name}" "${_tgt_name}" "${_restart_at}";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		trap "if [ \${?} -eq 0 ]; then					\
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			echo \"done ${PKG_NAME}\" >&3;				\
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		      else							\
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			echo \"fail ${PKG_NAME}\" >&3;				\
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		      fi;" EXIT HUP INT TERM USR1 USR2;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		ex_pkg_exec "${_pkg_name}" "${_tgt_name}" "${_restart_at}"	\
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			"${_dispatch_fn}";) 1>"${_stderrout_path}" 2>&1 3>"${_pipe_path}" &
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		while read _pipe_msg; do
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		case "${_pipe_msg%% *}" in
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		done)	_script_rc=0;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			"${_dispatch_fn}" finish_pkg "${_pkg_name}" "${_tgt_name}";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			break; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		fail)	_script_rc=1;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			"${_dispatch_fn}" fail_pkg "${_pkg_name}" "${_tgt_name}";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			break; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		step)	"${_dispatch_fn}" step_pkg ${_pipe_msg#step }; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		*)	_script_rc=1;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			"${_dispatch_fn}" fail_pkg "${_pkg_name}" "${_tgt_name}";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			break; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		esac; done <"${_pipe_path}";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		ex_rtl_fileop rm "${_pipe_path}";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		if [ "${_script_rc:-1}" -eq 1 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			return 1;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	"${_dispatch_fn}" finish_target "" "${_tgt_name}";
Lucio Andrés Illanes Albornoz (arab, vxp) 1da591
};
Lucio Andrés Illanes Albornoz (arab, vxp) 1da591
Lucio Andrés Illanes Albornoz (arab, vxp) 1da591
# vim:filetype=sh