Blame subr.ex/ex_pkg.subr

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
874146
e9fa07
#
e9fa07
# ex_pkg_check_depends() - check single named package for unsatisfied dependencies
e9fa07
# @_checkfl:		enable (1) or inhibit (0) dependency expansion
7d702f
# @_rpkg_disabled:	in reference to variable of list of disabled packages
7d702f
# @_rpkg_finished:	in reference to variable of list of finished packages
e9fa07
# @_pkg_name:		single package name
7d702f
# @_rpkg_names:		in reference to variable of list of package names
e9fa07
# @_workdir:		pathname to build-specific temporary directory
e9fa07
#
99f4d8
# Returns:		zero (0) given no outstanding dependencies, non-zero (>0) otherwise
e9fa07
# Side effects:		${PKG_${_PKG_NAME}_DEPENDS_FULL} may be mutated
e9fa07
#
e9fa07
ex_pkg_check_depends() {
e9fa07
	local	_epcd_checkfl="${1}" _epcd_rpkg_disabled="${2}" _epcd_rpkg_finished="${3#\$}"	\
e9fa07
		_epcd_pkg_name="${4}" _epcd_rpkg_names="${5#\$}" _epcd_workdir="${6}"		\
e9fa07
		_epcd_dependfl=0 _epcd_depends="" _epcd_pkg_name_depend="";
e9fa07
e9fa07
	if [ "${_epcd_checkfl}" -eq 1 ]; then
e9fa07
		if ! rtl_get_var_unsafe \$_epcd_depends -u "PKG_"${_epcd_pkg_name}"_DEPENDS_FULL"\
e9fa07
		|| [ "${_epcd_depends:+1}" != 1 ];
e9fa07
		then
e9fa07
			if rtl_get_var_unsafe \$_epcd_depends -u "PKG_"${_epcd_pkg_name}"_DEPENDS";
e9fa07
			then
e9fa07
				eval PKG_"${_epcd_pkg_name}"_DEPENDS_FULL='$(rtl_uniq ${_epcd_depends})';
e9fa07
			else
e9fa07
				return 0;
e9fa07
			fi;
e9fa07
		fi;
e9fa07
e9fa07
		for _epcd_pkg_name_depend in ${_epcd_depends}; do
e9fa07
			if ! rtl_lmatch "${_epcd_rpkg_disabled}" "${_epcd_pkg_name_depend}"\
e9fa07
			&& ! ex_pkg_state_test2 "${_epcd_workdir}" "${_epcd_pkg_name_depend}" finish;
e9fa07
			then
e9fa07
				if ! rtl_lmatch "${_epcd_rpkg_names}" "${_epcd_pkg_name_depend}"; then
4243a1
					rtl_log_msgV "fatalexit" "${MSG_build_unknown_dep}" "${_epcd_pkg_name_depend}" "${_epcd_pkg_name}";
e9fa07
				else
e9fa07
					_epcd_dependfl=1; break;
e9fa07
				fi;
e9fa07
			fi;
e9fa07
		done;
e9fa07
	fi;
e9fa07
e9fa07
	return "${_epcd_dependfl}";
e9fa07
};
e9fa07
e9fa07
#
e9fa07
# ex_pkg_find_package() - find build group a single named package belongs to
7d702f
# @_rgroup_name:	out reference to variable of build group name
e9fa07
# @_group_names:	build group names
e9fa07
# @_pkg_name:		single named package
e9fa07
#
99f4d8
# Returns:		zero (0) on success, non-zero (>0) if package not found, group name on stdout if package was found.
e9fa07
#
e9fa07
ex_pkg_find_package() {
e9fa07
	local	_epfp_rgroup_name="${1#\$}" _epfp_group_names="${2}" _epfp_pkg_name="${3}"	\
e9fa07
		_epfp_foundfl=0 _epfp_group_name="" _epfp_pkg_names="";
e9fa07
e9fa07
	for _epfp_group_name in ${_epfp_group_names}; do
e9fa07
		if rtl_get_var_unsafe \$_epfp_pkg_names -u "${_epfp_group_name}_PACKAGES"\
e9fa07
		&& [ "${_epfp_pkg_names:+1}" = 1 ]\
e9fa07
		&& rtl_lmatch \$_epfp_pkg_names "${_epfp_pkg_name}"; then
e9fa07
			_epfp_foundfl=1; break;
e9fa07
		fi;
e9fa07
	done;
e9fa07
e9fa07
	case "${_epfp_foundfl:-0}" in
e9fa07
	0)	eval ${_epfp_rgroup_name}=;
