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 b96c60
	local _group_name="${1}" _pkg_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 907bd3
		_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 b96c60
		"${_dispatch_fn}" disabled_pkg "${_group_name}" "${_pkg_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 b96c60
		"${_dispatch_fn}" skipped_pkg "${_group_name}" "${_pkg_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 b96c60
		"${_dispatch_fn}" start_pkg "${_group_name}" "${_pkg_name}";
Lucio Andrés Illanes Albornoz (arab, vxp) a43dbf
		(set -o errexit -o noglob; BUILD_IS_PARENT=0;
Lucio Andrés Illanes Albornoz b96c60
		ex_pkg_env "${_group_name}" "${_pkg_name}" "${_restart_at}";
Lucio Andrés Illanes Albornoz b96c60
		ex_pkg_exec "${_group_name}" "${_pkg_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 b96c60
	local _group_name="${1}" _restart="${2}" _restart_at="${3}" _dispatch_fn="${4}" _pkgs_found_vname="${5}"\
Lucio Andrés Illanes Albornoz cc86a5
		_njob="" _njobs="" _njobs_max="" _pipe_msg="" _pipe_path="" _pkg_names="" _pkgs_found=""	\
Lucio Andrés Illanes Albornoz b96c60
		_pkgs_found_new="" _script_rc="" _stderrout_path="" _group_name_uc="";
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 b96c60
	_group_name_uc="$(ex_rtl_toupper "${_group_name}")";
Lucio Andrés Illanes Albornoz b96c60
	"${_dispatch_fn}" start_group "${_group_name}" "";
Lucio Andrés Illanes Albornoz b96c60
	_pkg_names="$(ex_rtl_get_var_unsafe ${_group_name_uc}_PACKAGES)";
Lucio Andrés Illanes Albornoz cc86a5
	if [ -n "${_restart}" ]\
Lucio Andrés Illanes Albornoz cc86a5
	&& ! ex_rtl_lmatch "ALL LAST" " " "${_restart}"; then
Lucio Andrés Illanes Albornoz cc86a5
		_pkg_names="$(ex_rtl_lfilter "${_pkg_names}" "${_restart}")";
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
	fi;
Lucio Andrés Illanes Albornoz b96c60
	if [ "$(ex_rtl_get_var_unsafe ${_group_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 8eb7cf
				_pkgs_found_new="${_pkgs_found_new:+${_pkgs_found_new} }${1}";
Lucio Andrés Illanes Albornoz b96c60
				exp_pkg_dispatch "${_group_name}" "${1}"				\
Lucio Andrés Illanes Albornoz b96c60
					"${_restart_at}" "${_dispatch_fn}"				\
Lucio Andrés Illanes Albornoz b96c60
					"${_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 df83d9
							_pkgs_found_new="${_pkgs_found_new:+${_pkgs_found_new} }${1}";
Lucio Andrés Illanes Albornoz b96c60
							exp_pkg_dispatch "${_group_name}" "${1}"	\
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 b96c60
	"${_dispatch_fn}" finish_group "${_group_name}" "";
Lucio Andrés Illanes Albornoz 00c762
	if [ -n "${_pkgs_found_vname}" ]; then
Lucio Andrés Illanes Albornoz 8eb7cf
		_pkgs_found="$(ex_rtl_get_var_unsafe "${_pkgs_found_vname}")";
Lucio Andrés Illanes Albornoz 8eb7cf
		ex_rtl_set_var_unsafe "${_pkgs_found_vname}" "${_pkgs_found:+${_pkgs_found} }${_pkgs_found_new}";
Lucio Andrés Illanes Albornoz 00c762
	fi;
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