Commit | Line | Data |
b58ecb01 |
1 | #!/bin/bash |
2 | |
3 | set -e |
4 | |
b9970637 |
5 | TEST_STDERR_LOG=/tmp/dbictest.stderr |
851b6c2d |
6 | TIMEOUT_CMD="/usr/bin/timeout --kill-after=9.5m --signal=TERM 9m" |
b9970637 |
7 | |
b58ecb01 |
8 | echo_err() { echo "$@" 1>&2 ; } |
9 | |
10 | if [[ "$TRAVIS" != "true" ]] ; then |
11 | echo_err "Running this script makes no sense outside of travis-ci" |
12 | exit 1 |
13 | fi |
14 | |
15 | tstamp() { echo -n "[$(date '+%H:%M:%S')]" ; } |
16 | |
17 | run_or_err() { |
18 | echo_err -n "$(tstamp) $1 ... " |
19 | |
e032e3f4 |
20 | LASTCMD="$2" |
b58ecb01 |
21 | LASTEXIT=0 |
22 | START_TIME=$SECONDS |
db57071f |
23 | |
24 | PRMETER_PIDFILE="$(tempfile)_$SECONDS" |
25 | # the double bash is to hide the job control messages |
26 | bash -c "bash -c 'echo \$\$ >> $PRMETER_PIDFILE; while true; do sleep 10; echo -n \"\${SECONDS}s ... \"; done' &" |
27 | |
e032e3f4 |
28 | LASTOUT=$( eval "$2" 2>&1 ) || LASTEXIT=$? |
db57071f |
29 | |
30 | # stop progress meter |
31 | for p in $(cat "$PRMETER_PIDFILE"); do kill $p ; done |
32 | |
b58ecb01 |
33 | DELTA_TIME=$(( $SECONDS - $START_TIME )) |
34 | |
35 | if [[ "$LASTEXIT" != "0" ]] ; then |
e032e3f4 |
36 | if [[ -z "$3" ]] ; then |
37 | echo_err "FAILED !!! (after ${DELTA_TIME}s)" |
38 | echo_err "Command executed:" |
39 | echo_err "$LASTCMD" |
40 | echo_err "STDOUT+STDERR:" |
41 | echo_err "$LASTOUT" |
42 | fi |
4242985f |
43 | |
b58ecb01 |
44 | return $LASTEXIT |
45 | else |
46 | echo_err "done (took ${DELTA_TIME}s)" |
47 | fi |
48 | } |
49 | |
003e97c5 |
50 | apt_install() { |
51 | # flatten |
52 | pkgs="$@" |
53 | |
54 | # Need to do this at every step, the sources list may very well have changed |
55 | run_or_err "Updating APT available package list" "sudo apt-get update" |
56 | |
57 | run_or_err "Installing Debian APT packages: $pkgs" "sudo apt-get install --allow-unauthenticated --no-install-recommends -y $pkgs" |
58 | } |
59 | |
b58ecb01 |
60 | extract_prereqs() { |
71dd2ecc |
61 | # once --verbose is set, --no-verbose can't disable it |
62 | # do this by hand |
b2435630 |
63 | local PERL_CPANM_OPT="$( echo $PERL_CPANM_OPT | sed 's/--verbose\s*//' )" |
71dd2ecc |
64 | |
b58ecb01 |
65 | # hack-hack-hack |
66 | LASTEXIT=0 |
67 | COMBINED_OUT="$( { stdout="$(cpanm --quiet --scandeps --format tree "$@")" ; } 2>&1; echo "!!!STDERRSTDOUTSEPARATOR!!!$stdout")" \ |
68 | || LASTEXIT=$? |
69 | |
70 | OUT=${COMBINED_OUT#*!!!STDERRSTDOUTSEPARATOR!!!} |
777447e9 |
71 | ERR=${COMBINED_OUT%!!!STDERRSTDOUTSEPARATOR!!!*} |
b58ecb01 |
72 | |
50e644e5 |
73 | if [[ "$LASTEXIT" != "0" ]] ; then |
4242985f |
74 | echo_err "Error occured (exit code $LASTEXIT) retrieving dependencies of $@:" |
75 | echo_err "$ERR" |
76 | echo_err "$OUT" |
b58ecb01 |
77 | exit 1 |
78 | fi |
79 | |
777447e9 |
80 | # throw away warnings, up-to-date diag, ascii art, convert to modnames |
81 | PQ=$(perl -p -e ' |
82 | s/^.*?is up to date.*$//; |
83 | s/^\!.*//; |
84 | s/^[^a-z]+//i; |
85 | s/\-[^\-]+$/ /; # strip version part |
86 | s/\-/::/g |
87 | ' <<< "$OUT") |
f207111d |
88 | |
89 | # throw away what was in $@ |
90 | for m in "$@" ; do |
91 | PQ=$( perl -p -e 's/(?:\s|^)\Q'"$m"'\E(?:\s|$)/ /mg' <<< "$PQ") |
92 | done |
93 | |
94 | # RV |
95 | echo "$PQ" |
b58ecb01 |
96 | } |
97 | |
98 | parallel_installdeps_notest() { |
99 | if [[ -z "$@" ]] ; then return; fi |
100 | |
4242985f |
101 | # one module spec per line |
102 | MODLIST="$(printf '%s\n' "$@")" |
b58ecb01 |
103 | |
23905f5f |
104 | # We want to trap the output of each process and serially append them to |
105 | # each other as opposed to just dumping a jumbled up mass-log that would |
106 | # need careful unpicking by a human |
107 | # |
108 | # While cpanm does maintain individual buildlogs in more recent versions, |
109 | # we are not terribly interested in trying to figure out which log is which |
110 | # dist. The verbose-output + trap STDIO technique is vastly superior in this |
111 | # particular case |
10e248bf |
112 | # |
113 | # Explanation of inline args: |
114 | # |
115 | # [09:38] <T> you need a $0 |
116 | # [09:38] <G> hence the _ |
117 | # [09:38] <G> bash -c '...' _ |
118 | # [09:39] <T> I like -- because it's the magic that gnu getopts uses for somethign else |
119 | # [09:39] <G> or --, yes |
120 | # [09:39] <T> ribasushi: you could put "giant space monkey penises" instead of "--" and it would work just as well |
121 | # |
4242985f |
122 | run_or_err "Installing (without testing) $(echo $MODLIST)" \ |
123 | "echo \\ |
124 | \"$MODLIST\" \\ |
125 | | xargs -d '\\n' -n 1 -P $NUMTHREADS bash -c \\ |
e6b373aa |
126 | 'OUT=\$($TIMEOUT_CMD cpanm --notest \"\$@\" 2>&1 ) || (LASTEXIT=\$?; echo \"\$OUT\"; exit \$LASTEXIT)' \\ |
4242985f |
127 | 'giant space monkey penises' |
10e248bf |
128 | " |
b58ecb01 |
129 | } |
130 | |
579472df |
131 | installdeps() { |
132 | if [[ -z "$@" ]] ; then return; fi |
133 | |
e032e3f4 |
134 | MODLIST=$(printf "%q " "$@" | perl -pe 's/^\s+|\s+$//g') |
579472df |
135 | |
136 | local -x HARNESS_OPTIONS |
137 | |
138 | HARNESS_OPTIONS="j$NUMTHREADS" |
139 | |
e032e3f4 |
140 | if ! run_or_err "Attempting install of $# modules under parallel ($HARNESS_OPTIONS) testing ($MODLIST)" "_dep_inst_with_test $MODLIST" quiet_fail ; then |
141 | local errlog="failed after ${DELTA_TIME}s Exit:$LASTEXIT Log:$(/usr/bin/nopaste -q -s Shadowcat -d "Parallel testfail" <<< "$LASTOUT")" |
142 | echo "$errlog" |
579472df |
143 | |
a9fc70ee |
144 | POSTMORTEM="$POSTMORTEM$( |
145 | echo |
e032e3f4 |
146 | echo "Depinstall of $MODLIST under $HARNESS_OPTIONS parallel testing $errlog" |
a9fc70ee |
147 | )" |
579472df |
148 | |
149 | HARNESS_OPTIONS="" |
e032e3f4 |
150 | run_or_err "Retrying same $# modules without parallel testing" "_dep_inst_with_test $MODLIST" |
579472df |
151 | fi |
152 | |
153 | INSTALLDEPS_OUT="${INSTALLDEPS_OUT}${LASTOUT}" |
154 | } |
155 | |
e6b373aa |
156 | _dep_inst_with_test() { |
157 | if [[ "$DEVREL_DEPS" == "true" ]] ; then |
158 | # --dev is already part of CPANM_OPT |
e032e3f4 |
159 | LASTCMD="$TIMEOUT_CMD cpanm $@" |
160 | $LASTCMD 2>&1 |
e6b373aa |
161 | else |
e032e3f4 |
162 | LASTCMD="$TIMEOUT_CMD cpan $@" |
163 | $LASTCMD 2>&1 |
579472df |
164 | |
e6b373aa |
165 | # older perls do not have a CPAN which can exit with error on failed install |
166 | for m in "$@"; do |
167 | if ! perl -e ' |
579472df |
168 | |
647da28e |
169 | my $mod = ( |
579472df |
170 | $ARGV[0] =~ m{ \/ .*? ([^\/]+) $ }x |
171 | ? do { my @p = split (/\-/, $1); pop @p; join "::", @p } |
172 | : $ARGV[0] |
647da28e |
173 | ); |
174 | |
175 | $mod = q{List::Util} if $mod eq q{Scalar::List::Utils}; |
176 | |
177 | eval qq{require($mod)} or ( print $@ and exit 1) |
579472df |
178 | |
e6b373aa |
179 | ' "$m" 2> /dev/null ; then |
180 | echo -e "$m installation seems to have failed" |
181 | return 1 |
182 | fi |
183 | done |
184 | fi |
579472df |
185 | } |
186 | |
b58ecb01 |
187 | CPAN_is_sane() { perl -MCPAN\ 1.94_56 -e 1 &>/dev/null ; } |
f207111d |
188 | |
189 | CPAN_supports_BUILDPL() { perl -MCPAN\ 1.9205 -e1 &>/dev/null; } |