Conan_Kudo / build / midipix_build

Forked from build/midipix_build 4 years ago
Clone

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) 7a258a
exp_pkg_dispatch() {
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
	local _pkg_name="${1}" _tgt_name="${2}" _restart_at="${3}"				\
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
		_dispatch_fn="${4}" _stderrout_path="${5}" _pipe_path="${6}"			\
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
		_njobs_vname="${7}" _pkg_name_uc;
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
	_pkg_name_uc="$(ex_rtl_toupper "${_pkg_name}")";
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
	if [ -n "$(ex_rtl_get_var_unsafe PKG_${_pkg_name_uc}_DISABLED)" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
		"${_dispatch_fn}" disabled_pkg "${_pkg_name}" "${_tgt_name}";
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
	elif ex_pkg_state_test "${_pkg_name}" finish\
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
	&& [ -z "${_restart_at}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
		"${_dispatch_fn}" skipped_pkg "${_pkg_name}" "${_tgt_name}";
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
	else
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
		_stderrout_path="${BUILD_WORKDIR}/${_pkg_name}_stderrout.log";
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
		"${_dispatch_fn}" start_pkg "${_pkg_name}" "${_tgt_name}";
Lucio Andrés Illanes Albornoz (arab, vxp) a43dbf
		(set -o errexit -o noglob; BUILD_IS_PARENT=0;
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
		ex_pkg_env "${_pkg_name}" "${_tgt_name}" "${_restart_at}";
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
		ex_pkg_exec "${_pkg_name}" "${_tgt_name}" "${_restart_at}"			\
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
			"${_dispatch_fn}";) 1>"${_stderrout_path}" 2>&1 3>"${_pipe_path}" &
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
		: $((${_njobs_vname}+=1));
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
};
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
ex_pkg_dispatch() {
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
	local _tgt_name="${1}" _restart="${2}" _restart_at="${3}"				\
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
		_dispatch_fn="${4}" _tgt_name_uc						\
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
		_pkg_names _njob _njobs _njobs_max						\
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) cbc8e0
	if [ "$(ex_rtl_get_var_unsafe ${_tgt_name_uc}_PARALLELISE)" = 1 ]\
Lucio Andrés Illanes Albornoz (arab, vxp) cbc8e0
	&& [ "${ARG_PARALLEL:-0}" -gt 1 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
		_njobs_max="${DEFAULT_BUILD_CPUS}";
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
	else
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
		_njobs_max=1;
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 807f5f
	set -- ${_pkg_names};
Lucio Andrés Illanes Albornoz (arab, vxp) 807f5f
	while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 807f5f
		_script_rc=0; _njobs=0;
Lucio Andrés Illanes Albornoz (arab, vxp) 807f5f
		ex_rtl_fileop mkfifo "${_pipe_path}";
Lucio Andrés Illanes Albornoz (arab, vxp) 44d0b3
		for _njob in $(seq 1 $((${_njobs_max}-${_njobs}))); do
Lucio Andrés Illanes Albornoz (arab, vxp) 44d0b3
			if [ ${#} -eq 0 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 44d0b3
				break;
Lucio Andrés Illanes Albornoz (arab, vxp) 44d0b3
			else
Lucio Andrés Illanes Albornoz (arab, vxp) 44d0b3
				exp_pkg_dispatch "${1}" "${_tgt_name}"				\
Lucio Andrés Illanes Albornoz (arab, vxp) 44d0b3
					"${_restart_at}" "${_dispatch_fn}"			\
Lucio Andrés Illanes Albornoz (arab, vxp) 44d0b3
					"${_stderrout_path}" "${_pipe_path}"			\
Lucio Andrés Illanes Albornoz (arab, vxp) 44d0b3
					_njobs; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 44d0b3
			fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 44d0b3
		done;
Lucio Andrés Illanes Albornoz (arab, vxp) 807f5f
		if [ "${_njobs:-0}" -gt 0 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 807f5f
			while read _pipe_msg; do
Lucio Andrés Illanes Albornoz (arab, vxp) 807f5f
			case "${_pipe_msg%% *}" in
Lucio Andrés Illanes Albornoz (arab, vxp) 807f5f
			done)	"${_dispatch_fn}" finish_pkg ${_pipe_msg#done };
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
				: $((_njobs-=1));
Lucio Andrés Illanes Albornoz (arab, vxp) a68f6b
				if [ "${_script_rc:-0}" -eq 0 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) a68f6b
					for _njob in $(seq 1 $((${_njobs_max}-${_njobs}))); do
Lucio Andrés Illanes Albornoz (arab, vxp) a68f6b
						if [ ${#} -eq 0 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) a68f6b
							break;
Lucio Andrés Illanes Albornoz (arab, vxp) a68f6b
						else
Lucio Andrés Illanes Albornoz (arab, vxp) a68f6b
							exp_pkg_dispatch "${1}" "${_tgt_name}"		\
Lucio Andrés Illanes Albornoz (arab, vxp) a68f6b
								"${_restart_at}" "${_dispatch_fn}"	\
Lucio Andrés Illanes Albornoz (arab, vxp) a68f6b
								"${_stderrout_path}" "${_pipe_path}"	\
Lucio Andrés Illanes Albornoz (arab, vxp) a68f6b
								_njobs; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) a68f6b
						fi;
Lucio Andrés Illanes Albornoz (arab, vxp) a68f6b
					done;
Lucio Andrés Illanes Albornoz (arab, vxp) a68f6b
				fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
				if [ "${_njobs:-0}" -eq 0 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
					break;
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
				fi; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 807f5f
			fail)	_script_rc=1;
Lucio Andrés Illanes Albornoz (arab, vxp) 807f5f
				"${_dispatch_fn}" fail_pkg ${_pipe_msg#fail };
Lucio Andrés Illanes Albornoz (arab, vxp) 807f5f
				[ $((_njobs-=1)) -eq 0 ] && break; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 4b9285
			step)	"${_dispatch_fn}" step_pkg ${_pipe_msg#step }; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 4b9285
			esac; done <>"${_pipe_path}";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 807f5f
		ex_rtl_fileop rm "${_pipe_path}";
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
		if [ "${_script_rc:-1}" -eq 1 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
			return "${_script_rc}";
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
		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