Remove 37b5ab51 test warnings on older perls
[dbsrgits/DBIx-Class.git] / maint / travis-ci_scripts / common.bash
CommitLineData
b58ecb01 1#!/bin/bash
2
3set -e
4
b9970637 5TEST_STDERR_LOG=/tmp/dbictest.stderr
6
b58ecb01 7echo_err() { echo "$@" 1>&2 ; }
8
9if [[ "$TRAVIS" != "true" ]] ; then
10 echo_err "Running this script makes no sense outside of travis-ci"
11 exit 1
12fi
13
14tstamp() { echo -n "[$(date '+%H:%M:%S')]" ; }
15
16run_or_err() {
17 echo_err -n "$(tstamp) $1 ... "
18
19 LASTEXIT=0
20 START_TIME=$SECONDS
003e97c5 21 # the tee is a handy debugging tool when stumpage is exceedingly strong
22 #LASTOUT=$( bash -c "$2" 2>&1 | tee /dev/stderr) || LASTEXIT=$?
b58ecb01 23 LASTOUT=$( bash -c "$2" 2>&1 ) || LASTEXIT=$?
24 DELTA_TIME=$(( $SECONDS - $START_TIME ))
25
26 if [[ "$LASTEXIT" != "0" ]] ; then
4242985f 27 echo_err "FAILED !!! (after ${DELTA_TIME}s)"
28 echo_err "Command executed:"
29 echo_err "$2"
30 echo_err "STDOUT+STDERR:"
31 echo_err "$LASTOUT"
32
b58ecb01 33 return $LASTEXIT
34 else
35 echo_err "done (took ${DELTA_TIME}s)"
36 fi
37}
38
003e97c5 39apt_install() {
40 # flatten
41 pkgs="$@"
42
43 # Need to do this at every step, the sources list may very well have changed
44 run_or_err "Updating APT available package list" "sudo apt-get update"
45
46 run_or_err "Installing Debian APT packages: $pkgs" "sudo apt-get install --allow-unauthenticated --no-install-recommends -y $pkgs"
47}
48
b58ecb01 49extract_prereqs() {
71dd2ecc 50 # once --verbose is set, --no-verbose can't disable it
51 # do this by hand
b2435630 52 local PERL_CPANM_OPT="$( echo $PERL_CPANM_OPT | sed 's/--verbose\s*//' )"
71dd2ecc 53
b58ecb01 54 # hack-hack-hack
55 LASTEXIT=0
56 COMBINED_OUT="$( { stdout="$(cpanm --quiet --scandeps --format tree "$@")" ; } 2>&1; echo "!!!STDERRSTDOUTSEPARATOR!!!$stdout")" \
57 || LASTEXIT=$?
58
59 OUT=${COMBINED_OUT#*!!!STDERRSTDOUTSEPARATOR!!!}
60 ERR=$(grep -v " is up to date." <<< "${COMBINED_OUT%!!!STDERRSTDOUTSEPARATOR!!!*}")
61
50e644e5 62 if [[ "$LASTEXIT" != "0" ]] ; then
4242985f 63 echo_err "Error occured (exit code $LASTEXIT) retrieving dependencies of $@:"
64 echo_err "$ERR"
65 echo_err "$OUT"
b58ecb01 66 exit 1
67 fi
68
8fe19930 69 # throw away warnings, ascii art, convert to modnames
70 PQ=$(perl -p -e 's/^\!.*//; s/^[^a-z]+//i; s/\-[^\-]+$/ /; s/\-/::/g' <<< "$OUT")
f207111d 71
72 # throw away what was in $@
73 for m in "$@" ; do
74 PQ=$( perl -p -e 's/(?:\s|^)\Q'"$m"'\E(?:\s|$)/ /mg' <<< "$PQ")
75 done
76
77 # RV
78 echo "$PQ"
b58ecb01 79}
80
81parallel_installdeps_notest() {
82 if [[ -z "$@" ]] ; then return; fi
83
4242985f 84 # one module spec per line
85 MODLIST="$(printf '%s\n' "$@")"
b58ecb01 86
87 # The reason we do things so "non-interactively" is that xargs -P will have the
88 # latest cpanm instance overwrite the buildlog. There seems to be no way to
89 # specify a custom buildlog, hence we just collect the verbose output
10e248bf 90 # and display it in case of "worker" failure
91 #
92 # Explanation of inline args:
93 #
94 # [09:38] <T> you need a $0
95 # [09:38] <G> hence the _
96 # [09:38] <G> bash -c '...' _
97 # [09:39] <T> I like -- because it's the magic that gnu getopts uses for somethign else
98 # [09:39] <G> or --, yes
99 # [09:39] <T> ribasushi: you could put "giant space monkey penises" instead of "--" and it would work just as well
100 #
4242985f 101 run_or_err "Installing (without testing) $(echo $MODLIST)" \
102 "echo \\
103\"$MODLIST\" \\
104 | xargs -d '\\n' -n 1 -P $NUMTHREADS bash -c \\
105 'OUT=\$(cpanm --notest --no-man-pages \"\$@\" 2>&1 ) || (LASTEXIT=\$?; echo \"\$OUT\"; exit \$LASTEXIT)' \\
106 'giant space monkey penises'
10e248bf 107 "
b58ecb01 108}
109
579472df 110installdeps() {
111 if [[ -z "$@" ]] ; then return; fi
112
113 echo_err "$(tstamp) Processing dependencies: $@"
114
115 local -x HARNESS_OPTIONS
116
117 HARNESS_OPTIONS="j$NUMTHREADS"
118
119 echo_err -n "Attempting install of $# modules under parallel ($HARNESS_OPTIONS) testing ... "
120
121 LASTEXIT=0
122 START_TIME=$SECONDS
123 LASTOUT=$( cpan_inst "$@" ) || LASTEXIT=$?
124 DELTA_TIME=$(( $SECONDS - $START_TIME ))
125
126 if [[ "$LASTEXIT" = "0" ]] ; then
127 echo_err "done (took ${DELTA_TIME}s)"
128 else
a9fc70ee 129 local errlog="after ${DELTA_TIME}s Exit:$LASTEXIT Log:$(/usr/bin/nopaste -q -s Shadowcat -d "Parallel installfail" <<< "$LASTOUT")"
130 echo_err -n "failed ($errlog) retrying with sequential testing ... "
131 POSTMORTEM="$POSTMORTEM$(
132 echo
77a86bbf 133 echo "Depinstall under $HARNESS_OPTIONS parallel testing failed $errlog"
134 echo "============================================================="
135 echo "Attempted installation of: $@"
136 echo "============================================================="
a9fc70ee 137 )"
579472df 138
139 HARNESS_OPTIONS=""
140 LASTEXIT=0
141 START_TIME=$SECONDS
142 LASTOUT=$( cpan_inst "$@" ) || LASTEXIT=$?
143 DELTA_TIME=$(( $SECONDS - $START_TIME ))
144
145 if [[ "$LASTEXIT" = "0" ]] ; then
146 echo_err "done (took ${DELTA_TIME}s)"
147 else
148 echo_err "FAILED !!! (after ${DELTA_TIME}s)"
149 echo_err "STDOUT+STDERR:"
150 echo_err "$LASTOUT"
151 exit 1
152 fi
153 fi
154
155 INSTALLDEPS_OUT="${INSTALLDEPS_OUT}${LASTOUT}"
156}
157
158cpan_inst() {
c86519d7 159 /usr/bin/timeout --kill-after=9.5m --signal=TERM 9m cpan "$@" 2>&1
579472df 160
161 # older perls do not have a CPAN which can exit with error on failed install
162 for m in "$@"; do
163 if ! perl -e '
164
165eval ( q{require } . (
166 $ARGV[0] =~ m{ \/ .*? ([^\/]+) $ }x
167 ? do { my @p = split (/\-/, $1); pop @p; join "::", @p }
168 : $ARGV[0]
169) ) or ( print $@ and exit 1)' "$m" 2> /dev/null ; then
170
171 echo -e "$m installation seems to have failed"
172 return 1
173 fi
174 done
175}
176
b58ecb01 177CPAN_is_sane() { perl -MCPAN\ 1.94_56 -e 1 &>/dev/null ; }
f207111d 178
179CPAN_supports_BUILDPL() { perl -MCPAN\ 1.9205 -e1 &>/dev/null; }