e9fa07
#
8d7a8a
# Copyright (c) 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 LucĂ­a Andrea Illanes Albornoz <lucia@luciaillanes.de>
e9fa07
# set +o errexit -o noglob -o nounset is assumed.
e9fa07
#
e9fa07
e9fa07
#
0903bb
# exp_pkg_exec_pre() - prepare environment for single named package w/ dispatcher
e9fa07
# @_group_name:		build group name
e9fa07
# @_pkg_name:		single package name
e9fa07
# @_restart_at:		optional comma-separated list of build steps at which to rebuild or ALL or LAST
e9fa07
# @_workdir:		pathname to build-specific temporary directory
e9fa07
#
99f4d8
# Returns:		zero (0) on success, non-zero (>0) on failure
e9fa07
#
e9fa07
exp_pkg_exec_pre() {
e9fa07
	local _eppep_group_name="${1}" _eppep_pkg_name="${2}" _eppep_restart_at="${3}" _eppep_workdir="${4}";
e9fa07
e9fa07
	if [ "${PKG_URL:+1}" != 1 ]\
e9fa07
	&& [ "${PKG_URLS_GIT:+1}" != 1 ]\
e9fa07
	&& [ "${PKG_VERSION:+1}" != 1 ]\
e9fa07
	&& [ "${PKG_INSTALL_FILES:+1}" != 1 ]\
e9fa07
	&& [ "${PKG_INSTALL_FILES_V2:+1}" != 1 ]\
e9fa07
	&& ! rtl_test_cmd "pkg_${_eppep_pkg_name}_all";
e9fa07
	then
e9fa07
		"${_eppep_dispatch_fn}" missing_pkg "${_eppep_group_name}" "${_eppep_pkg_name}";
e9fa07
		return 1;
e9fa07
	elif ! ex_pkg_state_test2			\
e9fa07
			"${_eppep_workdir}"		\
e9fa07
			"${_eppep_pkg_name}" "start"	\
e9fa07
			"${_eppep_restart_at}";
e9fa07
	then
e9fa07
		if [ "${PKG_NO_CLEAN_BASE_DIR:-0}" -eq 0 ]\
e9fa07
		&& ! rtl_fileop rm "${PKG_BASE_DIR}" "${PKG_BUILD_DIR}" "${PKG_DESTDIR}" "${PKG_DESTDIR_HOST}"\
e9fa07
		|| ! rtl_fileop mkdir "${PKG_BASE_DIR}";
e9fa07
		then
e9fa07
			return 1;
e9fa07
		fi;
e9fa07
e9fa07
		if ! rtl_fileop mkdir "${PKG_BUILD_DIR}" "${PKG_DESTDIR}"\
e9fa07
		|| ! ex_pkg_state_set2 "${_eppep_workdir}" "${_eppep_pkg_name}" "start";
e9fa07
		then
e9fa07
			return 1;
e9fa07
		fi;
e9fa07
	elif ! rtl_exists_any "${PKG_BASE_DIR}" "${PKG_BUILD_DIR}" "${PKG_DESTDIR}" "${PKG_DESTDIR_HOST}"\
e9fa07
	&&   ! rtl_fileop mkdir "${PKG_BASE_DIR}" "${PKG_BUILD_DIR}" "${PKG_DESTDIR}" "${PKG_DESTDIR_HOST}";
e9fa07
	then
e9fa07
		return 1
e9fa07
	fi;
e9fa07
e9fa07
	rtl_fileop cd "${PKG_BUILD_DIR}";
e9fa07
	return "${?}";
e9fa07
};
e9fa07
e9fa07
#
0903bb
# exp_pkg_exec_step() - execute single build steps & update state for single named package w/ dispatcher
e9fa07
# @_group_name:		build group name
e9fa07
# @_pkg_name:		single package name
e9fa07
# @_restart_at:		optional comma-separated list of build steps at which to rebuild or ALL or LAST
e9fa07
# @_step:		build step to execute
e9fa07
#
99f4d8
# Returns:		zero (0) on success, non-zero (>0) on failure
e9fa07
#
e9fa07
exp_pkg_exec_step() {
e9fa07
	local	_eppes_group_name="${1}" _eppes_pkg_name="${2}" _eppes_restart_at="${3}"	\
e9fa07
		_eppes_step="${4}"								\
e9fa07
		_eppes_fn_name="" _eppes_pkg_step_fn="" _eppes_rc=0;
e9fa07
e9fa07
	if rtl_test_cmd "pkg_${_eppes_pkg_name}_${_eppes_step}"; then
e9fa07
		_eppes_pkg_step_fn="pkg_${_eppes_pkg_name}_${_eppes_step}";
e9fa07
	else
e9fa07
		_eppes_pkg_step_fn="pkg_${_eppes_step}";
e9fa07
	fi;
e9fa07
e9fa07
	for _eppes_fn_name in 						\
e9fa07
			"pkg_${_eppes_pkg_name}_${_eppes_step}_pre"	\
e9fa07
			"${_eppes_pkg_step_fn}"				\
e9fa07
			"pkg_${_eppes_pkg_name}_${_eppes_step}_post";
e9fa07
	do
e9fa07
		if rtl_test_cmd "${_eppes_fn_name}"\
e9fa07
		&& ! "${_eppes_fn_name}"					\
e9fa07
				"${_eppes_group_name}" "${_eppes_pkg_name}"	\
e9fa07
				"${_eppes_restart_at}";
e9fa07
		then
e9fa07
			_eppes_rc=1; break;
e9fa07
		fi;
e9fa07
	done;
e9fa07
e9fa07
	return "${_eppes_rc}";
e9fa07
};
e9fa07
e9fa07
#
0903bb
# exp_pkg_exec() - execute all pertaining build steps & update state for single named package w/ dispatcher
e9fa07
# @_dispatch_fn:	top-level dispatch function name
e9fa07
# @_group_name:		build group name
e9fa07
# @_pkg_name:		single package name
e9fa07
# @_restart_at:		optional comma-separated list of build steps at which to rebuild or ALL or LAST
e9fa07
# @_workdir:		pathname to build-specific temporary directory
e9fa07
#
99f4d8
# Returns:		zero (0) on success, non-zero (>0) on failure
e9fa07
#
e9fa07
exp_pkg_exec() {
e9fa07
	local	_eppe_dispatch_fn="${1}" _eppe_group_name="${2}" _eppe_pkg_name="${3}"	\
e9fa07
		_eppe_restart_at="${4}" _eppe_workdir="${5}"				\
e9fa07
		_eppe_build_step_last="" _eppe_rc=0 _eppe_step="";
e9fa07
e9fa07
	if ! exp_pkg_exec_pre						\
e9fa07
			"${_eppe_group_name}" "${_eppe_pkg_name}"	\
e9fa07
			"${_eppe_restart_at}" "${_eppe_workdir}"\
e9fa07
	|| ! "${_eppe_dispatch_fn}"				\
e9fa07
			start_pkg_child "${_eppe_group_name}"	\
e9fa07
			"${_eppe_pkg_name}";
e9fa07
	then
e9fa07
		_eppe_rc=1;
e9fa07
	elif rtl_test_cmd "pkg_${_eppe_pkg_name}_all"; then
e9fa07
		"pkg_${_eppe_pkg_name}_all"				\
e9fa07
			"${_eppe_group_name}" "${_eppe_pkg_name}"	\
e9fa07
			"${_eppe_restart_at}";
e9fa07
		_eppe_rc="${?}";
e9fa07
	else
e9fa07
		set -- ${PKG_BUILD_STEPS};
e9fa07
		while [ ${#} -gt 0 ]; do
e9fa07
			_eppe_step="${1}"; shift;
e9fa07
e9fa07
			if [ "${#_eppe_restart_at}" -gt 0 ]\
e9fa07
			&& [ "${_eppe_restart_at}" != "ALL" ]\
e9fa07
			&& [ "${_eppe_restart_at}" != "LAST" ]\
e9fa07
			&& ! rtl_lmatch \$_eppe_restart_at "${_eppe_step}" ","; then
e9fa07
				continue;
e9fa07
			fi;
e9fa07
e9fa07
			if [ "${_eppe_step}" = "finish" ]; then
e9fa07
				ex_pkg_state_set2 "${_eppe_workdir}" "${_eppe_pkg_name}" finish; break;
e9fa07
			elif [ "${PKG_FORCE:-0}" -eq 0 ]\
e9fa07
			&&   ex_pkg_state_test2 "${_eppe_workdir}" "${_eppe_pkg_name}" "${_eppe_step}" "${_eppe_restart_at}";
e9fa07
			then
e9fa07
				continue;
e9fa07
			elif ! exp_pkg_exec_step					\
e9fa07
					"${_eppe_group_name}" "${_eppe_pkg_name}"	\
e9fa07
					"${_eppe_restart_at}" "${_eppe_step}";
e9fa07
			then
e9fa07
				_eppe_rc=1; break;
670f66
			else	ex_pkg_dispatch_send "step" "${_eppe_group_name}" "${_eppe_pkg_name}" "${_eppe_step}";
e9fa07
				ex_pkg_state_set2 "${_eppe_workdir}" "${_eppe_pkg_name}" "${_eppe_step}" "${@}";
e9fa07
			fi;
e9fa07
		done;
e9fa07
	fi;
e9fa07
e9fa07
	return "${_eppe_rc}";
e9fa07
};
e9fa07
e9fa07
#
0903bb
# ex_pkg_exec() - prepare environment for, execute all pertaining build steps & update state for single named package w/ dispatcher
e9fa07
# @_rdispatch_count:		reference to inout variable of dispatcher count
e9fa07
# @_dispatch_count_cur:		current dispatcher count
e9fa07
# @_dispatch_count_max:		maximum dispatcher count
e9fa07
# @_dispatch_group_cur:		current group
e9fa07
# @_dispatch_group_max:		maximum group
e9fa07
# @_rdispatch_njobs:		reference to inout variable of dispatcher count
e9fa07
# @_rdispatch_wait:		reference to inout variable of package names in a wait state
e9fa07
# @_build_steps_default:	list of default build steps
e9fa07
# @_build_vars_default:		list of default build variables
e9fa07
# @_dispatch_fn:		top-level dispatch function name
e9fa07
# @_group_name:			build group name
e9fa07
# @_pipe_path:			pathname to parent-child process FIFO
e9fa07
# @_pkg_name:			single package name
e9fa07
# @_restart_at:			optional comma-separated list of build steps at which to rebuild or ALL or LAST
e9fa07
# @_workdir:			pathname to build-specific temporary directory
e9fa07
#
99f4d8
# Returns:			zero (0) on success, non-zero (>0) on failure.
e9fa07
#
e9fa07
ex_pkg_exec() {
e9fa07
	local	_epdp_rdispatch_count="${1#\$}" _epdp_dispatch_count_cur="${2}" _epdp_dispatch_count_max="${3}"		\
e9fa07
		_epdp_dispatch_group_cur="${4}" _epdp_dispatch_group_max="${5}" _epdp_rdispatch_njobs="${6#\$}"		\
e9fa07
		_epdp_rdispatch_wait="${7#\$}" _epdp_build_steps_default="${8}" _epdp_build_vars_default="${9}"		\
e9fa07
		_epdp_dispatch_fn="${10}" _epdp_group_name="${11}" _epdp_pipe_path="${12}" _epdp_pkg_name="${13}"	\
e9fa07
		_epdp_restart_at="${14}" _epdp_workdir="${15}"								\
e9fa07
		_epdp_dispatch_count_new=0 _epdp_perc_group=0 _epdp_perc_pkg=0;
e9fa07
e9fa07
	rtl_percentage2 \$_epdp_dispatch_group_cur \$_epdp_dispatch_group_max \$_epdp_perc_group;
e9fa07
	rtl_percentage2 \$_epdp_dispatch_count_cur \$_epdp_dispatch_count_max \$_epdp_perc_pkg;
e9fa07
e9fa07
	eval _epdp_dispatch_count_new='$((${'"${_epdp_rdispatch_count}"'}+1))';
e9fa07
	if "${_epdp_dispatch_fn}"				\
e9fa07
			start_pkg "${_epdp_group_name}"		\
e9fa07
			"${_epdp_pkg_name}"			\
e9fa07
			"${_epdp_dispatch_count_new}"		\
e9fa07
			"${_epdp_dispatch_count_max}"		\
e9fa07
			"${_epdp_perc_group}" "${_epdp_perc_pkg}";
e9fa07
	then
e9fa07
		eval : '$(('${_epdp_rdispatch_njobs}'+=1))';
e9fa07
		eval ${_epdp_rdispatch_count}=\"\${_epdp_dispatch_count_new}\";
e9fa07
		rtl_lconcat "${_epdp_rdispatch_wait}" "${_epdp_pkg_name}";
e9fa07
e9fa07
		(trap "if [ \${?} -eq 0 ]; then												\
670f66
			ex_pkg_dispatch_send \"done\" \"${_epdp_group_name}\" \"${_epdp_pkg_name}\" \"${_epdp_dispatch_count_new}\";	\
e9fa07
		      else														\
670f66
			ex_pkg_dispatch_send \"fail\" \"${_epdp_group_name}\" \"${_epdp_pkg_name}\" \"${_epdp_dispatch_count_new}\";	\
e9fa07
			pkill -U "${$}";												\
e9fa07
		      fi;" EXIT HUP INT TERM USR1 USR2;
e9fa07
		set +o errexit -o noglob -o nounset; BUILD_IS_PARENT=0; rtl_log_set_fname ""; rtl_log_set_no_attr 1;
e9fa07
e9fa07
		if ex_pkg_env									\
e9fa07
				"${_epdp_build_steps_default}" "${_epdp_build_vars_default}"	\
e9fa07
				"${_epdp_group_name}" "${_epdp_pkg_name}"			\
e9fa07
				"${_epdp_restart_at}" "${_epdp_workdir}";
e9fa07
		then
e9fa07
			exp_pkg_exec						\
e9fa07
				"${_epdp_dispatch_fn}" "${_epdp_group_name}"	\
e9fa07
				"${_epdp_pkg_name}" "${_epdp_restart_at}"	\
e9fa07
				"${_epdp_workdir}";
e9fa07
		else
e9fa07
			return 1;
e9fa07
		fi;) 1>"${_epdp_workdir}/${_epdp_pkg_name}_stderrout.log" 2>&1 3>"${_epdp_pipe_path}" &
e9fa07
		return "${?}";
e9fa07
	else
e9fa07
		return 1;
e9fa07
	fi;
e9fa07
};
e9fa07
64844b
# vim:filetype=sh textwidth=0