Lucio Andrés Illanes Albornoz (arab, vxp) 1da591
#
Lucio Andrés Illanes Albornoz (arab, vxp) 1da591
# set -o errexit -o noglob are assumed.
Lucio Andrés Illanes Albornoz (arab, vxp) 1da591
#
Lucio Andrés Illanes Albornoz (arab, vxp) 1da591
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
ex_pkg_dispatch() {
Lucio Andrés Illanes Albornoz (arab, vxp) 1da591
	local _tgt_name="${1}" _pkg_name="${2}"		\
Lucio Andrés Illanes Albornoz (arab, vxp) 1da591
		_restart="${3}" _restart_at="${4}"	\
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
		_pkg_step_cmds _pkg_step_cmd_args	\
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
		_stdout_path _stderr_path		\
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
		_pipe_path _pipe_path2 _pipe_msg _script_rc;
Lucio Andrés Illanes Albornoz (arab, vxp) 1da591
	if [ "${_pkg_name#*_flavour_*}" != "${_pkg_name}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) d7620f
		PKG_NAME_PARENT="${_pkg_name%_flavour_*}";
Lucio Andrés Illanes Albornoz (arab, vxp) 1da591
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
	if ex_pkg_state_test "${_pkg_name}" finish; then
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
		if [ -z "${_restart}" ]\
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
		&& [ "${_tgt_name}" != "INVARIANTS" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
			return 0;
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
	_pipe_path="${WORKDIR}/${_pkg_name}_build.fifo";
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
	ex_build_fileop rm "${_pipe_path}"; mkfifo "${_pipe_path}";
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
	_pipe2_path="${WORKDIR}/${_pkg_name}_build2.fifo";
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
	ex_build_fileop rm "${_pipe2_path}"; mkfifo "${_pipe2_path}";
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
	_stderr_path="${WORKDIR}/${_pkg_name}_stderr.log";
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
	_stdout_path="${WORKDIR}/${_pkg_name}_stdout.log";
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
	ex_build_fileop rm "${_stderr_path}" "${_stdout_path}";
Lucio Andrés Illanes Albornoz (arab, vxp) 1da591
	(set -o errexit -o noglob;
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
	ex_pkg_vars;
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
	if [ -z "${PKG_URL}" ]\
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
	&& [ -z "${PKG_URLS_GIT}" ]\
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
	&& [ -z "${PKG_VERSION}" ]\
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
	&& ! ex_test_cmd "pkg_${PKG_NAME}_all"; then
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
		ex_log_msg failexit "Error: package \`${PKG_NAME}' missing in build.vars.";
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
		exit 1;
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
	elif [ "${PKG_DISABLED:-0}" -eq 1 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
		ex_log_msg vnfo "Skipping disabled package \`${PKG_NAME}.'";
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
		echo "done ${PKG_BASE_DIR}" >&3; exit 0;
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
	else
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
		ex_pkg_env;
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
		ex_build_fileop mkdir "${PKG_BASE_DIR}";
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
		ex_build_fileop cd "${PKG_BASE_DIR}";
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
	set -- $(ex_lfilter -not "${BUILD_STEPS}"	\
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
			"$(ex_get_var_unsafe PKG_$(ex_toupper "${_pkg_name}")_BUILD_STEPS_DISABLE)");
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
	while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
		_pkg_step_cmds=""; _pkg_step_cmd_args="";
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
		case "${1#*:}" in
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
		dynamic)
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
			if [ "${_tgt_name}" = "INVARIANTS" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
				_pkg_step_cmds="pkg_${_pkg_name}_${1%:*} pkg_${1%:*}";
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
			elif [ -n "${_restart}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
				if [ -z "${_restart_at}" ]\
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
				|| ex_lmatch "${_restart_at}" , "${1%:*}"; then
Lucio Andrés Illanes Albornoz (arab, vxp) 1da591
					_pkg_step_cmds="pkg_${_pkg_name}_${1%:*} pkg_${1%:*}";
Lucio Andrés Illanes Albornoz (arab, vxp) 1da591
				fi;
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
			elif ! ex_pkg_state_test "${_pkg_name}" "${1%:*}"; then
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
				_pkg_step_cmds="pkg_${_pkg_name}_${1%:*} pkg_${1%:*}";
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
			fi; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
		invariant)
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
			_pkg_step_cmds="pkg_${1%:*}"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
		variant)
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
			if ex_lmatch "${_restart_at}" "," "${1%:*}"; then
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
				_pkg_step_cmds="pkg_${_pkg_name}_${1%:*} pkg_${1%:*}";
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
			fi; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
		virtual)
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
			_pkg_step_cmds="pkg_${_pkg_name}_${1%:*}";
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
			_pkg_step_cmd_args="${_restart_at:-ALL}"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
		all)
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
			if ex_test_cmd "pkg_${_pkg_name}_${1%:*}"; then
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
				"pkg_${_pkg_name}_${1%:*}" "${_restart_at:-ALL}";
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
				break;
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
			fi; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
		finish)	ex_pkg_state_push "${_pkg_name}" finish; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
		*)	;;
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
		esac;
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
		for __ in ${_pkg_step_cmds}; do
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
			if ex_test_cmd "${__}"; then
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
				ex_test_cmd "pkg_${_pkg_name}_${1%:*}_pre"	\
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
					&& "pkg_${_pkg_name}_${1%:*}_pre"
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
				"${__}" ${_pkg_step_cmd_args};
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
				ex_test_cmd "pkg_${_pkg_name}_${1%:*}_post"	\
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
					&& "pkg_${_pkg_name}_${1%:*}_post"
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
				if [ "${1#*:}" != "invariant" ]\
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
				&& [ ${#} -ge 2 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
					ex_pkg_state_push "${_pkg_name}" "${1%:*}" "-${2#*:}";
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
				else
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
					ex_pkg_state_push "${_pkg_name}" "${1%:*}";
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
				fi; break;
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
			fi;
Lucio Andrés Illanes Albornoz (arab, vxp) fc24fa
		done;
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
	shift; done; set -o xtrace
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
	echo "done ${PKG_BASE_DIR}" >&3; read __ <&4;)	\
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
		1>"${_stdout_path}" 2>"${_stderr_path}"	\
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
		3<>"${_pipe_path}" 4<>"${_pipe2_path}" &
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
	_script_rc=1; while read _pipe_msg <"${_pipe_path}"; do
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
	case "${_pipe_msg%% *}" in
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
	done)	echo >"${_pipe2_path}"; _script_rc=0; break; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
	*)	break; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
	esac; done;
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
	ex_build_fileop rm "${_pipe_path}";
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
	return "${_script_rc:-0}";
Lucio Andrés Illanes Albornoz (arab, vxp) 1da591
};
Lucio Andrés Illanes Albornoz (arab, vxp) 1da591
Lucio Andrés Illanes Albornoz (arab, vxp) 1da591
# vim:filetype=sh