Conan_Kudo / build / midipix_build

Forked from build/midipix_build 4 years ago
Clone

Blame subr/ex_pkg.subr

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 7bed88
# @_restart_recursive:	optional flag specifiying either no dependency expansion (0,) dependency expansion (1,) dependency expansion and forcibly rebuild (2,) forcibly rebuild reverse dependencies (3.)
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 7bed88
	&& [ -n "${_pkg_depends}" ]; then
Lucio Andrés Illanes Albornoz 7bed88
		if [ -z "${_restart}" ]\
Lucio Andrés Illanes Albornoz 7bed88
		|| [ "${_restart_recursive:-0}" -ge 1 ]; then
Lucio Andrés Illanes Albornoz 7bed88
			for _pkg_name_depend in $(rtl_uniq ${_pkg_depends}); do
Lucio Andrés Illanes Albornoz 7bed88
				if ! rtl_lmatch "${_pkg_complete}" "${_pkg_name_depend}"\
Lucio Andrés Illanes Albornoz 7bed88
				|| rtl_lmatch "${_pkg_wait}" "${_pkg_name_depend}"; then
Lucio Andrés Illanes Albornoz 7bed88
					_dependfl=1; break;
Lucio Andrés Illanes Albornoz 7bed88
				fi;
Lucio Andrés Illanes Albornoz 7bed88
			done;
Lucio Andrés Illanes Albornoz 7bed88
		fi;
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 221ee9
# @_restart:		optional whitespace-separated list of package names to rebuild
Lucio Andrés Illanes Albornoz 7bed88
# @_restart_recursive:	optional flag specifiying either no dependency expansion (0,) dependency expansion (1,) dependency expansion and forcibly rebuild (2,) forcibly rebuild reverse dependencies (3.)
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 d4a069
	local	_group_name="${1}" _restart="${2}" _restart_recursive="${3}"		\
Lucio Andrés Illanes Albornoz d4a069
		_pkg_depends="" _pkg_name="" _pkg_name_depend="" _pkg_names=""		\
Lucio Andrés Illanes Albornoz d4a069
		_pkg_rdepends="" _restartfl=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 7bed88
		if [ "${_restart_recursive:-0}" -ne 3 ]; then
Lucio Andrés Illanes Albornoz 7bed88
			if [ -n "${_restart}" ] && ! rtl_lmatch "${_restart}" "ALL LAST"; then
Lucio Andrés Illanes Albornoz 7bed88
				_pkg_names="$(rtl_lsearch "${_pkg_names}" "${_restart}")";
Lucio Andrés Illanes Albornoz 7bed88
			fi;
Lucio Andrés Illanes Albornoz d4a069
			if [ -n "${_restart}" ]\
Lucio Andrés Illanes Albornoz d4a069
			&& [ "${_restart_recursive:-0}" -ge 1 ]\
Lucio Andrés Illanes Albornoz d4a069
			&& [ "${_restart_recursive:-0}" -le 2 ]; then
Lucio Andrés Illanes Albornoz 7bed88
				_pkg_names="$(rtl_uniq $(rtl_lunfold_depends 'PKG_${_name}_DEPENDS' ${_pkg_names}))";
Lucio Andrés Illanes Albornoz 7bed88
			fi;
Lucio Andrés Illanes Albornoz d4a069
			for _pkg_name in ${_pkg_names}; do
Lucio Andrés Illanes Albornoz 7bed88
				if [ "${_restart}" = "ALL" ]\
Lucio Andrés Illanes Albornoz 7bed88
				|| rtl_lmatch "${_restart}" "${_pkg_name}"; then
Lucio Andrés Illanes Albornoz d4a069
					_restartfl=1;
Lucio Andrés Illanes Albornoz 7bed88
				else
Lucio Andrés Illanes Albornoz d4a069
					_restartfl=0;
Lucio Andrés Illanes Albornoz 7bed88
				fi;
Lucio Andrés Illanes Albornoz d4a069
				if [ "x$(rtl_get_var_unsafe -u "PKG_${_pkg_name}_DISABLED")" = "x1" ]; then
Lucio Andrés Illanes Albornoz d4a069
					EXP_PKG_COMPLETE="$(rtl_lconcat "${EXP_PKG_COMPLETE}" "${_pkg_name}")";
Lucio Andrés Illanes Albornoz d4a069
					EXP_PKG_DISABLED="$(rtl_lconcat "${EXP_PKG_DISABLED}" "${_pkg_name}")";
Lucio Andrés Illanes Albornoz d4a069
					_pkg_names="$(rtl_lfilter "${_pkg_names}" "${_pkg_name}")";
Lucio Andrés Illanes Albornoz d4a069
				elif ex_pkg_state_test "${_pkg_name}" finish\
Lucio Andrés Illanes Albornoz d4a069
				&& [ "${_restartfl:-0}" -eq 0 ]\
Lucio Andrés Illanes Albornoz d4a069
				&& [ "${_restart_recursive:-0}" -ne 2 ]\
Lucio Andrés Illanes Albornoz d4a069
				&& [ "x$(rtl_get_var_unsafe -u "${_group_name}_FORCE")" != "x1" ]; then
Lucio Andrés Illanes Albornoz d4a069
					EXP_PKG_COMPLETE="$(rtl_lconcat "${EXP_PKG_COMPLETE}" "${_pkg_name}")";
Lucio Andrés Illanes Albornoz d4a069
					EXP_PKG_FINISHED="$(rtl_lconcat "${EXP_PKG_FINISHED}" "${_pkg_name}")";
