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 2b85d0
# set +o errexit -o noglob is assumed.
Lucio Andrés Illanes Albornoz (arab, vxp) 1da591
#
Lucio Andrés Illanes Albornoz (arab, vxp) 1da591
Lucio Andrés Illanes Albornoz 2b85d0
#
Lucio Andrés Illanes Albornoz 2b85d0
# exp_pkg_check_depends() - check single named package for unsatisfied dependencies
Lucio Andrés Illanes Albornoz 2b85d0
# @_pkg_complete:	list of completed packages
Lucio Andrés Illanes Albornoz 2b85d0
# @_pkg_name:		single package name
Lucio Andrés Illanes Albornoz 2b85d0
# @_pkg_wait:		list of in-progress packages
Lucio Andrés Illanes Albornoz 2b85d0
# @_restart_recursive:	optional flag specifiying either no dependency expansion (0,) dependency expansion (1,) dependency expansion and forcibly rebuild (2.)
Lucio Andrés Illanes Albornoz 2b85d0
#
Lucio Andrés Illanes Albornoz 2b85d0
# Return:		zero (0) given no outstanding dependencies, non-zero (>0) otherwise
Lucio Andrés Illanes Albornoz 2b85d0
#
Lucio Andrés Illanes Albornoz 8a04de
exp_pkg_check_depends() {
Lucio Andrés Illanes Albornoz 2b85d0
	local	_pkg_complete="${1}" _pkg_name="${2}" _pkg_wait="${3}" _restart_recursive="${4}"	\
Lucio Andrés Illanes Albornoz 2b85d0
		_pkg_depends="" _pkg_name_depend="" _dependfl=0;
Lucio Andrés Illanes Albornoz 2b85d0
	if _pkg_depends="$(exp_pkg_expand_depends $(ex_rtl_get_var_unsafe -u "PKG_"${_pkg_name}"_DEPENDS"))"\
Lucio Andrés Illanes Albornoz 2b85d0
	&& [ -n "${_pkg_depends}" ]\
Lucio Andrés Illanes Albornoz 2b85d0
	&& ! [ -n "${_restart}" ] || [ "${_restart_recursive:-0}" -ge 1 ]; then
Lucio Andrés Illanes Albornoz e310d7
		for _pkg_name_depend in ${_pkg_depends}; do
Lucio Andrés Illanes Albornoz 2b85d0
			if ! ex_rtl_lmatch "${_pkg_complete}" "${_pkg_name_depend}"\
Lucio Andrés Illanes Albornoz 2b85d0
			|| ex_rtl_lmatch "${_pkg_wait}" "${_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 2b85d0
#
Lucio Andrés Illanes Albornoz 2b85d0
# exp_pkg_dispatch_package() - dispatch single named packages
Lucio Andrés Illanes Albornoz 2b85d0
# @_dispatch_fn:	top-level dispatch function name
Lucio Andrés Illanes Albornoz 2b85d0
# @_group_name:		build group name
Lucio Andrés Illanes Albornoz 2b85d0
# @_pkg_name:		single package name
Lucio Andrés Illanes Albornoz 2b85d0
# @_restart_at:		optional comma-separated list of build steps at which to rebuild or ALL
Lucio Andrés Illanes Albornoz 2b85d0
#
Lucio Andrés Illanes Albornoz 2b85d0
# Return:		zero (0) on success, non-zero (>0) on failure, ${NJOBS}, ${PKG_COUNT}, ${PKG_NAMES}, and ${PKG_WAIT} may be mutated post-return.
Lucio Andrés Illanes Albornoz 2b85d0
#
Lucio Andrés Illanes Albornoz 8a04de
exp_pkg_dispatch_package() {
Lucio Andrés Illanes Albornoz 2b85d0
	local _dispatch_fn="${1}" _group_name="${2}" _pkg_name="${3}" _restart_at="${4}";
Lucio Andrés Illanes Albornoz 2b85d0
	if "${_dispatch_fn}" start_pkg "${_group_name}" "${_pkg_name}" "$((${PKG_COUNT}+1))" "${PKG_COUNT_MAX}"; then
Lucio Andrés Illanes Albornoz 2b85d0
		: $((NJOBS+=1)); : $((PKG_COUNT+=1)); PKG_WAIT="$(ex_rtl_lconcat "${PKG_WAIT}" "${_pkg_name}")";
Lucio Andrés Illanes Albornoz 2b85d0
		(set +o errexit -o noglob; BUILD_IS_PARENT=0;
Lucio Andrés Illanes Albornoz 2b85d0
		if ex_pkg_env "${_group_name}" "${_pkg_name}" "${_restart_at}"; then
Lucio Andrés Illanes Albornoz 2b85d0
			ex_pkg_exec "${_dispatch_fn}" "${_group_name}" "${_pkg_name}" "${_restart_at}";
Lucio Andrés Illanes Albornoz 2b85d0
		else
Lucio Andrés Illanes Albornoz 2b85d0
			return "${?}";
Lucio Andrés Illanes Albornoz 2b85d0
		fi;) 1>"${BUILD_WORKDIR}/${_pkg_name}_stderrout.log" 2>&1 3>"${_pipe_path}" &
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
	else
Lucio Andrés Illanes Albornoz 2b85d0
		return "${?}";
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 2b85d0
#
Lucio Andrés Illanes Albornoz 2b85d0
# exp_pkg_dispatch_packages() - dispatch set of packages
Lucio Andrés Illanes Albornoz 2b85d0
# @_dispatch_fn:	top-level dispatch function name
Lucio Andrés Illanes Albornoz 2b85d0
# @_group_name:		build group name
Lucio Andrés Illanes Albornoz 2b85d0
# @_njobs_max:		maximum count of simultaneous jobs
Lucio Andrés Illanes Albornoz 2b85d0
# @_pipe_path:		pathname to parent-child process FIFO
Lucio Andrés Illanes Albornoz 2b85d0
# @_pkg_complete:	list of completed packages
Lucio Andrés Illanes Albornoz 2b85d0
# @_restart_at:		optional comma-separated list of build steps at which to rebuild or ALL
Lucio Andrés Illanes Albornoz 2b85d0
# @_restart_recursive:	optional flag specifiying either no dependency expansion (0,) dependency expansion (1,) dependency expansion and forcibly rebuild (2.)
Lucio Andrés Illanes Albornoz 2b85d0
#
Lucio Andrés Illanes Albornoz 2b85d0
# Return:		zero (0) on success, non-zero (>0) on failure, ${NJOBS}, ${PKG_COUNT}, ${PKG_NAMES}, and ${PKG_WAIT} may be mutated post-return.
Lucio Andrés Illanes Albornoz 2b85d0
#
Lucio Andrés Illanes Albornoz 2b85d0
exp_pkg_dispatch_packages() {
Lucio Andrés Illanes Albornoz 2b85d0
	local	_dispatch_fn="${1}" _group_name="${2}" _njobs_max="${3}" _pipe_path="${4}"		\
Lucio Andrés Illanes Albornoz 2b85d0
		_pkg_complete="${5}" _restart_at="${6}" _restart_recursive="${7}"			\
Lucio Andrés Illanes Albornoz 2b85d0
		_njob=0 _pkg_depends="" _pkg_name="";
Lucio Andrés Illanes Albornoz 2b85d0
	for _njob in $(seq 1 $((${_njobs_max}-${NJOBS}))); do
Lucio Andrés Illanes Albornoz 2b85d0
		for _pkg_name in ${PKG_NAMES}; do
Lucio Andrés Illanes Albornoz 2b85d0
			if ! ex_rtl_lmatch "${_pkg_complete}" "${_pkg_name}"\
Lucio Andrés Illanes Albornoz 2b85d0
			&& ! ex_rtl_lmatch "${PKG_WAIT}" "${_pkg_name}"\
Lucio Andrés Illanes Albornoz 2b85d0
			&& exp_pkg_check_depends "${_pkg_complete}" "${_pkg_name}" "${PKG_WAIT}" "${_restart_recursive}"; then
Lucio Andrés Illanes Albornoz 2b85d0
				exp_pkg_dispatch_package "${_dispatch_fn}" "${_group_name}" "${_pkg_name}" "${_restart_at}"; break;
Lucio Andrés Illanes Albornoz 2b85d0
			fi;
Lucio Andrés Illanes Albornoz 2b85d0
		done;
Lucio Andrés Illanes Albornoz 2b85d0
	done;
Lucio Andrés Illanes Albornoz 2b85d0
};
Lucio Andrés Illanes Albornoz 2b85d0
Lucio Andrés Illanes Albornoz 2b85d0
#
Lucio Andrés Illanes Albornoz 2b85d0
# exp_pkg_expand_depends() - expand list of package names to amended and ordered list according to dependency constraints
Lucio Andrés Illanes Albornoz 2b85d0
# @${@}:		list of package names
Lucio Andrés Illanes Albornoz 2b85d0
#
Lucio Andrés Illanes Albornoz 2b85d0
# Return:		zero (0) on success, non-zero (>0) on failure, list of packages on stdout
Lucio Andrés Illanes Albornoz 2b85d0
#
Lucio Andrés Illanes Albornoz 2b85d0
exp_pkg_expand_depends() {
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 2b85d0
		if _pkg_depends="$(ex_rtl_get_var_unsafe -u "PKG_${_pkg_name}_DEPENDS")"\
Lucio Andrés Illanes Albornoz 2b85d0
		&& [ -n "${_pkg_depends}" ]; then
Lucio Andrés Illanes Albornoz 2b85d0
			_pkg_depends="$(exp_pkg_expand_depends ${_pkg_depends})";
Lucio Andrés Illanes Albornoz 2b85d0
			_pkg_names="$(ex_rtl_lconcat "${_pkg_names}" "${_pkg_depends}")";
Lucio Andrés Illanes Albornoz 8a04de
		fi;
Lucio Andrés Illanes Albornoz 2b85d0
		_pkg_names="$(ex_rtl_lconcat "${_pkg_names}" "${_pkg_name}")";
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 2b85d0
#
Lucio Andrés Illanes Albornoz 2b85d0
# exp_pkg_expand_packages() - expand build group name to list of packages ordered and filtered according to dependency and restart constraints
Lucio Andrés Illanes Albornoz 2b85d0
# @_group_name:		build group name
Lucio Andrés Illanes Albornoz 2b85d0
# @_restart:		optional comma-separated list of package names to rebuild
Lucio Andrés Illanes Albornoz 2b85d0
# @_restart_recursive:	optional flag specifiying either no dependency expansion (0,) dependency expansion (1,) dependency expansion and forcibly rebuild (2.)
Lucio Andrés Illanes Albornoz 2b85d0
#
Lucio Andrés Illanes Albornoz 2b85d0
# Return:		zero (0) on success, non-zero (>0) on failure, ${EX_PKG_NSKIPPED}, ${EX_PKG_NAMES}, and ${PKG_COMPLETE} set post-return.
Lucio Andrés Illanes Albornoz 2b85d0
#
Lucio Andrés Illanes Albornoz 2b85d0
exp_pkg_expand_packages() {
Lucio Andrés Illanes Albornoz 2b85d0
	local _group_name="${1}" _restart="${2}" _restart_recursive="${3}" _pkg_name="" _pkg_names="";
Lucio Andrés Illanes Albornoz 2b85d0
	if _pkg_names="$(ex_rtl_get_var_unsafe -u "${_group_name}_PACKAGES")"\
Lucio Andrés Illanes Albornoz 2b85d0
	&& [ -n "${_pkg_names}" ]; then
Lucio Andrés Illanes Albornoz 2b85d0
		if [ -n "${_restart}" ] && ! ex_rtl_lmatch "${_restart}" "ALL LAST"; then
Lucio Andrés Illanes Albornoz 2b85d0
			_pkg_names="$(ex_rtl_lsearch "${_pkg_names}" "${_restart}")";
Lucio Andrés Illanes Albornoz 2b85d0
		fi;
Lucio Andrés Illanes Albornoz 2b85d0
		if ! [ -n "${_restart}" ] || [ "${_restart_recursive:-0}" -ge 1 ]; then
Lucio Andrés Illanes Albornoz 2b85d0
			_pkg_names="$(ex_rtl_uniq $(exp_pkg_expand_depends ${_pkg_names}))";
Lucio Andrés Illanes Albornoz 2b85d0
		fi;
Lucio Andrés Illanes Albornoz 2b85d0
		for _pkg_name in ${_pkg_names}; do
Lucio Andrés Illanes Albornoz 2b85d0
			if [ -n "$(ex_rtl_get_var_unsafe -u "PKG_${_pkg_name}_DISABLED")" ]; then
Lucio Andrés Illanes Albornoz 2b85d0
				PKG_COMPLETE="$(ex_rtl_lconcat "${PKG_COMPLETE}" "${_pkg_name}")";
Lucio Andrés Illanes Albornoz 2b85d0
				: $((EX_PKG_NSKIPPED+=1)); _pkg_names="$(ex_rtl_lfilter "${_pkg_names}" "${_pkg_name}")";
Lucio Andrés Illanes Albornoz 2b85d0
			elif ex_pkg_state_test "${_pkg_name}" finish\
Lucio Andrés Illanes Albornoz 2b85d0
			&& ! ex_rtl_lmatch "${_restart}" "${_pkg_name}"\
Lucio Andrés Illanes Albornoz 2b85d0
			&& [ "${_restart_recursive:-0}" -ne 2 ]; then
Lucio Andrés Illanes Albornoz 2b85d0
				PKG_COMPLETE="$(ex_rtl_lconcat "${PKG_COMPLETE}" "${_pkg_name}")";
Lucio Andrés Illanes Albornoz 2b85d0
				: $((EX_PKG_NSKIPPED+=1)); _pkg_names="$(ex_rtl_lfilter "${_pkg_names}" "${_pkg_name}")";
Lucio Andrés Illanes Albornoz 2b85d0
			fi;
Lucio Andrés Illanes Albornoz 2b85d0
		done;
Lucio Andrés Illanes Albornoz 2b85d0
		EX_PKG_NAMES="${_pkg_names}"; return 0;
Lucio Andrés Illanes Albornoz e310d7
	fi;
Lucio Andrés Illanes Albornoz 8a04de
};
Lucio Andrés Illanes Albornoz 8a04de
Lucio Andrés Illanes Albornoz 2b85d0
#
Lucio Andrés Illanes Albornoz 2b85d0
# ex_pkg_dispatch() - dispatch a single build group
Lucio Andrés Illanes Albornoz 2b85d0
# @_dispatch_fn:	top-level dispatch function name
Lucio Andrés Illanes Albornoz 2b85d0
# @_group_name:		build group name
Lucio Andrés Illanes Albornoz 2b85d0
# @_njobs_max:		maximum count of simultaneous jobs
Lucio Andrés Illanes Albornoz 2b85d0
# @_restart:		optional comma-separated list of package names to rebuild
Lucio Andrés Illanes Albornoz 2b85d0
# @_restart_at:		optional comma-separated list of build steps at which to rebuild or ALL
Lucio Andrés Illanes Albornoz 2b85d0
# @_restart_recursive:	optional flag specifiying either no dependency expansion (0,) dependency expansion (1,) dependency expansion and forcibly rebuild (2.)
Lucio Andrés Illanes Albornoz 2b85d0
#
Lucio Andrés Illanes Albornoz 2b85d0
# Return:		zero (0) on success, non-zero (>0) on failure, ${EX_PKG_NAMES} and ${EX_PKG_NSKIPPED} set post-return.
Lucio Andrés Illanes Albornoz 2b85d0
#
Lucio Andrés Illanes Albornoz 8a04de
ex_pkg_dispatch() {
Lucio Andrés Illanes Albornoz 2b85d0
	local	_dispatch_fn="${1}" _group_name="${2}" _njobs_max="${3}" _restart="${4}" _restart_at="${5}"			\
Lucio Andrés Illanes Albornoz 2b85d0
		_restart_recursive="${6}" _pipe_msg="" _pipe_path="${BUILD_WORKDIR}/build.fifo" _pkg_name=""			\
Lucio Andrés Illanes Albornoz 2b85d0
		_script_rc=0 NJOBS=0 PKG_COMPLETE="" PKG_COUNT=0 PKG_COUNT_MAX=0 PKG_NAMES="" PKG_WAIT=""; EX_PKG_NSKIPPED=0; EX_PKG_NAMES="";
Lucio Andrés Illanes Albornoz 2b85d0
	if "${_dispatch_fn}" start_group "${_group_name}" ""; then
Lucio Andrés Illanes Albornoz 2b85d0
		if ex_rtl_fileop mkdir "${BUILD_WORKDIR}"\
Lucio Andrés Illanes Albornoz 2b85d0
		&& ex_rtl_log_msg vnfo "Resolving \`${_group_name}' dependencies..."\
Lucio Andrés Illanes Albornoz 2b85d0
		&& exp_pkg_expand_packages "${_group_name}" "${_restart}" "${_restart_recursive}"\
Lucio Andrés Illanes Albornoz 2b85d0
		&& ex_rtl_log_msg vnfo "Resolved \`${_group_name}' dependencies."\
Lucio Andrés Illanes Albornoz 2b85d0
		&& PKG_COUNT_MAX="$(ex_rtl_llength "${EX_PKG_NAMES}")"\
Lucio Andrés Illanes Albornoz 2b85d0
		&& [ "${PKG_COUNT_MAX}" -gt 0 ]; then
Lucio Andrés Illanes Albornoz 2b85d0
			PKG_NAMES="${EX_PKG_NAMES}"; ex_rtl_fileop mkfifo "${_pipe_path}";
Lucio Andrés Illanes Albornoz 2b85d0
			while true; do
Lucio Andrés Illanes Albornoz 2b85d0
				while [ "${NJOBS:-0}" -gt 0 ] && read _pipe_msg; do
Lucio Andrés Illanes Albornoz 2b85d0
				case "${_pipe_msg%% *}" in
Lucio Andrés Illanes Albornoz 2b85d0
				done)	: $((NJOBS-=1)); _pkg_name="${_pipe_msg#done * }";
Lucio Andrés Illanes Albornoz 2b85d0
					"${_dispatch_fn}" finish_pkg ${_pipe_msg#done };
Lucio Andrés Illanes Albornoz 2b85d0
					PKG_COMPLETE="$(ex_rtl_lconcat "${PKG_COMPLETE}" "${_pkg_name}")";
Lucio Andrés Illanes Albornoz 2b85d0
					PKG_NAMES="$(ex_rtl_lfilter "${PKG_NAMES}" "${_pkg_name}")";
Lucio Andrés Illanes Albornoz 2b85d0
					PKG_WAIT="$(ex_rtl_lfilter "${PKG_WAIT}" "${_pkg_name}")";
Lucio Andrés Illanes Albornoz 2b85d0
					if [ -n "${PKG_NAMES}" ] && [ "${_script_rc}" -eq 0 ]; then
Lucio Andrés Illanes Albornoz 2b85d0
						if [ "${NJOBS}" -ne "${_njobs_max}" ]; then
Lucio Andrés Illanes Albornoz 2b85d0
							exp_pkg_dispatch_packages "${_dispatch_fn}" "${_group_name}" "${_njobs_max}"	\
Lucio Andrés Illanes Albornoz 2b85d0
								"${_pipe_path}" "${PKG_COMPLETE}" "${_restart_at}" "${_restart_recursive}";
Lucio Andrés Illanes Albornoz 2b85d0
						fi;
Lucio Andrés Illanes Albornoz 2b85d0
					elif [ "${NJOBS:-0}" -eq 0 ]; then
Lucio Andrés Illanes Albornoz 2b85d0
						break;
Lucio Andrés Illanes Albornoz 2b85d0
					fi; ;;
Lucio Andrés Illanes Albornoz 2b85d0
				fail)	: $((NJOBS-=1)); _script_rc=1;
Lucio Andrés Illanes Albornoz 2b85d0
					"${_dispatch_fn}" fail_pkg ${_pipe_msg#fail }; ;;
Lucio Andrés Illanes Albornoz 2b85d0
				step)	"${_dispatch_fn}" step_pkg ${_pipe_msg#step }; ;;
Lucio Andrés Illanes Albornoz 2b85d0
				esac; done <>"${_pipe_path}";
Lucio Andrés Illanes Albornoz 2b85d0
				if [ -n "${PKG_NAMES}" ] && [ "${_script_rc}" -eq 0 ]; then
Lucio Andrés Illanes Albornoz 2b85d0
					if [ "${NJOBS}" -ne "${_njobs_max}" ]; then
Lucio Andrés Illanes Albornoz 2b85d0
						exp_pkg_dispatch_packages "${_dispatch_fn}" "${_group_name}" "${_njobs_max}"	\
Lucio Andrés Illanes Albornoz 2b85d0
							"${_pipe_path}" "${PKG_COMPLETE}" "${_restart_at}" "${_restart_recursive}";
Lucio Andrés Illanes Albornoz 2b85d0
					fi;
Lucio Andrés Illanes Albornoz 2b85d0
				elif [ "${NJOBS:-0}" -eq 0 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 7a258a
					break;
Lucio Andrés Illanes Albornoz 2b85d0
				fi;
Lucio Andrés Illanes Albornoz 2b85d0
			done;
Lucio Andrés Illanes Albornoz 2b85d0
			ex_rtl_fileop rm "${_pipe_path}";
Lucio Andrés Illanes Albornoz 2b85d0
		fi;
Lucio Andrés Illanes Albornoz 2b85d0
		"${_dispatch_fn}" finish_group "${_group_name}" "";
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 2b85d0
# vim:filetype=sh textwidth=0