forked from Piraty/xxtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xxbuild
executable file
·192 lines (171 loc) · 4.37 KB
/
xxbuild
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
#!/bin/sh
# xxbuild [flags] PKG.. - build packages for a pre-defined set of archs
# set NO_COLUMN and/or NO_COLOR for easier-to-parse output
: "${XXBUILD_ARCHS:="x86_64 x86_64-musl i686 aarch64-musl aarch64 armv7l-musl armv7l armv6l-musl armv6l"}"
: "${XBPS_HOSTDIR:="$HOME/.cache/xxtools/hostdir"}"
: "${XBPS_MASTERDIR:="$(xdistdir)/masterdir.xxtools"}"
if [ -z "$NO_COLUMN" ] && command -v column >/dev/null; then
COLUMN="column -ts:"
else
COLUMN="cat"
fi
cd "$(xdistdir)" || exit 1
text_bold() {
[ -z "$NO_COLOR" ] && printf '\033[1m%s\033[m' "$@" || printf '%s' "$@"
}
text_red() {
[ -z "$NO_COLOR" ] && printf '\033[31m%s\033[m' "$@" || printf '%s' "$@"
}
text_green() {
[ -z "$NO_COLOR" ] && printf '\033[32m%s\033[m' "$@" || printf '%s' "$@"
}
text_yellow() {
[ -z "$NO_COLOR" ] && printf '\033[33m%s\033[m' "$@" || printf '%s' "$@"
}
target_arch_can_run_natively() {
#TODO: ppc
target_arch="$1"
host_arch="$(uname -m)"
case "$host_arch" in
x86_64)
case "$target_arch" in
i686*) return 0 ;;
x86_64*) return 0 ;;
esac
;;
aarch64)
case "$target_arch" in
armv7*) return 0 ;;
aarch64*) return 0 ;;
esac
;;
esac
return 1
}
_xbps_src() {
(
set -x
#shellcheck disable=SC2086
./xbps-src $xbps_src_flags "$@"
)
}
summary="$(printf '\n%s\n' "$(text_bold SUMMARY)")"
if [ "$COLUMN" != "cat" ]; then
summary="$(printf '%s\n' "$summary" "$(text_bold pkg:host:target:cross:result)")"
fi
append_summary() {
pkg="$1"
host_arch="$2"
target_arch="$3"
cross="$4"
result="$5"
if [ "$COLUMN" != "cat" ]; then
summary="$(printf '%s\n' "$summary" "${pkg}:${host_arch}:${target_arch}:${cross}:${result}")"
else
summary="$(printf '%s\n' "$summary" "pkg:${pkg} host:${host_arch} target:${target_arch} cross:${cross} result:${result}")"
fi
}
xbps_src_flags=
xxbuild_force=
xxbuild_keep_going=
for arg; do
case "$arg" in
-f) # clean binpkgs before build
xxbuild_force=y
;;
-k) # make build failure non-fatal
xxbuild_keep_going=y
shift
continue
;;
-*) : ;;
*) break ;;
esac
xbps_src_flags="$xbps_src_flags $arg"
shift
done
if [ "$#" = "0" ]; then
# if no packages are given, build changed templates commited on this branch
rm -f /tmp/templates
common/travis/changed_templates.sh &&
set -- $(cat /tmp/templates)
fi
# ensure all templates exist
fail=
pkgs=
for pkg; do
if [ -f "srcpkgs/$pkg/template" ]; then
t="srcpkgs/$pkg/template"
elif [ -f "$pkg/template" ]; then
t="$pkg/template"
elif [ -f "$pkg" ]; then
t="$pkg"
else
printf 'FAIL: no template found for: %s\n' "$pkg" >&2
fail=y
continue
fi
pkgs="$pkgs $(printf '%s' "$t" | cut -d'/' -f2)"
done
[ -z "$fail" ] || exit 1
[ -n "$pkgs" ] || exit 1
#shellcheck disable=SC2086
printf 'Building: %s\n' $pkgs
mkdir -p "$XBPS_HOSTDIR" "$XBPS_MASTERDIR"
export XBPS_HOSTDIR
export XBPS_MASTERDIR
# clean binpkgs, to not spoil the result by reusing prebuilt packages
if [ -n "$xxbuild_force" ]; then
rm -rf "$XBPS_HOSTDIR/binpkgs"
fi
bailout=
for target_arch in $XXBUILD_ARCHS; do
if target_arch_can_run_natively "$target_arch"; then
cross=n
master_arch="$target_arch"
xbps_src_cross_flags=
else
cross=y
master_arch="$(uname -m)"
# host libc should match target's. some packages fail to crossbuild
# cross-libc
case "$target_arch" in
*-musl) master_arch="${master_arch}-musl" ;;
*) : ;;
esac
xbps_src_cross_flags="-a $target_arch"
fi
# masterdir is not fully populated
if [ ! -s "$XBPS_MASTERDIR/.xbps_chroot_init" ]; then
rm -rf "$XBPS_MASTERDIR"
# ensure native build if possible
elif [ "$(cat "$XBPS_MASTERDIR/.xbps_chroot_init" 2>/dev/null)" != "$master_arch" ]; then
rm -rf "$XBPS_MASTERDIR"
fi
_xbps_src zap
_xbps_src -A "$master_arch" binary-bootstrap
# mimic xbulk, but check exit code to not fail on broken/nocross
# `xbulk $xbps_src_flags -f $xbps_src_cross_flags $(./xbps-src sort-dependencies $@)`
for pkg in $(./xbps-src sort-dependencies "$pkgs"); do
_xbps_src "$xbps_src_cross_flags" pkg "$pkg"
ret=$?
result=
case "$ret" in
0)
result="$(text_green OK)"
;;
2) # nocross, broken or no match in `archs=`
result="$(text_yellow SKIPPED)"
;;
*)
result="$(text_red FAILED)"
[ -n "$xxbuild_keep_going" ] || bailout=y
;;
esac
append_summary "$pkg" "$master_arch" "$target_arch" "$cross" "$result"
[ -z "$bailout" ] || break
done
[ -z "$bailout" ] || break
done
echo "$summary" | $COLUMN
exit $ret