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 b96c60
	local _msg="${1}" _group_name="${2}" _pkg_name="${3}"					\
Lucio Andrés Illanes Albornoz b96c60
		_build_group_meta="" _build_group_lc="" _build_groups_lc="" _last_pkg="" _pkg_restart="" PKGS_FOUND;
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 ed4109
	start_build)	shift; build_args "${@}"; build_init;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			ex_rtl_log_set_vnfo_lvl "${ARG_VERBOSE:-0}";
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 0eaee4
			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 cc86a5
			if [ "${ARG_RESTART}" = "LAST" ]; then
Lucio Andrés Illanes Albornoz cc86a5
				if [ -n "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}" ]\
Lucio Andrés Illanes Albornoz cc86a5
				&& [ -e "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}" ]; then
Lucio Andrés Illanes Albornoz cc86a5
					_last_pkg="$(cat "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}")";
Lucio Andrés Illanes Albornoz cc86a5
					ex_rtl_fileop rm "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}";
Lucio Andrés Illanes Albornoz cc86a5
					ex_rtl_state_clear "${BUILD_WORKDIR}" "${_last_pkg}";
Lucio Andrés Illanes Albornoz cc86a5
				fi;
Lucio Andrés Illanes Albornoz cc86a5
			fi;
Lucio Andrés Illanes Albornoz b376ae
			PKGS_FOUND="";
Lucio Andrés Illanes Albornoz b96c60
			for _build_group_lc in ${_build_groups_lc}; do
Lucio Andrés Illanes Albornoz b96c60
				ex_pkg_dispatch "${_build_group_lc}"				\
Lucio Andrés Illanes Albornoz (arab, vxp) 1dfec6
						"${ARG_RESTART}" "${ARG_RESTART_AT}"		\
Lucio Andrés Illanes Albornoz b376ae
						buildp_dispatch PKGS_FOUND;
Lucio Andrés Illanes Albornoz (arab, vxp) 1dfec6
				if [ ${?} -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 da0364
				if ! ex_rtl_lmatch "ALL LAST" " " "${_pkg_restart}"		\
Lucio Andrés Illanes Albornoz b376ae
				&& ! ex_rtl_lmatch "${PKGS_FOUND}" " " "${_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 00c762
			if ! ex_pkg_dispatch "invariants" "ALL" "ALL" buildp_dispatch ""; 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 (arab, vxp) ec19f0
			ex_rtl_log_msg info "${BUILD_NFINI} finished, ${BUILD_NSKIP} skipped, and ${BUILD_NFAIL} failed builds in ${BUILD_NBUILT} build script(s).";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			ex_rtl_log_msg info "Build time: ${BUILD_TIMES_HOURS} hour(s), ${BUILD_TIMES_MINUTES} minute(s), and ${BUILD_TIMES_SECS} 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 efc22a
	disabled_pkg)	: $((BUILD_NSKIP+=1));
Lucio Andrés Illanes Albornoz fc9bdb
			ex_rtl_log_msg vnfo "$(printf "[%03d/%03d] Skipping disabled package \`%s.'" "${4}" "${5}" "${_pkg_name}")"; ;;
Lucio Andrés Illanes Albornoz efc22a
	skipped_pkg)	: $((BUILD_NSKIP+=1));
Lucio Andrés Illanes Albornoz fc9bdb
			ex_rtl_log_msg vnfo "$(printf "[%03d/%03d] Skipping finished package \`%s.'" "${4}" "${5}" "${_pkg_name}")"; ;;
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 (arab, vxp) ec19f0
				ex_rtl_log_env_vars "build"		\
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
					$(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 (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