blob: 4ad02fcc69aca63bd398360a2f7a4b031c44237f (
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
#!/bin/bash
#set -x
source /etc/libretools.conf
source $(dirname $0)/libremessages
source $XDG_CONFIG_HOME/libretools/libretools.conf >/dev/null 2>&1|| true
# End inmediately but print a useful message
trap_exit() {
error "($(basename $0)) $@"
exit 1
}
# Trap signals from makepkg
set -E
trap 'trap_exit "TERM signal caught. Exiting..."' TERM HUP QUIT
trap 'trap_exit "Aborted by user! Exiting..."' INT
trap 'trap_exit "An unknown error has occurred. Exiting..."' ERR
# return : full version spec, including epoch (if necessary), pkgver, pkgrel
# usage : get_fullver( ${epoch:-0}, $pkgver, $pkgrel )
get_fullver() {
if [ $1 -eq 0 ]; then
# zero epoch case, don't include it in version
echo $2-$3
else
echo $1:$2-$3
fi
}
# Add line to build order cache in CSV format
# $1 status
# $2 pkgname
add_order() {
echo "${1};${DEPTH};${2:-${pkgbase}};${fullver};${PWD}" >> "${BUILDORDER}"
${VERBOSE} && msg2 "%${DEPTH}s${2:-${pkgbase}} [${1}]" || true
}
# Finds a PKGBUILD on toru's path cache
# Look in all caches but pick the first one
# TODO move to a toru flag (-p?)
where_is() {
grep -m1 "^${1}:" "${TORUPATH}/paths" 2>/dev/null| \
cut -d: -f2 2>/dev/null
}
if [ ! -f PKGBUILD ]; then
error "Missing PKGBUILD"
exit 1
fi
if ! source PKGBUILD ; then
error "Can't source PKGBUILD"
exit 1
fi
# Save resources
unset pkgdesc arch license groups backup install md5sums sha1sums \
sha256sums source options >/dev/null 2>&1
unset build package >/dev/null 2>&1
for _pkg in ${pkgname[@]}; do
unset package_${_pkg} >/dev/null 2>&1 || true
done
##
# Get useful values
pkgbase="${pkgbase:-${pkgname[0]}}"
fullver=$(get_fullver ${epoch:-0} ${pkgver} ${pkgrel})
# Get or set the build order cache (canonical)
BUILDORDER="$(readlink -f "${1:-$(mktemp /tmp/${pkgbase}.buildorder.XXXX)}")"
DEPTH=${2:-0}
NEXTDEPTH=$((${DEPTH} + 1))
VERBOSE=true
# ensure it exists
touch "${BUILDORDER}"
# If this package is already built quit silently
if is_built "${pkgbase}>=${fullver}"; then
add_order "ignore"
exit 0
fi
# Ignore if already in build order
egrep -q ";${pkgbase};" "${BUILDORDER}" && exit 0
# Add pkgbase to build order
add_order "build"
# Cleanup dep versioning
deps=($(echo "${depends[@]} ${makedepends[@]}" | \
sed "s/[=<>]\+[^ ]\+//g" | \
tr ' ' "\n" | \
sort -u))
# NOTE: getting depends from package() is a PITA
for _dep in ${deps[@]}; do
# Ignore if already in build order
egrep -q ";${_dep};" "${BUILDORDER}" && continue
depdir="$(where_is ${_dep})"
if [ -z "${depdir}" -o ! -d "${depdir}" ]; then
# We specify the pkgname because we can't source the dep PKGBUILD
add_order "missing" "${_dep}"
continue
fi
pushd "${depdir}" >/dev/null
# Run itself over dependencies
$0 "${BUILDORDER}" ${NEXTDEPTH}
done
# Only print build order at the end
if [ ${DEPTH} -eq 0 ]; then
${VERBOSE} && msg "Build tree stored in ${BUILDORDER}" || true
${VERBOSE} || echo "${BUILDORDER}" || true
fi
exit $?
|