e9fa07
		return 1; ;;
e9fa07
e9fa07
	1)	eval ${_epfp_rgroup_name}='${_epfp_group_name}';
e9fa07
		return 0; ;;
e9fa07
	esac;
e9fa07
};
e9fa07
e9fa07
#
fd38dc
# ex_pkg_get_default() - get single package default value
7d702f
# @_rdefault:		out reference to variable of default value or "" on end of list
138059
# @_default_idx:	one-based single default value index
fd38dc
# @_pkg_name:		single package name
fd38dc
# @_pkg_version:	single package version
80a5c9
# @_ldefault:		SP-separated list of default value names (any of: patches, patches_pre, vars_files)
fd38dc
#
99f4d8
# Returns:		zero (0) on success, non-zero (>0) on invalid default value name or unknown package.
fd38dc
#
fd38dc
ex_pkg_get_default() {
138059
	local	_epgd_rdefault="${1#\$}" _epgd_default_idx="${2}" _epgd_pkg_name="${3}"	\
138059
		_epgd_pkg_version="${4}" _epgd_ldefault="${5}"				\
80a5c9
		_epgd_default="" _epgd_group_name="" _epgd_patch_fname=""		\
80a5c9
		_epgd_pkg_name_full="" _epgd_pkg_patches_extra="" _epgd_rc=0;
fd38dc
fd38dc
	set --;
fd38dc
	_epgd_pkg_name_full="${_epgd_pkg_name}${_epgd_pkg_version:+-${_epgd_pkg_version}}";
fd38dc
	_epgd_rc=0;
fd38dc
fd38dc
	for _epgd_default in ${_epgd_ldefault}; do
fd38dc
		case "${_epgd_default}" in
fd38dc
		patches)
138059
			rtl_get_var_unsafe \$_epgd_pkg_patches_extra -u "PKG_${_epgd_pkg_name}_PATCHES_EXTRA";
fd38dc
			set +o noglob;
fd38dc
			set --												\
fd38dc
				"${@}"											\
ebe7b3
				"${MIDIPIX_BUILD_PWD}/patches/${_epgd_pkg_name}/"*.patch				\
fd38dc
				"${MIDIPIX_BUILD_PWD}/patches/${_epgd_pkg_name_full}.local.patch"			\
fd38dc
				"${MIDIPIX_BUILD_PWD}/patches/${_epgd_pkg_name_full}.local@${BUILD_HNAME}.patch"	\
fd38dc
				${_epgd_pkg_patches_extra};
fd38dc
			set -o noglob;
fd38dc
			;;
fd38dc
fd38dc
		patches_pre)
fd38dc
			set --										\
fd38dc
				"${@}"									\
fd38dc
				"${MIDIPIX_BUILD_PWD}/patches/${_epgd_pkg_name_full}_pre.local.patch"	\
fd38dc
				"${MIDIPIX_BUILD_PWD}/patches/${_epgd_pkg_name_full}_pre.local@${BUILD_HNAME}.patch";
fd38dc
			;;
fd38dc
80a5c9
		vars_files)
80a5c9
			rtl_get_var_unsafe \$_epgd_group_name -u "PKG_${_epgd_pkg_name}_GROUP";
80a5c9
			set --					\
80a5c9
				"vars/${_epgd_pkg_name}.vars"	\
80a5c9
				"vars.${_epgd_group_name}/${_epgd_pkg_name}.vars";
fd38dc
			;;
fd38dc
fd38dc
		*)
fd38dc
			_epgd_rc=1; break;
fd38dc
			;;
fd38dc
		esac;
fd38dc
	done;
fd38dc
fd38dc
	if [ "${_epgd_rc}" = 0 ]; then
fd38dc
		eval ${_epgd_rdefault}="\${${_epgd_default_idx}:-}";
fd38dc
	fi;
fd38dc
fd38dc
	return "${_epgd_rc}";
