Blame build.sh

lalbornoz 340f4c
#!/bin/sh
Lucio Andrés Illanes Albornoz 4b7725
# Copyright (c) 2016, 2017, 2018, 2019 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
#
Lucio Andrés Illanes Albornoz (arab, vxp) 090fd4
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
buildp_dispatch() {
Lucio Andrés Illanes Albornoz 2b85d0
	local	_msg="${1}" _group_name="${2}" _pkg_name="${3}"			\
Lucio Andrés Illanes Albornoz 2b85d0
		_build_group_lc="" _build_group_meta="" _build_groups_lc=""	\
Lucio Andrés Illanes Albornoz 78102c
		_njobs_max=1 _pkg_names="" _pkg_restart="" _rc=0;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	case "${_msg}" in
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	# Top-level
Lucio Andrés Illanes Albornoz c3bcd7
	start_build)	shift; build_init "${@}";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			ex_rtl_log_msg info "Build started by ${BUILD_USER:=${USER}}@${BUILD_HNAME:=$(hostname)} at ${BUILD_DATE_START}.";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			ex_rtl_log_env_vars "build (global)" ${DEFAULT_LOG_ENV_VARS};
Lucio Andrés Illanes Albornoz b96c60
			_build_groups_lc="${BUILD_GROUPS:-${GROUPS_DEFAULT}}";
Lucio Andrés Illanes Albornoz 2b85d0
			if ! ex_rtl_lmatch "${ARG_DIST}" "rpm" ","; then
Lucio Andrés Illanes Albornoz 452c35
				_build_groups_lc="$(ex_rtl_lfilter "${_build_groups_lc}" "host_deps_rpm")";
Lucio Andrés Illanes Albornoz 0eaee4
			fi;
Lucio Andrés Illanes Albornoz 2b85d0
			if [ "${ARG_PARALLEL:-0}" -gt 1 ]; then
Lucio Andrés Illanes Albornoz 2b85d0
				_njobs_max="${DEFAULT_BUILD_CPUS}";
Lucio Andrés Illanes Albornoz 2b85d0
			fi;
Lucio Andrés Illanes Albornoz b96c60
			for _build_group_lc in ${_build_groups_lc}; do
Lucio Andrés Illanes Albornoz 2b85d0
				ex_pkg_dispatch buildp_dispatch "${_build_group_lc}" "${_njobs_max}"	\
Lucio Andrés Illanes Albornoz 2b85d0
						"${ARG_RESTART}" "${ARG_RESTART_AT}" "${ARG_RESTART_RECURSIVE}"; _rc="${?}";
Lucio Andrés Illanes Albornoz 2b85d0
				: $((_nskipped+=${EX_PKG_NSKIPPED})); _pkg_names="$(ex_rtl_lconcat "${_pkg_names}" "${EX_PKG_NAMES}")";
Lucio Andrés Illanes Albornoz 2b85d0
				if [ "${_rc}" -ne 0 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 1dfec6
					break;
Lucio Andrés Illanes Albornoz (arab, vxp) 1dfec6
				fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			done;
Lucio Andrés Illanes Albornoz da0364
			for _pkg_restart in ${ARG_RESTART}; do
Lucio Andrés Illanes Albornoz 2b85d0
				if ! ex_rtl_lmatch "${_pkg_restart}" "ALL LAST"\
Lucio Andrés Illanes Albornoz 2b85d0
				&& ! ex_rtl_lmatch "${_pkg_names}" "${_pkg_restart}"; then
Lucio Andrés Illanes Albornoz da0364
					ex_rtl_log_msg failexit "Error: package \`${_pkg_restart}' unknown.";
Lucio Andrés Illanes Albornoz da0364
				fi;
Lucio Andrés Illanes Albornoz da0364
			done;
Lucio Andrés Illanes Albornoz 2b85d0
			if ! ex_pkg_dispatch buildp_dispatch "invariants" "${_njobs_max}" "ALL" "ALL" 2; then
Lucio Andrés Illanes Albornoz (arab, vxp) 6c6c71
				break;
Lucio Andrés Illanes Albornoz (arab, vxp) 6c6c71
			fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			buildp_dispatch finish_build; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	finish_build)	build_fini;
Lucio Andrés Illanes Albornoz 2b85d0
			ex_rtl_log_msg info "${BUILD_NFINI:-0} finished, ${_nskipped:-0} skipped, and ${BUILD_NFAIL:-0} failed builds in ${BUILD_NBUILT:-0} build script(s).";
