-
Notifications
You must be signed in to change notification settings - Fork 5
/
norm-testall
executable file
·183 lines (153 loc) · 5.84 KB
/
norm-testall
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
#!/usr/bin/env bash
set -eE
set -o pipefail
OURDIR="${BASH_SOURCE%/*}"
NORMDIR="$OURDIR"
. "$NORMDIR"/norm_common
EXTRAFLAGS=()
while [ $# -gt 0 ]; do
case "$1" in
--with-*) echo "got with ${1#--without-}"; EXTRAFLAGS+=("$1") ;;
--without-*) echo "got without ${1#--without-}"; EXTRAFLAGS+=("$1") ;;
(--) shift; break;;
(-*) echo "$0: error -- unregoznied option $1" 1>&2; exit 64;;
(*) break;;
esac
shift
done
[[ -n "$CI" ]] && EXTRAFLAGS+=("-q")
##
## set up variables
NORMTEST_PREFIX="$HOME/norm.test.$MACHINEID"
NORMTEST_PREFIXNAME=`basename "$NORMTEST_PREFIX"`
LOGPATH="$NORMDIR/testlogs/$MACHINEID"
## create output directories
mkdir -p "$NORMDIR/testlogs"
mkdir -p "$LOGPATH"
# Usage: JAILPATH=$(jailpath tools)
jailpath() {
[[ -z $1 ]] && log "SHOULD NOT HAPPEN: invalid usage of jailname()!" && exit 1
JAILNAME="$1"
JAILPATH="norm.jail.$JAILNAME.$MACHINEID"
echo $JAILPATH
}
do_strip() {
strip -gp "$@" || true
}
# Usage: prepare_jail tools xz ccache curl bzip2
prepare_jail() {
[[ -z $2 ]] && log "SHOULD NOT HAPPEN: invalid usage of prepare_jail()!" && exit 1
JAILNAME="$1"
JAILPATH=$(jailpath "$JAILNAME")
JAILFULLPATH="$HOME/$JAILPATH"
JAILLOG="$NORMDIR/testlogs/$JAILPATH.log"
JAILARCHIVE="$NORMDIR/testlogs/$JAILPATH.tar.gz"
shift
rm -rf "$JAILFULLPATH"
## if have archive, extract and done
if [[ -e $JAILARCHIVE ]]; then
tar xf "$JAILARCHIVE" -C "$HOME"
return 0
fi
## clear the bootstrap log
> "$JAILLOG"
FORMULAS=("$@")
echo Will build in $JAILPATH:
printf " * %s\n" "${FORMULAS[@]}"
for i in "${FORMULAS[@]}"; do
"$NORMDIR"/norm -p "$JAILFULLPATH" install ${EXTRAFLAGS[@]} "$i" 2>&1 | tee -a "$JAILLOG"
hash -r
done
norm -p "$JAILFULLPATH" list 2>&1 | tee -a "$JAILLOG"
set +eE
rm -vf "$JAILFULLPATH"/bin/{bunzip2,bzip2recover}
rm -vf "$JAILFULLPATH"/bin/bz{cat,cmp,diff,egrep,fgrep,grep,less,more}
rm -vf "$JAILFULLPATH"/bin/lz{cat,cmp,diff,egrep,fgrep,grep,less,more}
rm -vf "$JAILFULLPATH"/bin/xz{cat,cmp,diff,egrep,fgrep,grep,less,more}
rm -vf "$JAILFULLPATH"/bin/{lzma,lzmadec,lzmainfo,unlzma,unxz,xzdec}
rm -vf "$JAILFULLPATH"/bin/*-config
rm -vf "$JAILFULLPATH"/bin/{c_rehash,openssl,openssl.dynamic}
rm -vf "$JAILFULLPATH"/bin/{corelist,cpan,enc2xs,encguess,h2ph,h2xs,instmodsh,json_pp}
rm -vf "$JAILFULLPATH"/bin/{libnetcfg,piconv,pl2pm,pod2html,pod2text,pod2usage,podchecker,podselect,prove,ptar*}
rm -vf "$JAILFULLPATH"/bin/{shasum,splain,xsubpp,zipdetails}
rm -vf "$JAILFULLPATH"/bin/perl?*
rm -vf "$JAILFULLPATH"/bin/db_*
rm -vf "$JAILFULLPATH"/bin/gdbm*
rm -rf "$JAILFULLPATH"/include
rm -rf "$JAILFULLPATH"/lib/libbz2.*
rm -rf "$JAILFULLPATH"/lib/*.{a,la,so}
rm -rf "$JAILFULLPATH"/lib/lib{crypto,curl,db,db-6,db_cxx,db_cxx-6,db_stl,db_stl-6,gdbm,gdbm_compat,lzma,ssl,z}.so
rm -rf "$JAILFULLPATH"/lib/libdb.so.2
rm -rf "$JAILFULLPATH"/lib/pkgconfig
rm -rf "$JAILFULLPATH"/man
rm -rf "$JAILFULLPATH"/share
rm -rf "$JAILFULLPATH"/tmp
rm -rf "$JAILFULLPATH"/var
chmod u+w "$JAILFULLPATH"/lib/*
chmod u+w "$JAILFULLPATH"/lib/engines/*
do_strip "$JAILFULLPATH"/{bin,lib,lib/engines}/*
"$NORMDIR/norm-ldd" -q "$JAILFULLPATH" 2>&1 | tee -a "$JAILLOG"
set -eE
tar zcf "$JAILARCHIVE" -C "$HOME" "$JAILPATH"
}
## we don't want pipefail anymore -- failures to compile are handles by ourselves from now on
set +o pipefail
## check if were given list of packages, if not, try all of them
LIST=("$@")
[ -z "$LIST" ] && LIST=("$NORMDIR"/packages/*)
trim() {
local var="$*"
echo -n "$var"
}
##
## compile each package and save logs
for FORMULA_NAME in "${LIST[@]}"; do
# calculate formula name and file path
FORMULA_NAME=${FORMULA_NAME#$NORMDIR/packages/} ## get rid of paths if any
FORMULA_FILE="$NORMDIR/packages/$FORMULA_NAME" ## we want full path here
[ -f "$FORMULA_FILE" ] || continue ## must be a file
calc_formula_id "$FORMULA_FILE"
# check if we've done this formula before
[ -f "$LOGPATH/$FORMULA_ID.log.gz" ] && continue ## successful logfile exists, skip the formula
# clean up output prefix
rm -rf "$NORMTEST_PREFIX"
# clean up output logfiles
rm -f "$LOGPATH/$FORMULA_NAME".*
unset FAILURE
# do it
"$NORMDIR/norm" -p "$NORMTEST_PREFIX" install ${EXTRAFLAGS[@]} "$FORMULA_NAME" 2>&1 | tee "$LOGPATH/$FORMULA_ID.log"
BUILDSTATUS="${PIPESTATUS[0]}"
[ $BUILDSTATUS != 0 ] && FAILURE=1
log "testall finished for $FORMULA_NAME" | tee -a "$LOGPATH/$FORMULA_ID.log"
# compile success, check if ldd has any output
"$NORMDIR/norm-ldd" -q "$NORMTEST_PREFIX" | tee -a "$LOGPATH/$FORMULA_ID.log"
[ "${PIPESTATUS[0]}" != "0" ] && FAILURE=1
# write list of files in prefix (excluding /tmp)
# (cd "$NORMTEST_PREFIX" && find . -path ./tmp -prune -or -ls 2>&1 | tee -a "$LOGPATH/$FORMULA_ID.log")
# write list of packages that had been built
"$NORMDIR/norm" -p "$NORMTEST_PREFIX" list 2>&1 | tee -a "$LOGPATH/$FORMULA_ID.log"
# write list of packages that had been built
"$NORMDIR/norm" -p "$NORMTEST_PREFIX" dot 2>&1 | tee -a "$LOGPATH/$FORMULA_ID.log"
if [ -z "$FAILURE" ]; then
gzip "$LOGPATH/$FORMULA_ID.log"
fi
done
##
## list package names that didn't build cleanly
ERRORS=()
for FORMULA_NAME in "${LIST[@]}"; do
# calculate formula name and file path
FORMULA_NAME=${FORMULA_NAME#$NORMDIR/packages/} ## get rid of paths if any
ERRORS+=("$LOGPATH/$FORMULA".*.log)
done
if [ -n "$ERRORS" ] && [ -e "$ERRORS" ]; then
echo These packages have failed to build:
for file in "${ERRORS[@]}"; do
[ -e "$file" ] || continue
# normalize the formula name out of the logpath
FORMULA=${file%.*.log}
FORMULA=${FORMULA#$LOGPATH/}
echo $FORMULA
done
exit 1
fi