(travis) Make sure everything works even when we are SAD
[dbsrgits/DBIx-Class.git] / maint / travis-ci_scripts / 20_install.bash
1 #!/bin/bash
2
3 if [[ "${BASH_SOURCE[0]}" == "${0}" ]] ; then
4   echo "This script can not be executed standalone - it can only be source()d" 1>&2
5   exit 1
6 fi
7
8 if [[ -n "$SHORT_CIRCUIT_SMOKE" ]] ; then return ; fi
9
10 # we need a mirror that both has the standard index and a backpan version rolled
11 # into one, due to MDV testing
12 export CPAN_MIRROR="http://cpan.metacpan.org/"
13
14 PERL_CPANM_OPT="$PERL_CPANM_OPT --mirror $CPAN_MIRROR"
15
16 # do not set PERLBREW_CPAN_MIRROR - not all backpan-like mirrors have the perl tarballs
17 export PERL_MM_USE_DEFAULT=1 PERL_MM_NONINTERACTIVE=1 PERL_AUTOINSTALL_PREFER_CPAN=1 HARNESS_TIMER=1 MAKEFLAGS="-j$VCPU_USE"
18
19 # try CPAN's latest offering if requested
20 if [[ "$DEVREL_DEPS" == "true" ]] ; then
21
22   PERL_CPANM_OPT="$PERL_CPANM_OPT --dev"
23
24 fi
25
26 # Fixup CPANM_OPT to behave more like a traditional cpan client
27 export PERL_CPANM_OPT="--verbose --no-interactive --no-man-pages $( echo $PERL_CPANM_OPT | sed 's/--skip-satisfied//' )"
28
29 if [[ -n "$BREWVER" ]] ; then
30
31   # since perl 5.14 a perl can safely be built concurrently with -j$large
32   # (according to brute force testing and my power bill)
33   if [[ "$BREWVER" =~ [A-Za-z] ]] || perl -Mversion -e "exit !!(version->new(q($BREWVER)) < 5.014)" ; then
34     perlbrew_jopt="$VCPU_USE"
35   fi
36
37   BREWSRC="$BREWVER"
38
39   if is_cperl; then
40     if [[ "$BREWVER" == "cperl-master" ]] ; then
41       git clone --single-branch --depth=1 --branch=master https://github.com/perl11/cperl /tmp/cperl-master
42       BREWSRC="/tmp/cperl-master"
43     else
44       # FFS perlbrew ( see http://wollmers-perl.blogspot.de/2015/10/install-cperl-with-perlbrew.html )
45       wget -qO- https://github.com/perl11/cperl/archive/$BREWVER.tar.gz > /tmp/cperl-$BREWVER.tar.gz
46       BREWSRC="/tmp/cperl-$BREWVER.tar.gz"
47     fi
48   elif [[ "$BREWVER" == "schmorp_stableperl" ]] ; then
49     BREWSRC="http://stableperl.schmorp.de/dist/stableperl-5.22.0-1.001.tar.gz"
50   fi
51
52   run_or_err "Compiling/installing Perl $BREWVER (without testing, using ${perlbrew_jopt:-1} threads, may take up to 5 minutes)" \
53     "perlbrew install --as $BREWVER --notest --noman --verbose $BREWOPTS -j${perlbrew_jopt:-1}  $BREWSRC"
54
55   # FIXME work around https://github.com/perl11/cperl/issues/144
56   # (still affecting 5.22.3)
57   if is_cperl && ! [[ -f ~/perl5/perlbrew/perls/$BREWVER/bin/perl ]] ; then
58     ln -s ~/perl5/perlbrew/perls/$BREWVER/bin/cperl ~/perl5/perlbrew/perls/$BREWVER/bin/perl || /bin/true
59   fi
60
61   # can not do 'perlbrew use' in the run_or_err subshell above, or a $()
62   # furthermore some versions of `perlbrew use` return 0 regardless of whether
63   # the perl is found (won't be there unless compilation suceeded, wich *ALSO* returns 0)
64   perlbrew use $BREWVER || /bin/true
65
66   if \
67     ! [[ -x ~/perl5/perlbrew/perls/$BREWVER/bin/perl ]] \
68   ||  [[ "$( perlbrew use | grep -oP '(?<=Currently using ).+' )" != "$BREWVER" ]]
69   then
70     echo_err "Unable to switch to $BREWVER - compilation failed...?"
71     echo_err "$LASTOUT"
72     exit 1
73   fi
74
75 # no brewver - this means a travis perl, which means we want to clean up
76 # the presently installed libs
77 elif [[ "$CLEANTEST" == "true" ]] && [[ "$POISON_ENV" != "true" ]] ; then
78   purge_sitelib
79 fi
80
81 if [[ "$POISON_ENV" = "true" ]] ; then
82   # create a perlbrew-specific local lib
83   perlbrew lib create travis-local
84   perlbrew use "$( perlbrew use | grep -oP '(?<=Currently using ).+' )@travis-local"
85   echo_err "POISON_ENV active - adding a local lib: $(perlbrew use)"
86 fi
87
88 # configure CPAN.pm - older versions go into an endless loop
89 # when trying to autoconf themselves
90 CPAN_CFG_SCRIPT="
91   require CPAN;
92   require CPAN::FirstTime;
93   *CPAN::FirstTime::conf_sites = sub {};
94   CPAN::Config->load;
95   \$CPAN::Config->{urllist} = [qw{ $CPAN_MIRROR }];
96   \$CPAN::Config->{halt_on_failure} = $( is_cperl && echo -n 0 || echo -n 1 );
97   CPAN::Config->commit;
98 "
99 run_or_err "Configuring CPAN.pm" "perl -e '$CPAN_CFG_SCRIPT'"
100
101
102 # These envvars are always set, more *maybe* below
103 export DBIC_SHUFFLE_UNORDERED_RESULTSETS=1
104
105 # bogus nonexisting DBI_*
106 export DBI_DSN="dbi:ODBC:server=NonexistentServerAddress"
107 export DBI_DRIVER="ADO"
108
109 # some people do in fact set this - boggle!!!
110 # it of course won't work before 5.8.4
111 if perl -M5.008004 -e 1 &>/dev/null ; then
112   export PERL_STRICTURES_EXTRA=1
113 fi
114
115
116 # poison the environment
117 if [[ "$POISON_ENV" = "true" ]] ; then
118
119   toggle_vars=( MVDT )
120
121   [[ "$CLEANTEST" == "true" ]] && toggle_vars+=( BREAK_CC )
122
123   for var in "${toggle_vars[@]}"  ; do
124     if [[ -z "${!var}" ]] ; then
125       export $var=true
126       echo "POISON_ENV: setting $var to 'true'"
127     fi
128   done
129
130   # look through lib, find all mentioned DBIC* ENVvars and set them to true and see if anything explodes
131   toggle_booleans=( $( grep -ohP '\bDBIC_[0-9_A-Z]+' -r lib/ --exclude-dir Optional | sort -u | grep -vP '^(DBIC_TRACE(_PROFILE)?|DBIC_.+_DEBUG)$' ) )
132
133   # some extra pollutants
134   toggle_booleans+=( \
135     DBICTEST_ASSERT_NO_SPURIOUS_EXCEPTION_ACTION \
136     DBICTEST_SQLITE_USE_FILE \
137     DBICTEST_RUN_ALL_TESTS \
138     DBICTEST_SQLITE_REVERSE_DEFAULT_ORDER \
139   )
140
141   # if we have Moose - try to run everything under replicated
142   # FIXME - when switching to Moo kill this
143   if [[ "$CLEANTEST" != "true" ]] && perl -M5.008003 -e 1 &>/dev/null ; then
144     toggle_booleans+=( DBICTEST_VIA_REPLICATED )
145   fi
146
147   for var in "${toggle_booleans[@]}"
148   do
149     if [[ -z "${!var}" ]] ; then
150       export $var=1
151       echo "POISON_ENV: setting $var to 1"
152     fi
153   done
154
155   echo "POISON_ENV: setting PERL_UNICODE=SAD"
156   export PERL_UNICODE=SAD
157
158
159 ### emulate a local::lib-like env
160
161   # trick cpanm into executing true as shell - we just need the find+unpack
162   run_or_err "Downloading latest stable DBIC from CPAN" \
163     "SHELL=/bin/true cpanm --look DBIx::Class"
164
165   # move it somewhere as following cpanm will clobber it
166   run_or_err "Moving latest stable DBIC from CPAN to /tmp" "mv ~/.cpanm/latest-build/DBIx-Class-*/lib /tmp/stable_dbic_lib"
167
168   export PERL5LIB="/tmp/stable_dbic_lib:$PERL5LIB"
169
170   # perldoc -l <mod> searches $(pwd)/lib in addition to PERL5LIB etc, hence the cd /
171   echo_err "Latest stable DBIC (without deps) locatable via \$PERL5LIB at $(cd / && perldoc -l DBIx::Class)"
172 fi
173
174 if [[ "$CLEANTEST" != "true" ]] ; then
175   # using SQLT if will be available
176   # not doing later because we will be running in a subshell
177   export DBICTEST_SQLT_DEPLOY=1
178
179 fi
180
181 # FIXME - work around https://github.com/miyagawa/cpanminus/issues/462
182 # seriously...
183 perl -p -i -e 's/\blocal\$self->\{notest\}=1;//' $(which cpanm)