Remove vestigial unused @INC munge found after a8de639b
[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
851b6c2d 6TIMEOUT_CMD="/usr/bin/timeout --kill-after=9.5m --signal=TERM 9m"
b9970637 7
b58ecb01 8echo_err() { echo "$@" 1>&2 ; }
9
10if [[ "$TRAVIS" != "true" ]] ; then
11 echo_err "Running this script makes no sense outside of travis-ci"
12 exit 1
13fi
14
15tstamp() { echo -n "[$(date '+%H:%M:%S')]" ; }
16
17run_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 40apt_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 50extract_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!!!}
61 ERR=$(grep -v " is up to date." <<< "${COMBINED_OUT%!!!STDERRSTDOUTSEPARATOR!!!*}")
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
8fe19930 70 # throw away warnings, ascii art, convert to modnames
71 PQ=$(perl -p -e 's/^\!.*//; s/^[^a-z]+//i; s/\-[^\-]+$/ /; s/\-/::/g' <<< "$OUT")
f207111d 72
73 # throw away what was in $@
74 for m in "$@" ; do
75 PQ=$( perl -p -e 's/(?:\s|^)\Q'"$m"'\E(?:\s|$)/ /mg' <<< "$PQ")
76 done
77
78 # RV
79 echo "$PQ"
b58ecb01 80}
81
82parallel_installdeps_notest() {
83 if [[ -z "$@" ]] ; then return; fi
84
4242985f 85 # one module spec per line
86 MODLIST="$(printf '%s\n' "$@")"
b58ecb01 87
23905f5f 88 # We want to trap the output of each process and serially append them to
89 # each other as opposed to just dumping a jumbled up mass-log that would
90 # need careful unpicking by a human
91 #
92 # While cpanm does maintain individual buildlogs in more recent versions,
93 # we are not terribly interested in trying to figure out which log is which
94 # dist. The verbose-output + trap STDIO technique is vastly superior in this
95 # particular case
10e248bf 96 #
97 # Explanation of inline args:
98 #
99 # [09:38] <T> you need a $0
100 # [09:38] <G> hence the _
101 # [09:38] <G> bash -c '...' _
102 # [09:39] <T> I like -- because it's the magic that gnu getopts uses for somethign else
103 # [09:39] <G> or --, yes
104 # [09:39] <T> ribasushi: you could put "giant space monkey penises" instead of "--" and it would work just as well
105 #
4242985f 106 run_or_err "Installing (without testing) $(echo $MODLIST)" \
107 "echo \\
108\"$MODLIST\" \\
109 | xargs -d '\\n' -n 1 -P $NUMTHREADS bash -c \\
e6b373aa 110 'OUT=\$($TIMEOUT_CMD cpanm --notest \"\$@\" 2>&1 ) || (LASTEXIT=\$?; echo \"\$OUT\"; exit \$LASTEXIT)' \\
4242985f 111 'giant space monkey penises'
10e248bf 112 "
b58ecb01 113}
114
579472df 115installdeps() {
116 if [[ -z "$@" ]] ; then return; fi
117
118 echo_err "$(tstamp) Processing dependencies: $@"
119
120 local -x HARNESS_OPTIONS
121
122 HARNESS_OPTIONS="j$NUMTHREADS"
123
124 echo_err -n "Attempting install of $# modules under parallel ($HARNESS_OPTIONS) testing ... "
125
126 LASTEXIT=0
127 START_TIME=$SECONDS
e6b373aa 128 LASTOUT=$( _dep_inst_with_test "$@" ) || LASTEXIT=$?
579472df 129 DELTA_TIME=$(( $SECONDS - $START_TIME ))
130
131 if [[ "$LASTEXIT" = "0" ]] ; then
132 echo_err "done (took ${DELTA_TIME}s)"
133 else
e6b373aa 134 local errlog="after ${DELTA_TIME}s Exit:$LASTEXIT Log:$(/usr/bin/nopaste -q -s Shadowcat -d "Parallel testfail" <<< "$LASTOUT")"
a9fc70ee 135 echo_err -n "failed ($errlog) retrying with sequential testing ... "
136 POSTMORTEM="$POSTMORTEM$(
137 echo
77a86bbf 138 echo "Depinstall under $HARNESS_OPTIONS parallel testing failed $errlog"
139 echo "============================================================="
140 echo "Attempted installation of: $@"
141 echo "============================================================="
a9fc70ee 142 )"
579472df 143
144 HARNESS_OPTIONS=""
145 LASTEXIT=0
146 START_TIME=$SECONDS
e6b373aa 147 LASTOUT=$( _dep_inst_with_test "$@" ) || LASTEXIT=$?
579472df 148 DELTA_TIME=$(( $SECONDS - $START_TIME ))
149
150 if [[ "$LASTEXIT" = "0" ]] ; then
151 echo_err "done (took ${DELTA_TIME}s)"
152 else
153 echo_err "FAILED !!! (after ${DELTA_TIME}s)"
154 echo_err "STDOUT+STDERR:"
155 echo_err "$LASTOUT"
156 exit 1
157 fi
158 fi
159
160 INSTALLDEPS_OUT="${INSTALLDEPS_OUT}${LASTOUT}"
161}
162
e6b373aa 163_dep_inst_with_test() {
164 if [[ "$DEVREL_DEPS" == "true" ]] ; then
165 # --dev is already part of CPANM_OPT
166 $TIMEOUT_CMD cpanm "$@" 2>&1
167 else
168 $TIMEOUT_CMD cpan "$@" 2>&1
579472df 169
e6b373aa 170 # older perls do not have a CPAN which can exit with error on failed install
171 for m in "$@"; do
172 if ! perl -e '
579472df 173
647da28e 174my $mod = (
579472df 175 $ARGV[0] =~ m{ \/ .*? ([^\/]+) $ }x
176 ? do { my @p = split (/\-/, $1); pop @p; join "::", @p }
177 : $ARGV[0]
647da28e 178);
179
180$mod = q{List::Util} if $mod eq q{Scalar::List::Utils};
181
182eval qq{require($mod)} or ( print $@ and exit 1)
579472df 183
e6b373aa 184 ' "$m" 2> /dev/null ; then
185 echo -e "$m installation seems to have failed"
186 return 1
187 fi
188 done
189 fi
579472df 190}
191
b58ecb01 192CPAN_is_sane() { perl -MCPAN\ 1.94_56 -e 1 &>/dev/null ; }
f207111d 193
194CPAN_supports_BUILDPL() { perl -MCPAN\ 1.9205 -e1 &>/dev/null; }