summaryrefslogtreecommitdiffstats
path: root/scripts/lib/ptxd_make_progress.sh
blob: 9b36902aa1f533d1ed73ad050c1dbb6121c70aa1 (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
#!/bin/bash
#
# Copyright (C) 2018 by Michael Olbrich <m.olbrich@pengutronix.de>
#
# For further information about the PTXdist project and license conditions
# see the README file.
#

ptxd_make_setup_progress() {
    if [ -n "${PTXDIST_PROGRESS}" -a -n "${PTXDIST_QUIET}" ]; then
	ptxd_make_target_count=$( \
	    MAKE=false "${PTXCONF_SETUP_HOST_MAKE}" --dry-run \
	    -f "${RULESDIR}/other/Toplevel.make" "${@}" | \
		grep -E 'ptxd_make_print_progress stop /.*(\.(get|extract|prepare|compile|install|targetinstall|report)|/images/).*finished:' | \
		wc -l ; exit ${PIPESTATUS[0]})
	if [ $? -ne 0 ]; then
	    echo "Failed to initialize progress data!" >&2
	    exit 1
	fi
	export ptxd_make_target_count
	exec {ptxd_make_target_count_start}>> "${PTXDIST_TEMPDIR}/ptxd_make_target_count_start"
	exec {ptxd_make_target_count_stop}>> "${PTXDIST_TEMPDIR}/ptxd_make_target_count_stop"
	export ptxd_make_target_count_start ptxd_make_target_count_stop
	:> "${PTXDIST_TEMPDIR}/ptxd_make_target_count"
    fi
}

ptxd_make_print_progress() {
    if [ -n "${ptxd_make_target_count}" ]; then
	local start stop len
	if [[ "${2}" =~ .*(\.(get|extract|prepare|compile|install|targetinstall|report)|/images/).* ]]; then
	    local ptr="ptxd_make_target_count_${1}"
	    echo -n + >&${!ptr}
	    if [ "${2}" = "world.targetinstall" ]; then
		# world.targetinstall has no 'targetinfo'
		echo -n + >&${ptxd_make_target_count_start}
	    fi
	fi
	start=$(wc -c < "${PTXDIST_TEMPDIR}/ptxd_make_target_count_start")
	stop=$(wc -c < "${PTXDIST_TEMPDIR}/ptxd_make_target_count_stop")
	len="$(wc -c <<<${ptxd_make_target_count})"
	printf "[%$[len-1]d/%d] " "${stop}" "${ptxd_make_target_count}"
    fi
}
export -f ptxd_make_print_progress