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