Turns out Travis CPAN mirror is not local, add a fallback
[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
25 echo_err -e "FAILED !!! (after ${DELTA_TIME}s)\nCommand executed:\n$2\nSTDOUT+STDERR:\n$LASTOUT"
26 return $LASTEXIT
27 else
28 echo_err "done (took ${DELTA_TIME}s)"
29 fi
30}
31
32extract_prereqs() {
71dd2ecc 33 # once --verbose is set, --no-verbose can't disable it
34 # do this by hand
b2435630 35 local PERL_CPANM_OPT="$( echo $PERL_CPANM_OPT | sed 's/--verbose\s*//' )"
71dd2ecc 36
b58ecb01 37 # hack-hack-hack
38 LASTEXIT=0
39 COMBINED_OUT="$( { stdout="$(cpanm --quiet --scandeps --format tree "$@")" ; } 2>&1; echo "!!!STDERRSTDOUTSEPARATOR!!!$stdout")" \
40 || LASTEXIT=$?
41
42 OUT=${COMBINED_OUT#*!!!STDERRSTDOUTSEPARATOR!!!}
43 ERR=$(grep -v " is up to date." <<< "${COMBINED_OUT%!!!STDERRSTDOUTSEPARATOR!!!*}")
44
45 if [[ "$LASTEXIT" != "0" ]] || [[ -n "$ERR" ]] ; then
46 echo_err "$(echo -e "Error occured (exit code $LASTEXIT) retrieving dependencies of $@:\n$ERR\n$OUT")"
47 exit 1
48 fi
49
50 # throw away non-children (what was in $@), throw away ascii art, convert to modnames
51 perl -p -e 's/^[a-z].+//i; s/^[^a-z]+//i; s/\-[^\-]+$/ /; s/\-/::/g' <<< "$OUT"
52}
53
54parallel_installdeps_notest() {
55 if [[ -z "$@" ]] ; then return; fi
56
57 # flatten list into one string
58 MODLIST=$(echo "$@")
59
60 # The reason we do things so "non-interactively" is that xargs -P will have the
61 # latest cpanm instance overwrite the buildlog. There seems to be no way to
62 # specify a custom buildlog, hence we just collect the verbose output
10e248bf 63 # and display it in case of "worker" failure
64 #
65 # Explanation of inline args:
66 #
67 # [09:38] <T> you need a $0
68 # [09:38] <G> hence the _
69 # [09:38] <G> bash -c '...' _
70 # [09:39] <T> I like -- because it's the magic that gnu getopts uses for somethign else
71 # [09:39] <G> or --, yes
72 # [09:39] <T> ribasushi: you could put "giant space monkey penises" instead of "--" and it would work just as well
73 #
b58ecb01 74 run_or_err "Installing (without testing) $MODLIST" \
10e248bf 75 "echo $MODLIST | xargs -n 1 -P $NUMTHREADS bash -c \\
76 'OUT=\$(cpanm --notest --no-man-pages \"\$@\" 2>&1 ) || (LASTEXIT=\$?; echo \"\$OUT\"; exit \$LASTEXIT)' \\
77 'giant space monkey penises'
78 "
b58ecb01 79}
80
81
82CPAN_is_sane() { perl -MCPAN\ 1.94_56 -e 1 &>/dev/null ; }