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