midipix / build / midipix_build

Forked from build/midipix_build 4 years ago
Clone

Blame pkgtool.sh

Lucio Andrés Illanes Albornoz 8a27f9
#!/bin/sh
Lucio Andrés Illanes Albornoz 60fba6
# Copyright (c) 2020 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
Lucio Andrés Illanes Albornoz 8a27f9
#
Lucio Andrés Illanes Albornoz 8a27f9
Lucio Andrés Illanes Albornoz 60fba6
pkgtoolp_info() {
Lucio Andrés Illanes Albornoz b6a9a1
	local	_pkg_name="${1}" _group_name="" _pkg_name_uc="$(rtl_toupper "${1}")" _pkg_names="" _rc=0\
Lucio Andrés Illanes Albornoz b6a9a1
		EX_PKG_BUILD_GROUPS="" EX_PKG_DISABLED="" EX_PKG_FINISHED="" EX_PKG_NAMES=""; _status="";
Lucio Andrés Illanes Albornoz b6a9a1
	if ! ex_pkg_load_groups; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="Error: failed to load build groups.";
Lucio Andrés Illanes Albornoz b6a9a1
	elif ! _group_name="$(ex_pkg_find_package "${EX_PKG_BUILD_GROUPS}" "${_pkg_name}")"; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="Error: unknown package \`${_pkg_name}'.";
Lucio Andrés Illanes Albornoz 60fba6
	elif ! _pkg_names="$(ex_pkg_get_packages "${_group_name}")"; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="Error: failed to expand package list of build group \`${_group_name}'.";
Lucio Andrés Illanes Albornoz b6a9a1
	elif ! ex_pkg_env "${DEFAULT_BUILD_STEPS}" "${DEFAULT_BUILD_VARS}"\
Lucio Andrés Illanes Albornoz b6a9a1
			"${_group_name}" 1 "${_pkg_name}" "" "${BUILD_WORKDIR}"; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="Error: failed to set package environment for \`${_pkg_name}'.";
Lucio Andrés Illanes Albornoz b6a9a1
	else	rtl_log_env_vars "package" $(rtl_get_vars_fast "^PKG_${_pkg_name_uc}");
Lucio Andrés Illanes Albornoz e1d469
		if [ -z "${PKG_DEPENDS:-}" ]; then
Lucio Andrés Illanes Albornoz b6a9a1
			rtl_log_msg info "Package \`%s' has no dependencies." "${_pkg_name}";
Lucio Andrés Illanes Albornoz b6a9a1
		else	rtl_log_msg info "Direct dependencies of \`%s': %s" "${_pkg_name}" "${PKG_DEPENDS}";
Lucio Andrés Illanes Albornoz b6a9a1
			if ! ex_pkg_unfold_depends 1 1 "${_group_name}" "${_pkg_names}" "${_pkg_name}" 0; then
Lucio Andrés Illanes Albornoz b6a9a1
				rtl_log_msg warning "Warning: failed to unfold dependency-expanded package name list for \`%s'." "${_pkg_name}";
Lucio Andrés Illanes Albornoz b6a9a1
			else	EX_PKG_NAMES="$(rtl_lfilter "${EX_PKG_NAMES}" "${_pkg_name}")";
Lucio Andrés Illanes Albornoz 60fba6
				if [ -n "${EX_PKG_NAMES}" ]; then
Lucio Andrés Illanes Albornoz b6a9a1
					rtl_log_msg info "Full dependencies of \`%s': %s"\
Lucio Andrés Illanes Albornoz b6a9a1
							"${_pkg_name}" "$(rtl_lsort "${EX_PKG_NAMES}")";
Lucio Andrés Illanes Albornoz 60fba6
				fi;
Lucio Andrés Illanes Albornoz 60fba6
				if [ -n "${EX_PKG_DISABLED}" ]; then
Lucio Andrés Illanes Albornoz b6a9a1
					rtl_log_msg info "Full dependencies of \`%s' (disabled packages:) %s"\
Lucio Andrés Illanes Albornoz b6a9a1
							"${_pkg_name}" "$(rtl_lsort "${EX_PKG_DISABLED}")";
Lucio Andrés Illanes Albornoz 60fba6
				fi;
Lucio Andrés Illanes Albornoz 60fba6
			fi;
Lucio Andrés Illanes Albornoz 60fba6
		fi;
Lucio Andrés Illanes Albornoz b6a9a1
	fi; return "${_rc}";
Lucio Andrés Illanes Albornoz 60fba6
};
Lucio Andrés Illanes Albornoz 60fba6
Lucio Andrés Illanes Albornoz 8a27f9
pkgtoolp_restart_at() {
Lucio Andrés Illanes Albornoz b6a9a1
	local _pkg_name="${1}" _rc=0; _status="";
Lucio Andrés Illanes Albornoz b6a9a1
	if ! ex_pkg_load_dump "${_pkg_name}" "${BUILD_WORKDIR}"; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="${_status}";
Lucio Andrés Illanes Albornoz b6a9a1
	else	case "${ARG_RESTART_AT}" in
Lucio Andrés Illanes Albornoz b6a9a1
		ALL)	if ! "${MIDIPIX_BUILD_PWD}/build.sh" -P -r "${_pkg_name}" -v; then
