Lucio Andrés Illanes Albornoz c6d6e0
#
Lucio Andrés Illanes Albornoz c6d6e0
# set +o errexit -o noglob is assumed.
Lucio Andrés Illanes Albornoz c6d6e0
#
Lucio Andrés Illanes Albornoz c6d6e0
Lucio Andrés Illanes Albornoz c6d6e0
#
Lucio Andrés Illanes Albornoz c6d6e0
# ex_pkg_check_depends() - check single named package for unsatisfied dependencies
Lucio Andrés Illanes Albornoz c6d6e0
# @_pkg_complete:	list of completed packages
Lucio Andrés Illanes Albornoz c6d6e0
# @_pkg_name:		single package name
Lucio Andrés Illanes Albornoz c6d6e0
# @_pkg_wait:		list of in-progress packages
Lucio Andrés Illanes Albornoz c6d6e0
# @_restart_recursive:	optional flag specifiying either no dependency expansion (0,) dependency expansion (1,) dependency expansion and forcibly rebuild (2.)
Lucio Andrés Illanes Albornoz c6d6e0
#
Lucio Andrés Illanes Albornoz c6d6e0
# Return:		zero (0) given no outstanding dependencies, non-zero (>0) otherwise
Lucio Andrés Illanes Albornoz c6d6e0
#
Lucio Andrés Illanes Albornoz c6d6e0
ex_pkg_check_depends() {
Lucio Andrés Illanes Albornoz c6d6e0
	local	_pkg_complete="${1}" _pkg_name="${2}" _pkg_wait="${3}" _restart_recursive="${4}"	\
Lucio Andrés Illanes Albornoz c6d6e0
		_pkg_depends="" _pkg_name_depend="" _dependfl=0;
Lucio Andrés Illanes Albornoz c6d6e0
	if _pkg_depends="$(rtl_lunfold_depends 'PKG_${_name}_DEPENDS' $(rtl_get_var_unsafe -u "PKG_"${_pkg_name}"_DEPENDS"))"\
Lucio Andrés Illanes Albornoz c6d6e0
	&& [ -n "${_pkg_depends}" ]\
Lucio Andrés Illanes Albornoz c6d6e0
	&& ! [ -n "${_restart}" ] || [ "${_restart_recursive:-0}" -ge 1 ]; then
Lucio Andrés Illanes Albornoz c6d6e0
		for _pkg_name_depend in $(rtl_uniq ${_pkg_depends}); do
Lucio Andrés Illanes Albornoz c6d6e0
			if ! rtl_lmatch "${_pkg_complete}" "${_pkg_name_depend}"\
Lucio Andrés Illanes Albornoz c6d6e0
			|| rtl_lmatch "${_pkg_wait}" "${_pkg_name_depend}"; then
Lucio Andrés Illanes Albornoz c6d6e0
				_dependfl=1; break;
Lucio Andrés Illanes Albornoz c6d6e0
			fi;
Lucio Andrés Illanes Albornoz c6d6e0
		done;
Lucio Andrés Illanes Albornoz c6d6e0
	fi;
Lucio Andrés Illanes Albornoz c6d6e0
	return "${_dependfl}";
Lucio Andrés Illanes Albornoz c6d6e0
};
Lucio Andrés Illanes Albornoz c6d6e0
Lucio Andrés Illanes Albornoz c6d6e0
#
Lucio Andrés Illanes Albornoz c6d6e0
# ex_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 c6d6e0
# @_group_name:		build group name
Lucio Andrés Illanes Albornoz c6d6e0
# @_restart:		optional comma-separated list of package names to rebuild
Lucio Andrés Illanes Albornoz c6d6e0
# @_restart_recursive:	optional flag specifiying either no dependency expansion (0,) dependency expansion (1,) dependency expansion and forcibly rebuild (2.)
Lucio Andrés Illanes Albornoz c6d6e0
#
Lucio Andrés Illanes Albornoz c6d6e0
# Return:		zero (0) on success, non-zero (>0) on failure, ${EXP_PKG_COMPLETE}, ${EXP_PKG_DISABLED}, ${EXP_PKG_FINISHED}, and ${EXP_PKG_NAMES} set post-return.
Lucio Andrés Illanes Albornoz c6d6e0
#
Lucio Andrés Illanes Albornoz c6d6e0
ex_pkg_expand_packages() {
Lucio Andrés Illanes Albornoz c6d6e0
	local	_group_name="${1}" _restart="${2}" _restart_recursive="${3}"	\
Lucio Andrés Illanes Albornoz c6d6e0
		_pkg_name="" _pkg_names="" _restart_check=0;
Lucio Andrés Illanes Albornoz c6d6e0
	EXP_PKG_COMPLETE=""; EXP_PKG_DISABLED=""; EXP_PKG_FINISHED=""; EXP_PKG_NAMES="";
Lucio Andrés Illanes Albornoz c6d6e0
	if _pkg_names="$(rtl_get_var_unsafe -u "${_group_name}_PACKAGES")"\
Lucio Andrés Illanes Albornoz c6d6e0
	&& [ -n "${_pkg_names}" ]; then
Lucio Andrés Illanes Albornoz c6d6e0
		if [ -n "${_restart}" ] && ! rtl_lmatch "${_restart}" "ALL LAST"; then
Lucio Andrés Illanes Albornoz c6d6e0
			_pkg_names="$(rtl_lsearch "${_pkg_names}" "${_restart}")";
Lucio Andrés Illanes Albornoz c6d6e0
		fi;
Lucio Andrés Illanes Albornoz c6d6e0
		if ! [ -n "${_restart}" ] || [ "${_restart_recursive:-0}" -ge 1 ]; then
Lucio Andrés Illanes Albornoz c6d6e0
			_pkg_names="$(rtl_uniq $(rtl_lunfold_depends 'PKG_${_name}_DEPENDS' ${_pkg_names}))";
Lucio Andrés Illanes Albornoz c6d6e0
		fi;
Lucio Andrés Illanes Albornoz c6d6e0
		for _pkg_name in ${_pkg_names}; do
Lucio Andrés Illanes Albornoz c6d6e0
			if [ "${_restart}" = "ALL" ]\
Lucio Andrés Illanes Albornoz c6d6e0
			|| rtl_lmatch "${_restart}" "${_pkg_name}"; then
Lucio Andrés Illanes Albornoz c6d6e0
				_restart_check=1;
Lucio Andrés Illanes Albornoz c6d6e0
			else
Lucio Andrés Illanes Albornoz c6d6e0
				_restart_check=0;
Lucio Andrés Illanes Albornoz c6d6e0
			fi;
Lucio Andrés Illanes Albornoz c6d6e0
			if [ -n "$(rtl_get_var_unsafe -u "PKG_${_pkg_name}_DISABLED")" ]; then
Lucio Andrés Illanes Albornoz c6d6e0
				EXP_PKG_COMPLETE="$(rtl_lconcat "${EXP_PKG_COMPLETE}" "${_pkg_name}")";
Lucio Andrés Illanes Albornoz c6d6e0
				EXP_PKG_DISABLED="$(rtl_lconcat "${EXP_PKG_DISABLED}" "${_pkg_name}")";
Lucio Andrés Illanes Albornoz c6d6e0
				_pkg_names="$(rtl_lfilter "${_pkg_names}" "${_pkg_name}")";
Lucio Andrés Illanes Albornoz c6d6e0
			elif ex_pkg_state_test "${_pkg_name}" finish\
Lucio Andrés Illanes Albornoz c6d6e0
			&& [ "${_restart_check:-0}" -eq 0 ]\
Lucio Andrés Illanes Albornoz c6d6e0
			&& [ "${_restart_recursive:-0}" -ne 2 ]\
Lucio Andrés Illanes Albornoz c6d6e0
			&& [ "x$(rtl_get_var_unsafe -u "${_group_name}_FORCE")" != "x1" ]; then
Lucio Andrés Illanes Albornoz c6d6e0
				EXP_PKG_COMPLETE="$(rtl_lconcat "${EXP_PKG_COMPLETE}" "${_pkg_name}")";
Lucio Andrés Illanes Albornoz c6d6e0
				EXP_PKG_FINISHED="$(rtl_lconcat "${EXP_PKG_FINISHED}" "${_pkg_name}")";
Lucio Andrés Illanes Albornoz c6d6e0
				_pkg_names="$(rtl_lfilter "${_pkg_names}" "${_pkg_name}")";
Lucio Andrés Illanes Albornoz c6d6e0
			fi;
Lucio Andrés Illanes Albornoz c6d6e0
		done;
Lucio Andrés Illanes Albornoz c6d6e0
		EXP_PKG_NAMES="${_pkg_names}";
Lucio Andrés Illanes Albornoz c6d6e0
	fi;
Lucio Andrés Illanes Albornoz c6d6e0
	return 0;
Lucio Andrés Illanes Albornoz c6d6e0
};
Lucio Andrés Illanes Albornoz c6d6e0
Lucio Andrés Illanes Albornoz c6d6e0
# vim:filetype=sh textwidth=0