fd38dc
};
fd38dc
fd38dc
#
e9fa07
# ex_pkg_get_packages() - get list of packages belonging to single named build group
7d702f
# @_rpkg_names:	out reference to variable of package names
e9fa07
# @_group_name:	build group name
e9fa07
#
99f4d8
# Returns:	zero (0) on success, non-zero (>0) on failure, list of package names on stdout on success.
e9fa07
#
e9fa07
ex_pkg_get_packages() {
e9fa07
	local	_epgp_rpkg_names="${1#\$}" _epgp_group_name="${2}"	\
e9fa07
		_epgp_pkg_names="";
e9fa07
e9fa07
	if rtl_get_var_unsafe \$_epgp_pkg_names -u "${_epgp_group_name}_PACKAGES"\
e9fa07
	&& [ "${_epgp_pkg_names:+1}" = 1 ]; then
e9fa07
		eval ${_epgp_rpkg_names}='${_epgp_pkg_names}';
e9fa07
		return 0;
e9fa07
	else
e9fa07
		eval ${_epgp_rpkg_names}=;
e9fa07
		return 1;
e9fa07
	fi;
e9fa07
};
e9fa07
e9fa07
#
34eeaf
# ex_pkg_get_package_vars() - get package variable names
34eeaf
# @_rpkg_vnames:		out reference to package variable names variable
34eeaf
# @_build_vars_default:		list of default build variables
34eeaf
# @_pkg_name:			single package name
34eeaf
#
34eeaf
# Returns:			zero (0) on success, non-zero (>0) on failure, list of package names on stdout on success.
34eeaf
#
34eeaf
ex_pkg_get_package_vars() {
34eeaf
	local	_epgpv_rpkg_vnames="${1#\$}" _epgpv_build_vars_default="${2}" _epgpv_pkg_name="${3}"	\
34eeaf
		_epgpv_pkg_name_uc="" _epgpv_vname="" _epgpv_vnames="";
34eeaf
	rtl_toupper2 \$_epgpv_pkg_name \$_epgpv_pkg_name_uc;
34eeaf
34eeaf
	for _epgpv_vname in ${_epgpv_build_vars_default}; do
34eeaf
		if eval [ \"\${PKG_${_epgpv_pkg_name_uc}_${_epgpv_vname}:+1}\" = 1 ]; then
34eeaf
			rtl_lconcat \$_epgpv_vnames "PKG_${_epgpv_pkg_name_uc}_${_epgpv_vname}";
34eeaf
		fi;
34eeaf
	done;
34eeaf
34eeaf
	eval ${_epgpv_rpkg_vnames}='${_epgpv_vnames}';
34eeaf
	return 0;
34eeaf
}
34eeaf
34eeaf
#
e9fa07
# ex_pkg_load_vars() - load build variables
f6f7f2
# @_rstatus:		out reference to status string
f6f7f2
# @_rbuild_arch:	in reference to build architecture
f6f7f2
# @_rbuild_kind:	in reference to build kind
e9fa07
#
99f4d8
# Returns:	zero (0) on success, non-zero (>0) on failure, build variables post-return on success.
e9fa07
#
e9fa07
ex_pkg_load_vars() {
1aa81c
	local	_eplv_rstatus="${1#\$}" _eplv_rbuild_arch="${2#\$}" _eplv_rbuild_kind="${3#\$}"	\
f6f7f2
		_eplv_build_arch="" _eplv_rc=0 _eplv_fname="";
e9fa07
f6f7f2
	if ! rtl_lmatch "${_eplv_rbuild_arch}" "nt32 nt64"; then
e9fa07
		_eplv_rc=1;
f6f7f2
		rtl_setrstatus "${_eplv_rstatus}" 'invalid architecture \`${'"${_eplv_rbuild_arch}"'}'\''.';
f6f7f2
	elif ! rtl_lmatch "${_eplv_rbuild_kind}" "debug release"; then
e9fa07
		_eplv_rc=1;
f6f7f2
		rtl_setrstatus "${_eplv_rstatus}" 'unknown build type \`${'"${_eplv_rbuild_kind}"'}'\''.';
e9fa07
	else
f6f7f2
		eval _eplv_build_arch="\${${_eplv_rbuild_arch}}";
f6f7f2
		case "${_eplv_build_arch}" in
e9fa07
		nt32)	DEFAULT_TARGET="i686-nt32-midipix"; ;;
e9fa07
		nt64)	DEFAULT_TARGET="x86_64-nt64-midipix"; ;;