Lucio Andrés Illanes Albornoz b6a9a1
				_rc=1; _status="Error: failed to run command line ${MIDIPIX_BUILD_PWD}/build.sh -P -r ${_pkg_name} -v";
Lucio Andrés Illanes Albornoz b6a9a1
			fi; ;;
Lucio Andrés Illanes Albornoz b6a9a1
		*)	if ! "${MIDIPIX_BUILD_PWD}/build.sh" -P -r "${_pkg_name}:${ARG_RESTART_AT}" -v; then
Lucio Andrés Illanes Albornoz b6a9a1
				_rc=1; _status="Error: failed to run command line ${MIDIPIX_BUILD_PWD}/build.sh -P -r ${_pkg_name}:${ARG_RESTART_AT} -v";
Lucio Andrés Illanes Albornoz b6a9a1
			fi; ;;
Lucio Andrés Illanes Albornoz b6a9a1
		esac;
Lucio Andrés Illanes Albornoz b6a9a1
	fi; return "${_rc}";
Lucio Andrés Illanes Albornoz 8a27f9
};
Lucio Andrés Illanes Albornoz 8a27f9
Lucio Andrés Illanes Albornoz 60fba6
pkgtoolp_rdepends() {
Lucio Andrés Illanes Albornoz b6a9a1
	local	_pkg_name="${1}" _group_name="" _pkg_names="" _rc=0\
Lucio Andrés Illanes Albornoz b6a9a1
		EX_PKG_BUILD_GROUPS="" EX_PKG_DISABLED="" EX_PKG_FINISHED="" EX_PKG_NAMES=""; _status="";
Lucio Andrés Illanes Albornoz b6a9a1
	if ! ex_pkg_load_groups; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="Error: failed to load build groups.";
Lucio Andrés Illanes Albornoz b6a9a1
	elif ! _group_name="$(ex_pkg_find_package "${EX_PKG_BUILD_GROUPS}" "${_pkg_name}")"; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="Error: unknown package \`${_pkg_name}'.";
Lucio Andrés Illanes Albornoz 60fba6
	elif ! _pkg_names="$(ex_pkg_get_packages "${_group_name}")"; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="Error: failed to expand package list of build group \`${_group_name}'.";
Lucio Andrés Illanes Albornoz b6a9a1
	elif ! ex_pkg_unfold_rdepends "${_group_name}" "${_pkg_names}" "${_pkg_name}" 0; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="Error: failed to unfold reverse dependency-expanded package name list for \`${_pkg_name}'.";
Lucio Andrés Illanes Albornoz 60fba6
	elif [ -z "${EX_PKG_NAMES}" ] && [ -z "${EX_PKG_DISABLED}" ]; then
Lucio Andrés Illanes Albornoz b6a9a1
		rtl_log_msg info "Package \`%s' has no reverse dependencies." "${_pkg_name}";
Lucio Andrés Illanes Albornoz 60fba6
	else	if [ -n "${EX_PKG_NAMES}" ]; then
Lucio Andrés Illanes Albornoz b6a9a1
			rtl_log_msg info "Reverse dependencies of \`%s': %s"\
Lucio Andrés Illanes Albornoz b6a9a1
					"${_pkg_name}" "$(rtl_lsort "${EX_PKG_NAMES}")";
Lucio Andrés Illanes Albornoz 60fba6
		fi;
Lucio Andrés Illanes Albornoz 60fba6
		if [ -n "${EX_PKG_DISABLED}" ]; then
Lucio Andrés Illanes Albornoz b6a9a1
			rtl_log_msg info "Reverse dependencies of \`%s' (disabled packages:) %s"\
Lucio Andrés Illanes Albornoz b6a9a1
					"${_pkg_name}" "$(rtl_lsort "${EX_PKG_DISABLED}")";
Lucio Andrés Illanes Albornoz 60fba6
		fi;
Lucio Andrés Illanes Albornoz b6a9a1
	fi; return "${_rc}";
Lucio Andrés Illanes Albornoz 60fba6
};
Lucio Andrés Illanes Albornoz 60fba6
Lucio Andrés Illanes Albornoz 8a27f9
pkgtoolp_shell() {
Lucio Andrés Illanes Albornoz b6a9a1
	local _pkg_name="${1}" _rc=0; _status="";
Lucio Andrés Illanes Albornoz b6a9a1
	if ! ex_pkg_load_dump "${_pkg_name}" "${BUILD_WORKDIR}"; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="${_status}";
Lucio Andrés Illanes Albornoz b6a9a1
	else	rtl_log_env_vars "package" $(rtl_get_vars_fast "^PKG_");
Lucio Andrés Illanes Albornoz b6a9a1
		rtl_log_msg info "Launching shell \`%s' within package environment and \`%s'." "${SHELL}" "${PKG_BUILD_DIR}";
Lucio Andrés Illanes Albornoz b6a9a1
		rtl_log_msg info "Run \$R to rebuild \`%s'." "${_pkg_name}";
Lucio Andrés Illanes Albornoz b6a9a1
		rtl_log_msg info "Run \$RS <step> to restart the specified build step of \`%s'" "${_pkg_name}";
Lucio Andrés Illanes Albornoz b6a9a1
		rtl_log_msg info "Run \$D to automatically regenerate the patch for \`%s'." "${_pkg_name}";
Lucio Andrés Illanes Albornoz b6a9a1
		export	ARCH BUILD						\
Lucio Andrés Illanes Albornoz b6a9a1
			BUILD_DLCACHEDIR BUILD_WORKDIR				\
Lucio Andrés Illanes Albornoz b6a9a1
			MAKE="make LIBTOOL=${PKG_LIBTOOL:-slibtool}"		\
Lucio Andrés Illanes Albornoz b6a9a1
			MIDIPIX_BUILD_PWD					\
Lucio Andrés Illanes Albornoz b6a9a1
			PKG_NAME						\
Lucio Andrés Illanes Albornoz b6a9a1
			PREFIX PREFIX_CROSS PREFIX_MINGW32 PREFIX_MINIPIX	\
Lucio Andrés Illanes Albornoz b6a9a1
			PREFIX_NATIVE PREFIX_ROOT PREFIX_RPM;
Lucio Andrés Illanes Albornoz b6a9a1
		D="${MIDIPIX_BUILD_PWD}/${0##*/} --update-diff"			\
Lucio Andrés Illanes Albornoz b6a9a1
		R="${MIDIPIX_BUILD_PWD}/${0##*/} --restart-at ALL"		\
Lucio Andrés Illanes Albornoz b6a9a1
		RS="${MIDIPIX_BUILD_PWD}/${0##*/} --restart-at "		\
Lucio Andrés Illanes Albornoz b6a9a1
		"${SHELL}";
Lucio Andrés Illanes Albornoz b6a9a1
	fi; return "${_rc}";
Lucio Andrés Illanes Albornoz 8a27f9
};
Lucio Andrés Illanes Albornoz 8a27f9
Lucio Andrés Illanes Albornoz 60fba6
pkgtoolp_tarball() {
Lucio Andrés Illanes Albornoz b6a9a1
	local	_pkg_name="${1}" _date="" _group_name="" _hname="" _pkg_name_full=""\
Lucio Andrés Illanes Albornoz b6a9a1
		_pkg_version="" _rc=0 _tarball_fname="" EX_PKG_BUILD_GROUPS=""; _status="";
Lucio Andrés Illanes Albornoz b6a9a1
	if ! ex_pkg_load_groups; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="Error: failed to load build groups.";
Lucio Andrés Illanes Albornoz b6a9a1
	elif ! _group_name="$(ex_pkg_find_package "${EX_PKG_BUILD_GROUPS}" "${_pkg_name}")"; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="Error: unknown package \`${_pkg_name}'.";
Lucio Andrés Illanes Albornoz 60fba6
	elif ! ex_pkg_env "${DEFAULT_BUILD_STEPS}" "${DEFAULT_BUILD_VARS}"	\
Lucio Andrés Illanes Albornoz b6a9a1
			"${_group_name}" 0 "${_pkg_name}" "" "${BUILD_WORKDIR}"; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="Error: failed to set package environment for \`${_pkg_name}'.";
Lucio Andrés Illanes Albornoz 60fba6
	elif ! _date="$(date +%Y%m%d_%H%M%S)"; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="Error: failed to call date(1).";
Lucio Andrés Illanes Albornoz 60fba6
	elif ! _hname="$(hostname -f)"; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="Error: failed to call hostname(1).";
Lucio Andrés Illanes Albornoz 60fba6
	else	if [ -n "${PKG_VERSION}" ]; then
Lucio Andrés Illanes Albornoz b6a9a1
			_pkg_name_full="${_pkg_name}-${PKG_VERSION}";
Lucio Andrés Illanes Albornoz 60fba6
		else
Lucio Andrés Illanes Albornoz b6a9a1
			_pkg_name_full="${_pkg_name}";
Lucio Andrés Illanes Albornoz 60fba6
		fi;
Lucio Andrés Illanes Albornoz 60fba6
		_tarball_fname="${_pkg_name_full}@${_hname}-${_date}.tbz2";
Lucio Andrés Illanes Albornoz b6a9a1
		rtl_log_msg info "Creating compressed tarball of \`%s' and \`%s_stderrout.log'..."\
Lucio Andrés Illanes Albornoz b6a9a1
				"${PKG_BASE_DIR}" "${_pkg_name}";
Lucio Andrés Illanes Albornoz 60fba6
		if ! tar -C "${BUILD_WORKDIR}" -cpf -				\
Lucio Andrés Illanes Albornoz 60fba6
				"${PKG_BASE_DIR#${BUILD_WORKDIR%/}/}"		\
Lucio Andrés Illanes Albornoz b6a9a1
				"${_pkg_name}_stderrout.log"			|\
Lucio Andrés Illanes Albornoz 60fba6
					bzip2 -c -9 - > "${_tarball_fname}"; then
Lucio Andrés Illanes Albornoz b6a9a1
			_rc=1; _status="Error: failed to create compressed tarball of \`${PKG_BASE_DIR}' and \`${_pkg_name}_stderrout.log'.";
Lucio Andrés Illanes Albornoz 60fba6
		else
Lucio Andrés Illanes Albornoz b6a9a1
			rtl_log_msg info "Created compressed tarball of \`%s' and \`%s_stderrout.log'."\
Lucio Andrés Illanes Albornoz b6a9a1
					"${PKG_BASE_DIR}" "${_pkg_name}";
Lucio Andrés Illanes Albornoz 60fba6
		fi;
Lucio Andrés Illanes Albornoz b6a9a1
	fi; return "${_rc}";
Lucio Andrés Illanes Albornoz 60fba6
};
Lucio Andrés Illanes Albornoz 60fba6
Lucio Andrés Illanes Albornoz 8a27f9
pkgtoolp_update_diff() {
Lucio Andrés Illanes Albornoz b6a9a1
	local	_pkg_name="${1}" _diff_fname_dst="" _diff_fname_src="" _fname=""\
Lucio Andrés Illanes Albornoz b6a9a1
		_fname_base="" _rc=0; _status="";
Lucio Andrés Illanes Albornoz b6a9a1
	if ! ex_pkg_load_dump "${_pkg_name}" "${BUILD_WORKDIR}"; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="${_status}";
Lucio Andrés Illanes Albornoz b6a9a1
	else	if [ -n "${PKG_VERSION}" ]; then
Lucio Andrés Illanes Albornoz b6a9a1
			_diff_fname_dst="${_pkg_name}-${PKG_VERSION}.local.patch";
Lucio Andrés Illanes Albornoz b6a9a1
		else
Lucio Andrés Illanes Albornoz b6a9a1
			_diff_fname_dst="${_pkg_name}.local.patch";
Lucio Andrés Illanes Albornoz 8a27f9
		fi;
Lucio Andrés Illanes Albornoz b6a9a1
		if ! _diff_fname_src="$(mktemp)"; then
Lucio Andrés Illanes Albornoz b6a9a1
			_rc=1; _status="Error: failed to create temporary target diff(1) file.";
Lucio Andrés Illanes Albornoz b6a9a1
		else	trap "rm -f \"${_diff_fname_src}\" >/dev/null 2>&1" EXIT HUP INT TERM USR1 USR2;
Lucio Andrés Illanes Albornoz b6a9a1
			(cd "${PKG_BASE_DIR}" && printf "" > "${_diff_fname_src}";
Lucio Andrés Illanes Albornoz b6a9a1
			 for _fname in $(find "${PKG_SUBDIR}" -iname \*.orig); do
Lucio Andrés Illanes Albornoz b6a9a1
				_fname_base="${_fname##*/}"; _fname_base="${_fname_base%.orig}";
Lucio Andrés Illanes Albornoz b6a9a1
				case "${_fname_base}" in
Lucio Andrés Illanes Albornoz b6a9a1
				config.sub)
Lucio Andrés Illanes Albornoz b6a9a1
					continue; ;;
Lucio Andrés Illanes Albornoz b6a9a1
				*)	diff -u "${_fname}" "${_fname%.orig}" >> "${_diff_fname_src}"; ;;
