Blame subr/ex_pkg_exec.subr

Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
#
Lucio Andrés Illanes Albornoz e1d469
# set +o errexit -o noglob -o nounset is assumed.
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
#
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
Lucio Andrés Illanes Albornoz 8a27f9
exp_pkg_exec_filter_vars_fn() {
Lucio Andrés Illanes Albornoz 8a27f9
	local _vname="${1}";
Lucio Andrés Illanes Albornoz 8a27f9
	case "${_vname}" in
Lucio Andrés Illanes Albornoz 8a27f9
	DEFAULT|PKG_*)
Lucio Andrés Illanes Albornoz 8a27f9
		return 0; ;;
Lucio Andrés Illanes Albornoz 8a27f9
	BUILD_DLCACHEDIR|BUILD_WORKDIR|MIDIPIX_BUILD_PWD)
Lucio Andrés Illanes Albornoz 8a27f9
		return 0; ;;
Lucio Andrés Illanes Albornoz 8a27f9
	CONFIG_CACHE_GNULIB)
Lucio Andrés Illanes Albornoz 8a27f9
		return 0; ;;
Lucio Andrés Illanes Albornoz 8a27f9
	PREFIX|PREFIX_CROSS|PREFIX_MINGW32|PREFIX_MINIPIX|PREFIX_NATIVE|PREFIX_RPM)
Lucio Andrés Illanes Albornoz 8a27f9
		return 0; ;;
Lucio Andrés Illanes Albornoz 8a27f9
	*)	return 1; ;;
Lucio Andrés Illanes Albornoz 8a27f9
	esac;
Lucio Andrés Illanes Albornoz 8a27f9
};
Lucio Andrés Illanes Albornoz 8a27f9
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 370e98
# @_restart_at:		optional comma-separated list of build steps at which to rebuild or ALL or LAST
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 e1d469
	if [ -z "${PKG_URL:-}" ]\
Lucio Andrés Illanes Albornoz e1d469
	&& [ -z "${PKG_URLS_GIT:-}" ]\
Lucio Andrés Illanes Albornoz e1d469
	&& [ -z "${PKG_VERSION:-}" ]\
Lucio Andrés Illanes Albornoz 611492
	&& [ -z "${PKG_INSTALL_FILES:-}" ]\
Lucio Andrés Illanes Albornoz 611492
	&& [ -z "${PKG_INSTALL_FILES_V2:-}" ]\
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 8a4e16
		&& ! rtl_fileop rm "${PKG_BASE_DIR}" "${PKG_BUILD_DIR}" "${PKG_DESTDIR}" "${PKG_DESTDIR_HOST}"\
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 4e49c8
	elif ! rtl_exists_any "${PKG_BASE_DIR}" "${PKG_BUILD_DIR}" "${PKG_DESTDIR}" "${PKG_DESTDIR_HOST}"\
Lucio Andrés Illanes Albornoz 4e49c8
	&&   ! rtl_fileop mkdir "${PKG_BASE_DIR}" "${PKG_BUILD_DIR}" "${PKG_DESTDIR}" "${PKG_DESTDIR_HOST}"; then
Lucio Andrés Illanes Albornoz 4e49c8
		return 1
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 370e98
# @_restart_at:		optional comma-separated list of build steps at which to rebuild or ALL or LAST
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 370e98
# @_restart_at:		optional comma-separated list of build steps at which to rebuild or ALL or LAST
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 370e98
		_build_step_last="" _rc=0 _step="";
Lucio Andrés Illanes Albornoz 370e98
Lucio Andrés Illanes Albornoz 370e98
	if ! exp_pkg_exec_pre "${_group_name}" "${_pkg_name}" "${_restart_at}"\
Lucio Andrés Illanes Albornoz 370e98
	|| ! "${_dispatch_fn}" start_pkg_child "${_group_name}" "${_pkg_name}"; then
Lucio Andrés Illanes Albornoz 370e98
		_rc=1;
