Blame build.sh

lalbornoz 340f4c
#!/bin/sh
Lucio Andrés Illanes Albornoz (arab, vxp) a39ccb
# Copyright (c) 2016, 2017 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 (arab, vxp) 1dfec6
	local _msg="${1}" _pkg_name="${2}" _tgt_name="${3}"					\
Lucio Andrés Illanes Albornoz cc86a5
		_build_tgt_meta="" _build_tgt_lc="" _build_tgts_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 0eaee4
			_build_tgts_lc="${BUILD_TARGETS:-${TARGETS_DEFAULT}}";
Lucio Andrés Illanes Albornoz 0eaee4
			if ! ex_rtl_lmatch "${ARG_DIST}" , rpm; then
Lucio Andrés Illanes Albornoz 0eaee4
				_build_tgts_lc="$(ex_rtl_lfilter_not "${_build_tgts_lc}" "host_tools_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 0eaee4
			for _build_tgt_lc in ${_build_tgts_lc}; do
Lucio Andrés Illanes Albornoz (arab, vxp) 1dfec6
				ex_pkg_dispatch "${_build_tgt_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 (arab, vxp) ec19f0
	# Target build
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	start_target)	ex_rtl_log_msg inf2 "Starting \`${_tgt_name}' build target..."; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	finish_target)	ex_rtl_log_msg suc2 "Finished \`${_tgt_name}' build target."; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	# Package build
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	start_pkg)	ex_rtl_log_msg info "Starting \`${_pkg_name}' build..."; ;;
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 (arab, vxp) ec19f0
			ex_rtl_log_msg succ "Finished \`${_pkg_name}' build."; ;;
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 (arab, vxp) ec19f0
				ex_rtl_log_msg fail "Build failed in \`${_pkg_name}', check \`${BUILD_WORKDIR}/${_pkg_name}_stderrout.log' for details.";
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 (arab, vxp) 30ae14
				ex_rtl_log_msg fail "Build failed in \`${_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 efc22a
			ex_rtl_log_msg vnfo "Skipping disabled package \`${_pkg_name}.'"; ;;
Lucio Andrés Illanes Albornoz efc22a
	skipped_pkg)	: $((BUILD_NSKIP+=1));
Lucio Andrés Illanes Albornoz efc22a
			ex_rtl_log_msg vnfo "Skipping finished package \`${_pkg_name}.'"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 5c1ec1
	step_pkg)	ex_rtl_log_msg vucc "Finished build step ${4} of package \`${_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
lalbornoz 340f4c
# vim:filetype=sh