Lucio Andrés Illanes Albornoz b6a9a1
				esac;
Lucio Andrés Illanes Albornoz b6a9a1
			done);
Lucio Andrés Illanes Albornoz b6a9a1
			if [ "${?}" -ne 0 ]; then
Lucio Andrés Illanes Albornoz b6a9a1
				_rc=1; _status="Error: failed to create diff(1).";
Lucio Andrés Illanes Albornoz b6a9a1
			elif ! rtl_fileop mv "${_diff_fname_src}" "${MIDIPIX_BUILD_PWD}/patches/${_diff_fname_dst}"; then
Lucio Andrés Illanes Albornoz b6a9a1
				_rc=1; _status="Error: failed to rename diff(1) to \`${MIDIPIX_BUILD_PWD}/patches/${_diff_fname_dst}'.";
Lucio Andrés Illanes Albornoz b6a9a1
			else	trap - EXIT HUP INT TERM USR1 USR2;
Lucio Andrés Illanes Albornoz b6a9a1
				rtl_log_msg info "Updated \`%s/patches/%s'."\
Lucio Andrés Illanes Albornoz b6a9a1
						"${MIDIPIX_BUILD_PWD}" "${_diff_fname_dst}";
Lucio Andrés Illanes Albornoz b6a9a1
			fi;
