Conan_Kudo / build / midipix_build

Forked from build/midipix_build 4 years ago
Clone

Blame subr/ex_pkg_exec.subr

Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
#
Lucio Andrés Illanes Albornoz 2b85d0
# set +o errexit -o noglob is assumed.
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
#
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
Lucio Andrés Illanes Albornoz 2b85d0
#
Lucio Andrés Illanes Albornoz 2b85d0
# exp_pkg_exec_pre() - XXX
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
Lucio Andrés Illanes Albornoz 2b85d0
#
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
exp_pkg_exec_pre() {
Lucio Andrés Illanes Albornoz b96c60
	local _group_name="${1}" _pkg_name="${2}" _restart_at="${3}";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	if [ -z "${PKG_URL}" ]\
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	&& [ -z "${PKG_URLS_GIT}" ]\
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	&& [ -z "${PKG_VERSION}" ]\
Lucio Andrés Illanes Albornoz c6d6e0
	&& ! rtl_test_cmd "pkg_${_pkg_name}_all"; then
Lucio Andrés Illanes Albornoz c6d6e0
		"${_dispatch_fn}" missing_pkg "${_group_name}" "${_pkg_name}";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		return 1;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	elif ! ex_pkg_state_test "${_pkg_name}" "start" "${_restart_at}"; then
Lucio Andrés Illanes Albornoz 2b85d0
		if [ "${PKG_NO_CLEAN_BASE_DIR:-0}" -eq 0 ]\
Lucio Andrés Illanes Albornoz c6d6e0
		&& ! rtl_fileop rm "${PKG_BASE_DIR}" "${PKG_BUILD_DIR}" "${PKG_DESTDIR}"\
Lucio Andrés Illanes Albornoz c6d6e0
		|| ! rtl_fileop mkdir "${PKG_BASE_DIR}"; then
Lucio Andrés Illanes Albornoz bf9edf
			return 1;
Lucio Andrés Illanes Albornoz 2b85d0
		fi;
Lucio Andrés Illanes Albornoz c6d6e0
		if ! rtl_fileop mkdir "${PKG_BUILD_DIR}" "${PKG_DESTDIR}"\
Lucio Andrés Illanes Albornoz 2b85d0
		|| ! ex_pkg_state_set "${_pkg_name}" "start"; then
Lucio Andrés Illanes Albornoz bf9edf
			return 1;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	fi;
Lucio Andrés Illanes Albornoz c6d6e0
	rtl_fileop cd "${PKG_BUILD_DIR}";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
};
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
Lucio Andrés Illanes Albornoz 2b85d0
#
Lucio Andrés Illanes Albornoz 2b85d0
# exp_pkg_exec_step() - XXX
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
# @_step:		build step to execute
Lucio Andrés Illanes Albornoz 2b85d0
#
Lucio Andrés Illanes Albornoz 2b85d0
# Return:		zero (0) on success, non-zero (>0) on failure
Lucio Andrés Illanes Albornoz 2b85d0
#
Lucio Andrés Illanes Albornoz 2b85d0
exp_pkg_exec_step() {
Lucio Andrés Illanes Albornoz 2b85d0
	local	_group_name="${1}" _pkg_name="${2}" _restart_at="${3}" _step="${4}"	\
Lucio Andrés Illanes Albornoz 2b85d0
		_fn_name="" _pkg_step_fn="" _rc=0;
Lucio Andrés Illanes Albornoz c6d6e0
	if rtl_test_cmd "pkg_${_pkg_name}_${_step}"; then
Lucio Andrés Illanes Albornoz 2b85d0
		_pkg_step_fn="pkg_${_pkg_name}_${_step}";
Lucio Andrés Illanes Albornoz 2b85d0
	else
Lucio Andrés Illanes Albornoz 2b85d0
		_pkg_step_fn="pkg_${_step}";
Lucio Andrés Illanes Albornoz 2b85d0
	fi;
Lucio Andrés Illanes Albornoz 2b85d0
	for _fn_name in \
Lucio Andrés Illanes Albornoz 2b85d0
			"pkg_${_pkg_name}_${_step}_pre"	\
Lucio Andrés Illanes Albornoz 2b85d0
			"${_pkg_step_fn}"		\
Lucio Andrés Illanes Albornoz 2b85d0
			"pkg_${_pkg_name}_${_step}_post"; do
Lucio Andrés Illanes Albornoz c6d6e0
		if rtl_test_cmd "${_fn_name}"\
Lucio Andrés Illanes Albornoz 2b85d0
		&& ! "${_fn_name}" "${_group_name}" "${_pkg_name}" "${_restart_at}"; then
Lucio Andrés Illanes Albornoz 2b85d0
			_rc=1; break;
Lucio Andrés Illanes Albornoz 2b85d0
		fi;
Lucio Andrés Illanes Albornoz 2b85d0
	done;
Lucio Andrés Illanes Albornoz 2b85d0
	return "${_rc}";
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_exec() - XXX
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
Lucio Andrés Illanes Albornoz 2b85d0
#
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
ex_pkg_exec() {
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
		_rc=0 _step="" _step_next="";
Lucio Andrés Illanes Albornoz 2b85d0
	trap "if [ \${?} -eq 0 ]; then								\
Lucio Andrés Illanes Albornoz 2b85d0
		echo \"done ${_group_name} ${_pkg_name}\" >&3;					\
Lucio Andrés Illanes Albornoz 2b85d0
	      else										\
Lucio Andrés Illanes Albornoz 2b85d0
		echo \"fail ${_group_name} ${_pkg_name}\" >&3;					\
Lucio Andrés Illanes Albornoz 2b85d0
		pkill -U "${$}";								\
Lucio Andrés Illanes Albornoz (arab, vxp) 30ae14
	      fi;" EXIT HUP INT TERM USR1 USR2;
Lucio Andrés Illanes Albornoz 2b85d0
	if exp_pkg_exec_pre "${_group_name}" "${_pkg_name}" "${_restart_at}"\
Lucio Andrés Illanes Albornoz c6d6e0
	&& "${_dispatch_fn}" start_pkg_child "${_group_name}" "${_pkg_name}"; then
Lucio Andrés Illanes Albornoz c6d6e0
		if rtl_test_cmd "pkg_${_pkg_name}_all"; then
Lucio Andrés Illanes Albornoz dda17d
			"pkg_${_pkg_name}_all" "${_restart_at}"; _rc="${?}";
Lucio Andrés Illanes Albornoz 2b85d0
		else	set -- ${PKG_BUILD_STEPS};
Lucio Andrés Illanes Albornoz 2b85d0
			while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz 2b85d0
				_step="${1}"; _step_next="${2}"; shift;
Lucio Andrés Illanes Albornoz c6d6e0
				if [ "${PKG_FORCE:-0}" -eq 0 ]\
Lucio Andrés Illanes Albornoz c6d6e0
				&& ex_pkg_state_test "${_pkg_name}" "${_step}" "${_restart_at}"	; then
Lucio Andrés Illanes Albornoz 2b85d0
					continue;
Lucio Andrés Illanes Albornoz 2b85d0
				elif ! exp_pkg_exec_step "${_group_name}" "${_pkg_name}" "${_restart_at}" "${_step}"; then
Lucio Andrés Illanes Albornoz 2b85d0
					_rc=1; break;
Lucio Andrés Illanes Albornoz (arab, vxp) fce0a9
				else
Lucio Andrés Illanes Albornoz 2b85d0
					echo "step ${_group_name} ${_pkg_name} ${_step}" >&3;
Lucio Andrés Illanes Albornoz 2b85d0
					ex_pkg_state_set "${_pkg_name}" "${_step}" "${_step_next:+-${_step_next}}";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
				fi;
Lucio Andrés Illanes Albornoz 2b85d0
			done;
Lucio Andrés Illanes Albornoz 2b85d0
		fi;
Lucio Andrés Illanes Albornoz bf9edf
		if [ "${_rc:-0}" -eq 0 ]; then
Lucio Andrés Illanes Albornoz bf9edf
			if [ -z "${_restart_at}" ]\
Lucio Andrés Illanes Albornoz bf9edf
			|| [ "${_restart_at}" = "ALL" ]; then
Lucio Andrés Illanes Albornoz bf9edf
				ex_pkg_state_set "${_pkg_name}" finish;
Lucio Andrés Illanes Albornoz bf9edf
			fi;
Lucio Andrés Illanes Albornoz dda17d
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	fi;
Lucio Andrés Illanes Albornoz 2b85d0
	return "${_rc}";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
};
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
# vim:filetype=sh