Lucio Andrés Illanes Albornoz 7bed88
					_pkg_names="$(rtl_lfilter "${_pkg_names}" "${_pkg_name}")";
Lucio Andrés Illanes Albornoz 7bed88
				fi;
Lucio Andrés Illanes Albornoz d4a069
			done;
Lucio Andrés Illanes Albornoz d4a069
		else	for _pkg_name_depend in ${_restart}; do
Lucio Andrés Illanes Albornoz d4a069
				for _pkg_name in ${_pkg_names}; do
Lucio Andrés Illanes Albornoz d4a069
					if [ "${_pkg_name}" != "${_pkg_name_depend}" ]\
Lucio Andrés Illanes Albornoz d4a069
					&& [ "x$(rtl_get_var_unsafe -u "PKG_${_pkg_name}_DISABLED")" != "x1" ]\
Lucio Andrés Illanes Albornoz d4a069
					&& _pkg_depends="$(rtl_lunfold_depends 'PKG_${_name}_DEPENDS' $(rtl_get_var_unsafe -u "PKG_"${_pkg_name}"_DEPENDS"))"\
Lucio Andrés Illanes Albornoz d4a069
					&& [ -n "${_pkg_depends}" ]\
Lucio Andrés Illanes Albornoz d4a069
					&& rtl_lmatch "${_pkg_depends}" "${_pkg_name_depend}"; then
Lucio Andrés Illanes Albornoz d4a069
						_pkg_rdepends="$(rtl_lconcat "${_pkg_rdepends}" "${_pkg_name}")";
Lucio Andrés Illanes Albornoz d4a069
					fi;
Lucio Andrés Illanes Albornoz d4a069
				done;
Lucio Andrés Illanes Albornoz d4a069
			done;
Lucio Andrés Illanes Albornoz d4a069
			_pkg_names="";
Lucio Andrés Illanes Albornoz d4a069
			for _pkg_name in ${_pkg_rdepends}; do
Lucio Andrés Illanes Albornoz d4a069
				if _pkg_depends="$(rtl_lunfold_depends 'PKG_${_name}_DEPENDS' $(rtl_get_var_unsafe -u "PKG_"${_pkg_name}"_DEPENDS"))"\
Lucio Andrés Illanes Albornoz d4a069
				&& [ -n "${_pkg_depends}" ]; then
Lucio Andrés Illanes Albornoz d4a069
					for _pkg_name_depend in ${_pkg_depends}; do
Lucio Andrés Illanes Albornoz d4a069
						if [ "x$(rtl_get_var_unsafe -u "PKG_${_pkg_name_depend}_DISABLED")" = "x1" ]; then
Lucio Andrés Illanes Albornoz d4a069
							EXP_PKG_COMPLETE="$(rtl_lconcat "${EXP_PKG_COMPLETE}" "${_pkg_name_depend}")";
Lucio Andrés Illanes Albornoz d4a069
							EXP_PKG_DISABLED="$(rtl_lconcat "${EXP_PKG_DISABLED}" "${_pkg_name_depend}")";
Lucio Andrés Illanes Albornoz d4a069
						elif ex_pkg_state_test "${_pkg_name_depend}" finish\
Lucio Andrés Illanes Albornoz d4a069
						&& [ "x$(rtl_get_var_unsafe -u "${_group_name}_FORCE")" != "x1" ]\
Lucio Andrés Illanes Albornoz d4a069
						&& ! rtl_lmatch "${_pkg_rdepends}" "${_pkg_name_depend}"; then
Lucio Andrés Illanes Albornoz d4a069
							EXP_PKG_COMPLETE="$(rtl_lconcat "${EXP_PKG_COMPLETE}" "${_pkg_name_depend}")";
Lucio Andrés Illanes Albornoz d4a069
							EXP_PKG_FINISHED="$(rtl_lconcat "${EXP_PKG_FINISHED}" "${_pkg_name_depend}")";
Lucio Andrés Illanes Albornoz d4a069
						elif ! ex_pkg_state_test "${_pkg_name_depend}" finish\
Lucio Andrés Illanes Albornoz d4a069
						|| [ "x$(rtl_get_var_unsafe -u "${_group_name}_FORCE")" = "x1" ]; then
Lucio Andrés Illanes Albornoz d4a069
							_pkg_names="$(rtl_lconcat "${_pkg_names}" "${_pkg_name_depend}")";
Lucio Andrés Illanes Albornoz d4a069
						fi;
Lucio Andrés Illanes Albornoz d4a069
					done;
Lucio Andrés Illanes Albornoz d4a069
				fi;
Lucio Andrés Illanes Albornoz d4a069
				_pkg_names="$(rtl_lconcat "${_pkg_names}" "${_pkg_name}")";
Lucio Andrés Illanes Albornoz d4a069
			done;
Lucio Andrés Illanes Albornoz d4a069
			EXP_PKG_COMPLETE="$(rtl_uniq ${EXP_PKG_COMPLETE})";
Lucio Andrés Illanes Albornoz d4a069
			EXP_PKG_DISABLED="$(rtl_uniq ${EXP_PKG_DISABLED})";
Lucio Andrés Illanes Albornoz d4a069
			EXP_PKG_FINISHED="$(rtl_uniq ${EXP_PKG_FINISHED})";
Lucio Andrés Illanes Albornoz d4a069
			_pkg_names="$(rtl_uniq ${_pkg_names})";
Lucio Andrés Illanes Albornoz d4a069
		fi;
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