Lucio Andrés Illanes Albornoz b6a9a1
		fi;
Lucio Andrés Illanes Albornoz b6a9a1
	fi; return "${_rc}";
Lucio Andrés Illanes Albornoz 8a27f9
};
Lucio Andrés Illanes Albornoz 8a27f9
Lucio Andrés Illanes Albornoz 8a27f9
pkgtool() {
Lucio Andrés Illanes Albornoz b6a9a1
	local _rc=0 _status="" BUILD_GROUPS="" ARCH BUILD BUILD_WORKDIR PKGTOOL_PKGNAME PREFIX;
Lucio Andrés Illanes Albornoz b6a9a1
	if ! . "${0%/*}/subr/pkgtool_init.subr"; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; printf "Error: failed to source \`${0%/*}/subr/pkgtool_init.subr'." >&2;
Lucio Andrés Illanes Albornoz b6a9a1
	elif ! pkgtool_init "${@}"; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="${_status}";
Lucio Andrés Illanes Albornoz b6a9a1
	else	case "1" in
Lucio Andrés Illanes Albornoz b6a9a1
		"${ARG_INFO:-0}")		pkgtoolp_info "${PKGTOOL_PKG_NAME}"; ;;
Lucio Andrés Illanes Albornoz b6a9a1
		"${ARG_RDEPENDS:-0}")		pkgtoolp_rdepends "${PKGTOOL_PKG_NAME}"; ;;