Lucio Andrés Illanes Albornoz 370e98
	elif rtl_test_cmd "pkg_${_pkg_name}_all"; then
Lucio Andrés Illanes Albornoz 370e98
		"pkg_${_pkg_name}_all" "${_restart_at}"; _rc="${?}";
Lucio Andrés Illanes Albornoz 3e5303
	else	set -- ${PKG_BUILD_STEPS};
Lucio Andrés Illanes Albornoz 370e98
		while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz 370e98
			_step="${1}"; shift;
Lucio Andrés Illanes Albornoz 370e98
			if [ "${#_restart_at}" -gt 0 ]\
Lucio Andrés Illanes Albornoz 370e98
			&& [ "${_restart_at}" != "ALL" ]\
Lucio Andrés Illanes Albornoz 370e98
			&& [ "${_restart_at}" != "LAST" ]\
Lucio Andrés Illanes Albornoz 370e98
			&& ! rtl_lmatch "${_restart_at}" "${_step}" ","; then
Lucio Andrés Illanes Albornoz 370e98
				continue;
Lucio Andrés Illanes Albornoz bf9edf
			fi;
Lucio Andrés Illanes Albornoz 370e98
			if [ "${_step}" = "${ARG_DUMP_IN}" ]; then
Lucio Andrés Illanes Albornoz 370e98
				printf "" > "${BUILD_WORKDIR}/${_pkg_name}.dump";
Lucio Andrés Illanes Albornoz 370e98
				rtl_filter_vars exp_pkg_exec_filter_vars_fn >> "${BUILD_WORKDIR}/${_pkg_name}.dump";
Lucio Andrés Illanes Albornoz 370e98
				export >> "${BUILD_WORKDIR}/${_pkg_name}.dump"; exit 1;
Lucio Andrés Illanes Albornoz 370e98
			elif [ "${_step}" = "finish" ]; then
Lucio Andrés Illanes Albornoz 370e98
				ex_pkg_state_set "${_pkg_name}" finish; break;
Lucio Andrés Illanes Albornoz 370e98
			elif [ "${PKG_FORCE:-0}" -eq 0 ]\
Lucio Andrés Illanes Albornoz 370e98
			&&   ex_pkg_state_test "${_pkg_name}" "${_step}" "${_restart_at}"; then
Lucio Andrés Illanes Albornoz 370e98
				continue;
Lucio Andrés Illanes Albornoz 370e98
			elif ! exp_pkg_exec_step "${_group_name}" "${_pkg_name}" "${_restart_at}" "${_step}"; then
Lucio Andrés Illanes Albornoz 370e98
				_rc=1; break;
Lucio Andrés Illanes Albornoz 370e98
			else	printf "step %s %s %s\n" "${_group_name}" "${_pkg_name}" "${_step}" >&3;
Lucio Andrés Illanes Albornoz 370e98
				ex_pkg_state_set "${_pkg_name}" "${_step}" "${@}";
Lucio Andrés Illanes Albornoz 370e98
			fi;
Lucio Andrés Illanes Albornoz 370e98
		done;
Lucio Andrés Illanes Albornoz 370e98
	fi;
Lucio Andrés Illanes Albornoz 370e98
	if [ "${_rc:-0}" -ne 0 ]\
Lucio Andrés Illanes Albornoz 370e98
	&&   [ "${ARG_DUMP_ON_ABORT:-0}" -eq 1 ]; then
Lucio Andrés Illanes Albornoz 370e98
		printf "" > "${BUILD_WORKDIR}/${_pkg_name}.dump";
Lucio Andrés Illanes Albornoz 370e98
		rtl_filter_vars exp_pkg_exec_filter_vars_fn >> "${BUILD_WORKDIR}/${_pkg_name}.dump";
Lucio Andrés Illanes Albornoz 370e98
		export >> "${BUILD_WORKDIR}/${_pkg_name}.dump";
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