Lucio Andrés Illanes Albornoz 2b85d0
			ex_rtl_log_msg info "Build time: ${BUILD_TIMES_HOURS:-0} hour(s), ${BUILD_TIMES_MINUTES:-0} minute(s), and ${BUILD_TIMES_SECS:-0} second(s).";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			if [ -n "${BUILD_PKGS_FAILED}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 0b72c8
				ex_rtl_log_msg failexit "Build script failure(s) in: ${BUILD_PKGS_FAILED}.";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			fi; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
Lucio Andrés Illanes Albornoz b96c60
	# Group build
Lucio Andrés Illanes Albornoz b96c60
	start_group)	ex_rtl_log_msg inf2 "Starting \`${_group_name}' build group..."; ;;
Lucio Andrés Illanes Albornoz b96c60
	finish_group)	ex_rtl_log_msg suc2 "Finished \`${_group_name}' build group."; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	# Package build
Lucio Andrés Illanes Albornoz fc9bdb
	start_pkg)	ex_rtl_log_msg info "$(printf "[%03d/%03d] Starting \`%s' build..." "${4}" "${5}" "${_pkg_name}")"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	finish_pkg)	: $((BUILD_NFINI+=1));
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			if [ "${ARG_VERBOSE:-0}" -ge 2 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
				cat "${BUILD_WORKDIR}/${_pkg_name}_stderrout.log";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			fi;
Lucio Andrés Illanes Albornoz fc9bdb
			ex_rtl_log_msg succ "$(printf "Finished \`%s' build." "${_pkg_name}")"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	fail_pkg)	: $((BUILD_NFAIL+=1));
Lucio Andrés Illanes Albornoz (arab, vxp) b3d07b
			BUILD_PKGS_FAILED="${BUILD_PKGS_FAILED:+${BUILD_PKGS_FAILED} }${_pkg_name}";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			if [ "${ARG_RELAXED:-0}" -eq 1 ]; then
Lucio Andrés Illanes Albornoz fc9bdb
				ex_rtl_log_msg fail "$(printf "Build failed in \`%s', check \`%s' for details." "${_pkg_name}" "${BUILD_WORKDIR}/${_pkg_name}_stderrout.log")";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			else
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
				ex_rtl_log_msg fail "${BUILD_WORKDIR}/${_pkg_name}_stderrout.log:";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
				cat "${BUILD_WORKDIR}/${_pkg_name}_stderrout.log";
Lucio Andrés Illanes Albornoz da0364
				if [ -n "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}" ]; then
Lucio Andrés Illanes Albornoz da0364
					echo "${_pkg_name}" > "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}";
Lucio Andrés Illanes Albornoz da0364
				fi;
Lucio Andrés Illanes Albornoz fc9bdb
				ex_rtl_log_msg fail "$(printf "Build failed in \`%s'." "${_pkg_name}")";
Lucio Andrés Illanes Albornoz (arab, vxp) 71818e
				if [ "${ARG_PARALLEL:-0}" -eq 1 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 71818e
					ex_rtl_log_msg fail "Terminating pending builds...";
Lucio Andrés Illanes Albornoz (arab, vxp) 71818e
					pkill -P "${$}";
Lucio Andrés Illanes Albornoz (arab, vxp) 71818e
				fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 30ae14
				exit 1;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			fi; ;;
Lucio Andrés Illanes Albornoz fc9bdb
	step_pkg)	ex_rtl_log_msg vucc "$(printf "Finished build step %s of package \`%s'." "${4}" "${_pkg_name}")"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	# Child process
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	exec_finish)	;;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	exec_missing)	ex_rtl_log_msg failexit "Error: package \`${_pkg_name}' missing in build.vars."; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	exec_start)	if [ "${PKG_NO_LOG_VARS:-0}" -eq 0 ]; then
Lucio Andrés Illanes Albornoz 2b85d0
				ex_rtl_log_env_vars "build" $(set | awk -F= '/^PKG_/{print $1}' | sort);
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			fi;
Lucio Andrés Illanes Albornoz f0dfe1
			if [ "${ARG_VERBOSE:-0}" -ge 3 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
				set -o xtrace;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			fi; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	exec_step)	ex_rtl_log_msg info "Finished build step ${4} of package \`${_pkg_name}'."; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	esac; return 0;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
};
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
Lucio Andrés Illanes Albornoz 2b85d0
set +o errexit -o noglob; cd "$(dirname "${0}")";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
for __ in $(find subr -name *.subr); do
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	. "${__}"; done; buildp_dispatch start_build "${@}";
lalbornoz 340f4c
Lucio Andrés Illanes Albornoz fc9bdb
# vim:filetype=sh textwidth=0