Lucio Andrés Illanes Albornoz b6a9a1
		"${ARG_RESTART_AT:+1}")		pkgtoolp_restart_at "${PKGTOOL_PKG_NAME}"; ;;
Lucio Andrés Illanes Albornoz b6a9a1
		"${ARG_SHELL:-0}")		pkgtoolp_shell "${PKGTOOL_PKG_NAME}"; ;;
Lucio Andrés Illanes Albornoz b6a9a1
		"${ARG_TARBALL:-0}")		pkgtoolp_tarball "${PKGTOOL_PKG_NAME}"; ;;
Lucio Andrés Illanes Albornoz b6a9a1
		"${ARG_UPDATE_DIFF:-0}")	pkgtoolp_update_diff "${PKGTOOL_PKG_NAME}"; ;;
Lucio Andrés Illanes Albornoz b6a9a1
		esac; _rc="${?}";
Lucio Andrés Illanes Albornoz b6a9a1
	fi;
Lucio Andrés Illanes Albornoz b6a9a1
	if [ "${_rc}" -ne 0 ]; then
Lucio Andrés Illanes Albornoz b6a9a1
		rtl_log_msg fatalexit "${_status}";
Lucio Andrés Illanes Albornoz b6a9a1
	elif [ -n "${_status}" ]; then
Lucio Andrés Illanes Albornoz b6a9a1
		rtl_log_msg info "${_status}";
Lucio Andrés Illanes Albornoz 8a27f9
	fi;
Lucio Andrés Illanes Albornoz 8a27f9
};
Lucio Andrés Illanes Albornoz 8a27f9
Lucio Andrés Illanes Albornoz e1d469
set +o errexit -o noglob -o nounset; pkgtool "${@}";
Lucio Andrés Illanes Albornoz 8a27f9
Lucio Andrés Illanes Albornoz 8a27f9
# vim:filetype=sh textwidth=0