e9fa07
		esac;
e9fa07
6370be
		if [ "${PREFIX_ROOT:+1}" ]\
6370be
		&& [ "${PREFIX_ROOT#/}" = "${PREFIX_ROOT}" ]; then
6370be
			PREFIX_ROOT="${PWD%/}/${PREFIX_ROOT}";
6370be
		fi;
6370be
		if [ "${PREFIX:+1}" ]\
6370be
		&& [ "${PREFIX#/}" = "${PREFIX}" ]; then
1aa81c
			PREFIX="${PWD%/}/${PREFIX}";
1aa81c
		fi;
1aa81c
e9fa07
		for _eplv_fname in				\
e9fa07
				"${HOME}/midipix_build.vars"	\
e9fa07
				"${HOME}/.midipix_build.vars"	\
bf1a83
				../midipix_build.vars;
e9fa07
		do
e9fa07
			if [ -r "${_eplv_fname}" ]; then
e9fa07
				rtl_fileop source "${_eplv_fname}";
e9fa07
			fi;
e9fa07
		done;
bf1a83
bf1a83
		set +o noglob;
bf1a83
		for _eplv_fname in				\
fe0f0a
				./vars.env.d/*.env;
bf1a83
		do
bf1a83
			set -o noglob;
bf1a83
			if [ -r "${_eplv_fname}" ]; then
bf1a83
				rtl_fileop source "${_eplv_fname}";
bf1a83
			fi;
bf1a83
		done;
bf1a83
		set -o noglob;
e9fa07
	fi;
e9fa07
e9fa07
	return "${_eplv_rc}";
e9fa07
};
e9fa07
e9fa07
#
e9fa07
# ex_pkg_load_groups() - load all available build groups
7d702f
# @_rgroups:		out reference to variable of build groups
7d702f
# @_rgroups_noauoto:	optional out reference to variable of build groups not built automatically
e9fa07
#
99f4d8
# Returns:		zero (0) on success, non-zero (>0) on failure.
e9fa07
#
e9fa07
ex_pkg_load_groups() {
874146
	local	_eplg_rgroups="${1#\$}" _eplg_rgroups_noauto="${2#\$}"	\
874146
		_eplg_build_groups="" _eplg_build_groups_noauto="" _eplg_fname="";
e9fa07
874146
	EXP_PKG_REGISTER_GROUP_RGROUPS="${_eplg_rgroups}";
874146
	EXP_PKG_REGISTER_GROUP_RGROUPS_NOAUTO="${_eplg_rgroups_noauto}";
78240c
	for _eplg_fname in $(find ./groups.d -name *.group | sort); do
874146
		rtl_fileop source_with_fnamevar "${_eplg_fname}";
e9fa07
	done;
874146
	unset EXP_PKG_REGISTER_GROUP_RGROUPS;
874146
	unset EXP_PKG_REGISTER_GROUP_RGROUPS_NOAUTO;
e9fa07
b2c1ea
	for _eplg_fname in $(find ./groups.d -mindepth 2 -name *.package | sort); do
b2c1ea
		rtl_fileop source_with_fnamevar "${_eplg_fname}";
b2c1ea
	done;
b2c1ea
e9fa07
	return 0;
e9fa07
};
e9fa07
e9fa07
#
b2c1ea
# ex_pkg_register() - register single package
b2c1ea
# @_pkg_name:		single package name
b2c1ea
# @_fname:		pathname to file package is defined in, relative to midipix_build root
b2c1ea
# @[_group_name]:	optional build group name; inferred from @_fname if not specified
b2c1ea
#
b2c1ea
# Returns:		zero (0) on success, non-zero (>0) on failure.
b2c1ea
#
b2c1ea
ex_pkg_register() {
b2c1ea
	local	_epr_pkg_name="${1}" _epr_fname="${2}" _epr_group_name="${3:-}"	\
b2c1ea
		_epr_group_name_uc="" _epr_group_noautofl=0;
b2c1ea
b2c1ea
	if [ "${_epr_group_name:+1}" != 1 ]; then
b2c1ea
		_epr_group_name="${_epr_fname#./*/}";
