summaryrefslogtreecommitdiffhomepage
path: root/subr/ex_pkg_dispatch.subr
blob: fc1ddaa9b539b16ea99ed022cd053fb80fae0ec5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#
# set -o errexit -o noglob are assumed.
#

ex_pkg_dispatch() {
	local _tgt_name="${1}" _pkg_name="${2}"		\
		_restart="${3}" _restart_at="${4}"	\
		_pkg_step_cmds _pkg_step_cmd_args;
	if [ "${_pkg_name#*_flavour_*}" != "${_pkg_name}" ]; then
		PKG_NAME_PARENT="${_pkg_name%_flavour_*}";
	fi;
	if ex_pkg_state_test "${_pkg_name}" finish; then
		if [ -z "${_restart}" ]\
		&& [ "${_tgt_name}" != "INVARIANTS" ]; then
			return 0;
		fi;
	fi;
	(set -o errexit -o noglob;
	ex_pkg_vars; ex_pkg_env;
	ex_build_fileop mkdir "${PKG_BASE_DIR}";
	ex_build_fileop cd "${PKG_BASE_DIR}";
	set -- $(ex_lfilter -not "${BUILD_STEPS}"	\
			"$(ex_get_var_unsafe PKG_$(ex_toupper "${_pkg_name}")_BUILD_STEPS_DISABLE)");
	while [ ${#} -gt 0 ]; do
		_pkg_step_cmds=""; _pkg_step_cmd_args="";
		case "${1#*:}" in
		dynamic)
			if [ "${_tgt_name}" = "INVARIANTS" ]; then
				_pkg_step_cmds="pkg_${_pkg_name}_${1%:*} pkg_${1%:*}";
			elif [ -n "${_restart}" ]; then
				if [ -z "${_restart_at}" ]\
				|| ex_lmatch "${_restart_at}" , "${1%:*}"; then
					_pkg_step_cmds="pkg_${_pkg_name}_${1%:*} pkg_${1%:*}";
				fi;
			elif ! ex_pkg_state_test "${_pkg_name}" "${1%:*}"; then
				_pkg_step_cmds="pkg_${_pkg_name}_${1%:*} pkg_${1%:*}";
			fi; ;;
		invariant)
			_pkg_step_cmds="pkg_${1%:*}"; ;;
		variant)
			if ex_lmatch "${_restart_at}" "," "${1%:*}"; then
				_pkg_step_cmds="pkg_${_pkg_name}_${1%:*} pkg_${1%:*}";
			fi; ;;
		virtual)
			_pkg_step_cmds="pkg_${_pkg_name}_${1%:*}";
			_pkg_step_cmd_args="${_restart_at:-ALL}"; ;;
		all)
			if ex_test_cmd "pkg_${_pkg_name}_${1%:*}"; then
				"pkg_${_pkg_name}_${1%:*}" "${_restart_at:-ALL}";
				break;
			fi; ;;
		finish)	ex_pkg_state_push "${_pkg_name}" finish; ;;
		*)	;;
		esac;
		for __ in ${_pkg_step_cmds}; do
			if ex_test_cmd "${__}"; then
				ex_test_cmd "pkg_${_pkg_name}_${1%:*}_pre"	\
					&& "pkg_${_pkg_name}_${1%:*}_pre"
				"${__}" ${_pkg_step_cmd_args};
				ex_test_cmd "pkg_${_pkg_name}_${1%:*}_post"	\
					&& "pkg_${_pkg_name}_${1%:*}_post"
				if [ "${1#*:}" != "invariant" ]\
				&& [ ${#} -ge 2 ]; then
					ex_pkg_state_push "${_pkg_name}" "${1%:*}" "-${2#*:}";
				else
					ex_pkg_state_push "${_pkg_name}" "${1%:*}";
				fi; break;
			fi;
		done;
	shift; done); return ${?};
};

# vim:filetype=sh