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