b2c1ea
		_epr_group_name="${_epr_group_name%%/*}";
b2c1ea
		_epr_group_name="${_epr_group_name%.d}";
b2c1ea
		_epr_group_name="${_epr_group_name#*.}";
b2c1ea
	fi;
b2c1ea
b2c1ea
	rtl_toupper2 \$_epr_group_name \$_epr_group_name_uc;
b2c1ea
	rtl_lconcat "\$${_epr_group_name_uc}_PACKAGES" "${_epr_pkg_name}";
b2c1ea
	rtl_set_var_unsafe -u "PKG_${_epr_pkg_name}_GROUP" "${_epr_group_name}";
b2c1ea
	rtl_set_var_unsafe -u "PKG_${_epr_pkg_name}_GROUP_FNAME" "${_epr_fname}";
b2c1ea
b2c1ea
	return 0;
b2c1ea
};
b2c1ea
b2c1ea
#
874146
# ex_pkg_register_group() - register single group
874146
# @_group_name:					single group name
874146
# @_fname:					pathname to file group is defined in, relative to midipix_build root
874146
# @[_autofl]:					"auto" for groups to build by default, "noauto" for optional groups only built when requested
874146
# ${EXP_PKG_REGISTER_GROUP_RGROUPS}:		inout reference to variable of build groups
874146
# ${EXP_PKG_REGISTER_GROUP_RGROUPS_NOAUTO}:	inout reference to variable of build groups only built when requested
874146
#
874146
# Returns:		zero (0) on success, non-zero (>0) on failure.
874146
#
874146
ex_pkg_register_group() {
874146
	local	_eprg_group_name="${1}" _eprg_fname="${2}" _eprg_autofl="${3:-auto}"	\
874146
		_eprg_pkg_name="" _eprg_pkg_names="" _eprg_rgroups="";
874146
874146
	case "${_eprg_autofl}" in
874146
	auto)	_eprg_rgroups="${EXP_PKG_REGISTER_GROUP_RGROUPS}"; ;;
874146
	noauto)	_eprg_rgroups="${EXP_PKG_REGISTER_GROUP_RGROUPS_NOAUTO}"; ;;
874146
	*)	;;
874146
	esac;
874146
	if ! rtl_lmatch "${_eprg_rgroups}" "${_eprg_group_name}"; then
874146
		rtl_lconcat "${_eprg_rgroups}" "${_eprg_group_name}";
874146
	fi;
874146
874146
	if rtl_get_var_unsafe \$_eprg_pkg_names -u "${_eprg_group_name}_PACKAGES"\
874146
	&& [ "${_eprg_pkg_names:+1}" = 1 ]; then
874146
		case "${_eprg_autofl}" in
a37133
		auto)
874146
			for _eprg_pkg_name in ${_eprg_pkg_names}; do
874146
				rtl_set_var_unsafe -u "PKG_${_eprg_pkg_name}_GROUP" "${_eprg_group_name}";
874146
				rtl_set_var_unsafe -u "PKG_${_eprg_pkg_name}_GROUP_FNAME" "${_eprg_fname}";
874146
			done;
874146
			;;
874146
		esac;
874146
	fi;
874146
874146
	return 0;
