Conan_Kudo / build / midipix_build

Forked from build/midipix_build 4 years ago
Clone
Blob Blame History Raw
#
# set -o errexit -o noglob are assumed.
#

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

# vim:filetype=sh