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 8a04de
exp_pkg_check_depends() {
Lucio Andrés Illanes Albornoz 9225a6
	local _group_name="${1}" _pkg_depends="${2}" _pkg_name="${3}" _dependfl=0;
Lucio Andrés Illanes Albornoz 1eec19
	if ! [ -n "${_restart}" ]\
Lucio Andrés Illanes Albornoz 8c791c
	|| [ "${ARG_RESTART_RECURSIVE:-0}" -eq 1 ]; then
Lucio Andrés Illanes Albornoz e310d7
		for _pkg_name_depend in ${_pkg_depends}; do
Lucio Andrés Illanes Albornoz e310d7
			if [ -n "$(ex_rtl_lsearch "${_pkgs_wait}" "${_pkg_name_depend}")" ]\
Lucio Andrés Illanes Albornoz e310d7
			|| [ -z "$(ex_rtl_lsearch "${_pkgs_complete}" "${_pkg_name_depend}")" ]; then
Lucio Andrés Illanes Albornoz e310d7
				_dependfl=1; break;
Lucio Andrés Illanes Albornoz e310d7
			fi;
Lucio Andrés Illanes Albornoz e310d7
		done;
Lucio Andrés Illanes Albornoz e310d7
	fi;
Lucio Andrés Illanes Albornoz 8a04de
	return "${_dependfl}";
Lucio Andrés Illanes Albornoz 8a04de
};
Lucio Andrés Illanes Albornoz 8a04de
Lucio Andrés Illanes Albornoz 8a04de
exp_pkg_dispatch_group() {
Lucio Andrés Illanes Albornoz 8a04de
	local _njob=0 _pkg_depends="" _pkg_name="";
Lucio Andrés Illanes Albornoz 8a04de
	for _njob in $(seq 1 $((${_njobs_max}-${_njobs}))); do
Lucio Andrés Illanes Albornoz 8a04de
		for _pkg_name in ${_pkg_names}; do
Lucio Andrés Illanes Albornoz 9225a6
			if [ -z "$(ex_rtl_lsearch "${_pkgs_complete}" "${_pkg_name}")" ]\
Lucio Andrés Illanes Albornoz 9225a6
			&& [ -z "$(ex_rtl_lsearch "${_pkgs_wait}" "${_pkg_name}")" ]\
Lucio Andrés Illanes Albornoz 8a04de
			&& _pkg_depends="$(exp_pkg_expand_packages $(ex_rtl_get_var_unsafe "PKG_$(ex_rtl_toupper "${_pkg_name}")_DEPENDS"))"\
Lucio Andrés Illanes Albornoz 9225a6
			&& exp_pkg_check_depends "${_group_name}" "${_pkg_depends}" "${_pkg_name}"	\
Lucio Andrés Illanes Albornoz 9225a6
			&& exp_pkg_dispatch_package "${_dispatch_fn}" "${_group_name}"			\
Lucio Andrés Illanes Albornoz ebda8b
					"${_pkg_name}" "${_restart}" "${_restart_at}"			\
Lucio Andrés Illanes Albornoz ebda8b
					"${_stderrout_path}" "${_pipe_path}"; then
Lucio Andrés Illanes Albornoz 8a04de
				_pkgs_found_new="${_pkgs_found_new:+${_pkgs_found_new} }${_pkg_name}";
Lucio Andrés Illanes Albornoz 8a04de
				break;
Lucio Andrés Illanes Albornoz 8a04de
			fi;
Lucio Andrés Illanes Albornoz 8a04de
		done;
Lucio Andrés Illanes Albornoz 8a04de
	done;
Lucio Andrés Illanes Albornoz 8a04de
};
Lucio Andrés Illanes Albornoz 8a04de
Lucio Andrés Illanes Albornoz 8a04de
exp_pkg_dispatch_package() {
Lucio Andrés Illanes Albornoz ebda8b
	local _dispatch_fn="${1}" _group_name="${2}" _pkg_name="${3}" _restart="${4}" _restart_at="${5}"	\
Lucio Andrés Illanes Albornoz ebda8b
		_stderrout_path="${6}" _pipe_path="${7}" _pkg_name_uc="" _rc=0;
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 fc9bdb
		_pkgs_complete="${_pkgs_complete:+${_pkgs_complete} }${_pkg_name}";
Lucio Andrés Illanes Albornoz 25e5b6
		_pkg_names="$(ex_rtl_lfilter "${_pkg_names}" "${_pkg_name}")";
Lucio Andrés Illanes Albornoz fc9bdb
		: $((_pkgs_count+=1)); _rc=1;
Lucio Andrés Illanes Albornoz fc9bdb
		"${_dispatch_fn}" disabled_pkg "${_group_name}" "${_pkg_name}" "${_pkgs_count}" "${_pkgs_count_max}";
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
	elif ex_pkg_state_test "${_pkg_name}" finish\
Lucio Andrés Illanes Albornoz ebda8b
	&& [ -z "$(ex_rtl_lsearch "${_restart}" "${_pkg_name}")" ]\
Lucio Andrés Illanes Albornoz ebda8b
	&& [ "${ARG_RESTART_RECURSIVE}" -ne 2 ]; then
Lucio Andrés Illanes Albornoz fc9bdb
		_pkgs_complete="${_pkgs_complete:+${_pkgs_complete} }${_pkg_name}";
Lucio Andrés Illanes Albornoz 25e5b6
		_pkg_names="$(ex_rtl_lfilter "${_pkg_names}" "${_pkg_name}")";
Lucio Andrés Illanes Albornoz fc9bdb
		: $((_pkgs_count+=1)); _rc=1;
Lucio Andrés Illanes Albornoz fc9bdb
		"${_dispatch_fn}" skipped_pkg "${_group_name}" "${_pkg_name}" "${_pkgs_count}" "${_pkgs_count_max}";
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
	else
Lucio Andrés Illanes Albornoz fc9bdb
		: $((_pkgs_count+=1)); _pkgs_wait="${_pkgs_wait:+${_pkgs_wait} }${_pkg_name}";
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
		_stderrout_path="${BUILD_WORKDIR}/${_pkg_name}_stderrout.log";
Lucio Andrés Illanes Albornoz fc9bdb
		"${_dispatch_fn}" start_pkg "${_group_name}" "${_pkg_name}" "${_pkgs_count}" "${_pkgs_count_max}";
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 ebda8b
		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 8a04de
		: $((_njobs+=1));
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
	fi;
Lucio Andrés Illanes Albornoz 8a04de
	return "${_rc}";
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
};
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
Lucio Andrés Illanes Albornoz 8a04de
exp_pkg_expand_packages() {
Lucio Andrés Illanes Albornoz 8a04de
	local _pkg_depends="" _pkg_name="" _pkg_names="";
Lucio Andrés Illanes Albornoz 8a04de
	for _pkg_name in "${@}"; do
Lucio Andrés Illanes Albornoz 8a04de
		_pkg_depends="$(ex_rtl_get_var_unsafe "PKG_$(ex_rtl_toupper "${_pkg_name}")_DEPENDS")";
Lucio Andrés Illanes Albornoz 8a04de
		if [ -n "${_pkg_depends}" ]; then
Lucio Andrés Illanes Albornoz 8a04de
			_pkg_depends="$(exp_pkg_expand_packages ${_pkg_depends})";
Lucio Andrés Illanes Albornoz 8a04de
			_pkg_names="${_pkg_names:+${_pkg_names} }${_pkg_depends} ${_pkg_name}";
Lucio Andrés Illanes Albornoz 8a04de
		else
Lucio Andrés Illanes Albornoz 8a04de
			_pkg_names="${_pkg_names:+${_pkg_names} }${_pkg_name}";
Lucio Andrés Illanes Albornoz 8a04de
		fi;
Lucio Andrés Illanes Albornoz 8a04de
	done;
Lucio Andrés Illanes Albornoz 8a04de
	echo "${_pkg_names}";
Lucio Andrés Illanes Albornoz 8a04de
};
Lucio Andrés Illanes Albornoz 8a04de
Lucio Andrés Illanes Albornoz 8a04de
exp_pkg_get_packages() {
Lucio Andrés Illanes Albornoz e310d7
	local _dispatch_fn="${1}" _group_name="${2}" _restart="${3}" _group_name_uc="";
Lucio Andrés Illanes Albornoz b96c60
	_group_name_uc="$(ex_rtl_toupper "${_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 8a04de
		_pkg_names="$(ex_rtl_lsearch "${_pkg_names}" "${_restart}")";
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
	fi;
Lucio Andrés Illanes Albornoz 1eec19
	if ! [ -n "${_restart}" ]\
Lucio Andrés Illanes Albornoz ebda8b
	|| [ "${ARG_RESTART_RECURSIVE:-0}" -ge 1 ]; then
Lucio Andrés Illanes Albornoz ebda8b
		ex_rtl_log_msg vnfo "Resolving \`${_group_name}' dependencies...";
Lucio Andrés Illanes Albornoz e310d7
		_pkg_names="$(ex_rtl_uniq $(exp_pkg_expand_packages ${_pkg_names}))";
Lucio Andrés Illanes Albornoz ebda8b
		ex_rtl_log_msg vnfo "Resolved \`${_group_name}' dependencies.";
Lucio Andrés Illanes Albornoz e310d7
	fi;
Lucio Andrés Illanes Albornoz 8a04de
};
Lucio Andrés Illanes Albornoz 8a04de
Lucio Andrés Illanes Albornoz 8a04de
ex_pkg_dispatch() {
Lucio Andrés Illanes Albornoz 8a04de
	local _group_name="${1}" _restart="${2}" _restart_at="${3}" _dispatch_fn="${4}" _pkgs_found_vname="${5}"	\
Lucio Andrés Illanes Albornoz 8a04de
		_njob="" _njobs=0 _njobs_max=1 _pipe_msg="" _pipe_path="${BUILD_WORKDIR}/build.fifo"			\
Lucio Andrés Illanes Albornoz fc9bdb
		_pkg_name="" _pkg_names="" _pkgs_complete="" _pkgs_count=0 _pkgs_count_max=0 _pkgs_found=""		\
Lucio Andrés Illanes Albornoz fc9bdb
		_pkgs_found_new="" _pkgs_wait="" _script_rc=0 _stderrout_path="";
Lucio Andrés Illanes Albornoz 8a04de
	"${_dispatch_fn}" start_group "${_group_name}" ""; ex_rtl_fileop mkdir "${BUILD_WORKDIR}";
Lucio Andrés Illanes Albornoz e310d7
	if exp_pkg_get_packages "${_dispatch_fn}" "${_group_name}" "${_restart}"\
Lucio Andrés Illanes Albornoz 8a04de
	&& [ -n "${_pkg_names}" ]; then
Lucio Andrés Illanes Albornoz fc9bdb
		for _pkg_name in ${_pkg_names}; do
Lucio Andrés Illanes Albornoz fc9bdb
			: $((_pkgs_count_max+=1));
Lucio Andrés Illanes Albornoz fc9bdb
		done;
Lucio Andrés Illanes Albornoz 8c791c
		if [ "${ARG_PARALLEL:-0}" -gt 1 ]; then
Lucio Andrés Illanes Albornoz 8a04de
			_njobs_max="${DEFAULT_BUILD_CPUS}";
Lucio Andrés Illanes Albornoz 8a04de
		fi;
Lucio Andrés Illanes Albornoz 8a04de
		ex_rtl_fileop mkfifo "${_pipe_path}"; exp_pkg_dispatch_group;
Lucio Andrés Illanes Albornoz 8a04de
		while [ "${_njobs:-0}" -gt 0 ]; do
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 fc9bdb
			done)	"${_dispatch_fn}" finish_pkg ${_pipe_msg#done };
Lucio Andrés Illanes Albornoz fc9bdb
				: $((_njobs-=1)); _pkg_name="${_pipe_msg#done * }";
Lucio Andrés Illanes Albornoz 8a04de
				_pkgs_complete="${_pkgs_complete:+${_pkgs_complete} }${_pkg_name}";
Lucio Andrés Illanes Albornoz 25e5b6
				_pkg_names="$(ex_rtl_lfilter "${_pkg_names}" "${_pkg_name}")";
Lucio Andrés Illanes Albornoz 8a04de
				_pkgs_wait="$(ex_rtl_lfilter "${_pkgs_wait}" "${_pkg_name}")";
Lucio Andrés Illanes Albornoz (arab, vxp) a68f6b
				if [ "${_script_rc:-0}" -eq 0 ]; then
Lucio Andrés Illanes Albornoz 8a04de
					exp_pkg_dispatch_group;
Lucio Andrés Illanes Albornoz (arab, vxp) a68f6b
				fi;
Lucio Andrés Illanes Albornoz 8a04de
				if [ "${_njobs}" -eq 0 ]\
Lucio Andrés Illanes Albornoz 8a04de
				&& [ -z "${_pkg_names}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
					break;
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
				fi; ;;
Lucio Andrés Illanes Albornoz fc9bdb
			fail)	_script_rc=1; "${_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 8a04de
		done;
Lucio Andrés Illanes Albornoz (arab, vxp) 807f5f
		ex_rtl_fileop rm "${_pipe_path}";
Lucio Andrés Illanes Albornoz 8a04de
	fi;
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 8a04de
	return "${_script_rc}";
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