-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtbuilder
executable file
·268 lines (233 loc) · 6.37 KB
/
tbuilder
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#!/bin/sh
readonly XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
readonly CONFIGDIR="$XDG_CONFIG_HOME/tbuilder"
readonly POUDRIERE_DIR=${POUDRIERE_DIR:-/usr/local/poudriere}
readonly POUDRIERE_PORTS=${POUDRIERE_PORTS:-${POUDRIERE_DIR}/ports/default}
readonly command=$1
query=$2
readonly build=${3:-none}
interrupted=0 # build interrupted by ctrl+c
check_portname() {
local flavor flavors port
if [ "$1" = "." ]; then
if [ ! "$(make -V PORTNAME)" ]; then
printf "===> %s: not a portdir\n\n" "$PWD" >&2
display_usage
fi
port=$(echo "$PWD" | awk '{
n = split($0, p ,"/");
print p[n-1] "/" p[n];
}')
else
port=$1
fi
if [ ! -d "$POUDRIERE_PORTS/${port%%@*}" ]; then
printf "===> %s: port directory does not exists\n\n" \
"$POUDRIERE_PORTS/$port" >&2
display_usage
fi
if [ "${port##*@}" != "${port%%@*}" ]; then
flavors=$(make -C "$POUDRIERE_PORTS/${port%%@*}" -V FLAVORS)
if [ "${port##*@}" = "all" ]; then
for flavor in $flavors; do
echo "${port%%@*}@$flavor"
done
return
fi
fi
echo $port
}
display_usage() {
<< EOF >&2 cat
Usage: ${0##*/} <command> <query> [name] [poudriere testport args]
command: bdeps - build ports having certain build dependency
file - build ports read from file
grep - build ports containing phrase in Makefile
ldeps - build ports linking with certain library
match - build ports with name matching certain phrase
name - build specific port
slaves - build slaves of certain port
query: (bdeps|match) - portname
(file) - name of file to read category/port entries from
(grep) - grep pattern
(ldeps|name|slaves) - category/port or '.' for port from current directory
name: poudriere jail name or profile filename
EOF
exit 1
}
is_build_dep() {
local dep hname oname test_str=$(opt_test_string $2)
make -V BUILD_DEPENDS -V LIB_DEPENDS $test_str | grep -q $1 && return 0
[ "$2" ] || return 1
hname=$(grep $1 Makefile | cut -f1 -d=)
oname=$(echo $2 | sed -E 's,(\+|\-),,')
for dep in BUILD LIB; do
[ "$oname" = "${hname%_${dep}_DEPENDS}" ] && return 0
done
return 1
}
is_other_dep() {
local dep hname oname test_str=$(opt_test_string $2)
make -V FETCH_DEPENDS -V EXTRACT_DEPENDS -V PATCH_DEPENDS \
-V RUN_DEPENDS -V TEST_DEPENDS $test_str | grep -q $1 &&
return 0
[ "$2" ] || return 1
hname=$(grep $1 Makefile | cut -f1 -d=)
oname=$(echo $2 | sed -E 's,(\+|\-),,')
for dep in FETCH EXTRACT PATCH RUN TEST; do
[ "$oname" = "${hname%_${dep}_DEPENDS}" ] && return 0
done
return 1
}
opt_test_string() {
case $1 in
-*)
echo "OPTIONS_DEFAULT=${1#-}" ;;
+*)
echo "OPTIONS_UNSET=${1#+}" ;;
esac
}
poudriere_jails() {
poudriere jail -lq | cut -d" " -f1
}
poudriere_test_build() {
local jname=$1 port=${2%%:*} option=${2#*:}
local port_cfg outcome="success"
if [ "$port" != "$option" ]; then
if [ "${option%:*}" != "OPT_UNKNOWN" ]; then
echo "*** port $port needs ${option%:*} set to ${option#*:} ***"
else
echo "*** port $port unknown option needed ***"
fi
port_cfg="-c"
fi
$SUDO poudriere testport -j $jname -o $port $poudriere_args $port_cfg
[ $? -eq 0 ] || outcome="failed"
[ $interrupted -eq 0 ] || outcome="interrupted"
BUILD_RESULTS="$BUILD_RESULTS $port:$jname:$outcome"
}
[ "$query" ] || display_usage
if [ "$build" != "none" ] && ! poudriere_jails | grep -q $build \
&& [ ! -f "$CONFIGDIR/$build" ]
then
printf "===> %s: no such poudriere jail or profile\n\n" "$build" >&2
display_usage
fi
if [ "$4" ]; then
shift 3;
poudriere_args="$*";
fi
if [ ! -d "$POUDRIERE_PORTS" ]; then
echo "===> Poudriere ports directory not found: $POUDRIERE_PORTS" >&2
echo "===> Try setting POUDRIERE_PORTS environment variable" >&2
exit 1
fi
if [ $(id -u) -ne 0 ]; then
if ! which sudo >/dev/null; then
echo "===> sudo not found" >&2
echo "===> This script requires root privileges or properly configured sudo." >&2
exit 1
fi
SUDO="sudo"
fi
trap 'interrupted=1' INT
case $command in
bdeps)
ports=$(pfind -b $query | cut -f1 -d' ') ;;
file)
if [ ! -f "$query" ]; then
echo "===> File $query does not exists" >&2
exit 1
fi
ports=$(grep -v '^#' "$query") ;;
grep)
ports=$(cd "$POUDRIERE_PORTS" && find . -name "Makefile*" -exec \
grep -q "$query" {} \; -print | grep -v "$query/Makefile" |
sed -E 's;(\./|/Makefile);;g') ;;
ldeps)
query=$(check_portname $query)
if [ "$query" ]; then
tmp=$(cd "$POUDRIERE_PORTS" &&
find . -name "Makefile*" -exec grep -q \
"^[^#].*$query[ \\]*\$" {} \; -print | sed 's|\./||')
fi
for path in $tmp; do
path=$(dirname "$path")
[ "$query" != "$path" ] || continue
cd "$POUDRIERE_PORTS/$path"
if is_build_dep $query; then
ports="$ports $path"
continue
fi
is_other_dep $query && continue
for option in $(make pretty-print-config); do
case $option in -*)
if is_build_dep $query $option; then
ports="$ports $path:${option#-}:on"
continue 2
fi
is_other_dep $query $option && continue 2
esac
done
for option in $(make pretty-print-config); do
case $option in +*)
if is_build_dep $query $option; then
ports="$ports $path:${option#+}:off"
continue 2
fi
esac
done
ports="$ports $path:OPT_UNKNOWN:none"
done
;;
match)
ports=$(pfind -n $query | cut -f1 -d' ') ;;
name)
ports=$(check_portname $query) ;;
slaves)
master=$(check_portname $query)
[ "$master" ] && ports=$(pfind -s $master | cut -f1 -d' ') ;;
*)
display_usage
esac
[ "$ports" ] || exit 1
for port in $ports; do
case $build in
none)
option=${port#*:}
if [ "$command" != "name" ]; then
case ${option%:*} in
"${port%%:*}")
echo "Found match: ${port%%:*}" ;;
"OPT_UNKNOWN")
echo "Found match: ${port%%:*}, unknown option needed" ;;
*)
echo "Found match: ${port%%:*}, needs ${option%:*}=${option#*:}" ;;
esac
else
printf "===> No target build jailname provided\n\n" >&2
display_usage
fi
;;
*)
if poudriere_jails | grep -q $build; then
queue=$build
else
queue=$(grep -v "^#" "$CONFIGDIR/$build")
fi
for b in $queue; do
poudriere_test_build $b $port
[ $interrupted -eq 0 ] || break 2
done
esac
done
if [ "$BUILD_RESULTS" ]; then
printf "\n===> Following build(s) were performed:\n"
printf "%-40s %-15s %s\n" "PORTNAME" "JAIL" "RESULT"
for result in $BUILD_RESULTS; do
params=${result#*:}
printf "%-40s %-15s %s\n" "${result%%:*}" \
"${params%:*}" "${params#*:}"
done
echo ""
fi