874146
};
874146
874146
#
e9fa07
# ex_pkg_unfold_depends() - unfold list of package names into dependency-expanded set of complete, disabled, finished, and outstanding package names
7d702f
# @_rdisabled:		in reference toout variable of disabled packages
7d702f
# @_rfinished:		in reference toout variable of finished packages
7d702f
# @_rnames:		out reference to variable of package names
e9fa07
# @_checkfl:		enable (1) or inhibit (0) dependency expansion
e9fa07
# @_forcefl:		enable (1) or inhibit (0) forcibly rebuilding finished packages
e9fa07
# @_group_name:		build group name
e9fa07
# @_pkg_names:		list of package names
e9fa07
# @_restart:		optional whitespace-separated list of package names to rebuild
e9fa07
# @_test_finished:	only exclude disabled packages (0,) split finished packages
e9fa07
# @_workdir:		pathname to build-specific temporary directory
e9fa07
#
99f4d8
# Returns:		zero (0) on success, non-zero (>0) on failure.
e9fa07
#
e9fa07
ex_pkg_unfold_depends() {
e9fa07
	local	_epud_rdisabled="${1#\$}" _epud_rfinished="${2#\$}" _epud_rnames="${3#\$}"	\
e9fa07
		_epud_checkfl="${4}" _epud_forcefl="${5}" _epud_group_name="${6}"		\
e9fa07
		_epud_pkg_names="${7}" _epud_restart="${8}" _epud_test_finished="${9}"		\
e9fa07
		_epud_workdir="${10}"								\
e9fa07
		_epud_pkg_disabled="" _epud_pkg_force="" _epud_pkg_name=""			\
e9fa07
		_epud_pkg_names_new=""	_epud_restartfl=0;
e9fa07
e9fa07
	if [ "${_epud_restart:+1}" = 1 ]\
e9fa07
	&& ! rtl_lmatch \$_epud_restart "ALL LAST"; then
e9fa07
		rtl_lsearch \$_epud_pkg_names "${_epud_restart}";
e9fa07
	fi;
e9fa07
	if [ "${_epud_restart:+1}" = 1 ]\
e9fa07
	&& [ "${_epud_checkfl:-0}" -eq 1 ]; then
dbea96
		rtl_lunfold_dependsV 'PKG_${_rld_name}_DEPENDS' \$_epud_pkg_names ${_epud_pkg_names};
e9fa07
		_epud_pkg_names="$(rtl_uniq ${_epud_pkg_names})";
e9fa07
	fi;
e9fa07
e9fa07
	for _epud_pkg_name in ${_epud_pkg_names}; do
e9fa07
		if [ "${_epud_restart}" = "ALL" ]\
e9fa07
		|| rtl_lmatch \$_epud_restart "${_epud_pkg_name}"; then
e9fa07
			_epud_restartfl=1;
e9fa07
		else
e9fa07
			_epud_restartfl=0;
e9fa07
		fi;
e9fa07
e9fa07
		if rtl_get_var_unsafe \$_epud_pkg_disabled -u "PKG_${_epud_pkg_name}_DISABLED"\
e9fa07
		&& [ "${_epud_pkg_disabled}" = 1 ];
e9fa07
		then
e9fa07
			rtl_lconcat "${_epud_rdisabled}" "${_epud_pkg_name}";
e9fa07
e9fa07
		elif [ "${_epud_test_finished:-1}" -eq 1 ]\
e9fa07
		&&   ex_pkg_state_test2 "${_epud_workdir}" "${_epud_pkg_name}" finish\
e9fa07
		&&   [ "${_epud_restartfl:-0}" -eq 0 ]\
e9fa07
		&&   [ "${_epud_forcefl:-0}" -ne 1 ]\
e9fa07
		&&   rtl_get_var_unsafe \$_epud_pkg_force -u "${_epud_group_name}_FORCE"\
e9fa07
		&&   [ "${_epud_pkg_force}" != 1 ];
e9fa07
		then
e9fa07
			rtl_lconcat "${_epud_rfinished}" "${_epud_pkg_name}";
e9fa07
e9fa07
		else
e9fa07
			rtl_lconcat \$_epud_pkg_names_new "${_epud_pkg_name}";
e9fa07
		fi;
e9fa07
	done;
e9fa07
e9fa07
	eval ${_epud_rdisabled}='$(rtl_uniq2 "${_epud_rdisabled}")';
e9fa07
	eval ${_epud_rfinished}='$(rtl_uniq2 "${_epud_rfinished}")';
e9fa07
	eval ${_epud_rnames}='$(rtl_uniq "${_epud_pkg_names_new}")';
e9fa07
e9fa07
	return 0;
e9fa07
};
e9fa07
e9fa07
#
e9fa07
# ex_pkg_unfold_rdepends() - unfold list of package names into reverse dependency-expanded set of complete, disabled, finished, and outstanding package names
7d702f
# @_rdisabled:		in reference toout variable of disabled packages
7d702f
# @_rfinished:		in reference toout variable of finished packages
7d702f
# @_rnames:		out reference to variable of package names
e9fa07
# @_group_name:		build group name
e9fa07
# @_pkg_names:		list of package names
e9fa07
# @_restart:		optional whitespace-separated list of package names to rebuild
e9fa07
# @_test_finished:	only exclude disabled packages (0,) split finished packages
e9fa07
# @_workdir:		pathname to build-specific temporary directory
e9fa07
#
99f4d8
# Returns:		zero (0) on success, non-zero (>0) on failure.
e9fa07
#
e9fa07
ex_pkg_unfold_rdepends() {
e9fa07
	local	_epur_rdisabled="${1#\$}" _epur_rfinished="${2#\$}" _epur_rnames="${3#\$}"	\
e9fa07
		_epur_group_name="${4}" _epur_pkg_names="${5}" _epur_restart="${6}"		\
e9fa07
		_epur_test_finished="${7}" _epur_workdir="${8}"					\
e9fa07
		_epur_depends="" _epur_disabled=0 _epur_force=0 _epur_pkg_depends=""		\
e9fa07
		_epur_pkg_name="" _epur_pkg_names_new="" _epur_pkg_name_depend=""		\
e9fa07
		_epur_pkg_rdepends="";
e9fa07
e9fa07
	for _epur_pkg_name_depend in ${_epur_restart}; do
e9fa07
		for _epur_pkg_name in ${_epur_pkg_names}; do
e9fa07
			if [ "${_epur_pkg_name}" = "${_epur_pkg_name_depend}" ]; then
e9fa07
				continue;
e9fa07
e9fa07
			elif rtl_get_var_unsafe \$_epur_depends -u "PKG_"${_epur_pkg_name}"_DEPENDS"\
dbea96
			  && rtl_lunfold_dependsV 'PKG_${_rld_name}_DEPENDS' \$_epur_pkg_depends ${_epur_depends}\
e9fa07
			  && [ "${_epur_pkg_depends:+1}" = 1 ]\
e9fa07
			  && rtl_lmatch \$_epur_pkg_depends "${_epur_pkg_name_depend}";
e9fa07
			then
e9fa07
				if rtl_get_var_unsafe \$_epur_disabled -u "PKG_${_epur_pkg_name}_DISABLED"\
e9fa07
				&& [ "${_epur_disabled}" = 1 ];
e9fa07
				then
e9fa07
					rtl_lconcat "${_epur_rdisabled}" "${_epur_pkg_name}";
e9fa07
e9fa07
				elif [ "${_epur_test_finished}" -eq 1 ]\
e9fa07
				&&   ex_pkg_state_test2 "${_epur_workdir}" "${_epur_pkg_name}" finish\
e9fa07
				&&   rtl_get_var_unsafe \$_epur_force -u "${_epur_group_name}_FORCE"\
e9fa07
				&&   [ "${_epur_force}" != 1 ];
e9fa07
				then
e9fa07
					rtl_lconcat "${_epur_rfinished}" "${_epur_pkg_name}";
e9fa07
e9fa07
				elif [ "${_epur_test_finished:-1}" -eq 0 ]\
e9fa07
				||   ! ex_pkg_state_test2 "${_epur_workdir}" "${_epur_pkg_name}" finish\
e9fa07
				||   ( rtl_get_var_unsafe \$_epur_force -u "${_epur_group_name}_FORCE"\
e9fa07
				&&   [ "${_epur_force}" = 1 ] );
e9fa07
				then
e9fa07
					rtl_lconcat \$_epur_pkg_names_new "${_epur_pkg_name}";
e9fa07
				fi;
e9fa07
			fi;
e9fa07
		done;
e9fa07
	done;
e9fa07
e9fa07
	eval ${_epur_rdisabled}='$(rtl_uniq2 "${_epur_rdisabled}")';
e9fa07
	eval ${_epur_rfinished}='$(rtl_uniq2 "${_epur_rfinished}")';
e9fa07
	eval ${_epur_rnames}='$(rtl_uniq "${_epur_pkg_names_new}")';
e9fa07
e9fa07
	return 0;
e9fa07
};
e9fa07
e9fa07
# vim:filetype=sh textwidth=0