Fix silly thinko in travis_prepare_env's extract_prereqs()
[dbsrgits/DBIx-Class.git] / maint / travis-ci_prepare_env
CommitLineData
d70070c9 1#!/bin/bash
2
3# * The way .travis.yml is fed to the command controller is idiotic - it
4# makes using multiline `bash -c` statements impossible. Therefore to
5# aid readability (our travis logic is rather complex), the bulk of
6# functionality is moved to a script. More about the problem here:
7# https://github.com/travis-ci/travis-ci/issues/497
8
9set -e
10
44020f08 11echo_err() { echo "$@" 1>&2 ; }
12
13tstamp() { echo -n "[$(date '+%H:%M:%S')]" ; }
14
15run_or_err() {
16 echo_err -n "$(tstamp) $1 ... "
17
dd5ee5dd 18 LASTEXIT=0
19 LASTOUT=$( bash -c "$2" 2>&1 ) || LASTEXIT=$?
20
44020f08 21 if [[ "$LASTEXIT" != "0" ]] ; then
22 echo_err -e "FAILED !!!\nCommand executed:\n$2\nSTDOUT+STDERR:\n$LASTOUT"
23 return $LASTEXIT
24 else
25 echo_err "done."
26 fi
27}
28
d70070c9 29if [[ "$TRAVIS" != "true" ]] ; then
44020f08 30 echo_err "Running this script makes no sense outside of travis-ci"
d70070c9 31 exit 1
32fi
33
34#
35# Current dir is the root of the DBIC checkout (make sure to
36# come back there if moving around before end of this script)
37#
38# envvars available for us:
39#
40# NUMTHREADS = { number}
41# dynamically determined amount of threads we want to run on this
42# smoker concurrently
43#
44# CLEANTEST = [ true | false ]
45# controls whether we simulate a "user-side" install experience
46# that is - no author deps and no M::I installation
47#
48# BREWVER = { tripple dotted perl version, e.g. 5.8.3 }
49# brew a custom perl version such and such
50#
51# BREWOPTS = { string to be fed unquoted to perlbrew, e.g. -Duseithreads }
52# build options for perlbrew
53#
54
44020f08 55echo_err "$(tstamp) Smoke preconfiguration starting $(date)"
56
57TRAVIS_CPAN_MIRROR=$(echo "$PERL_CPANM_OPT" | grep -oP -- '--mirror\s+\S+' | head -n 1 | cut -d ' ' -f 2)
58if ! [[ "$TRAVIS_CPAN_MIRROR" =~ "http://" ]] ; then
59 echo_err "Unable to extract primary cpan mirror from PERL_CPANM_OPT - something is wrong"
60 echo_err "PERL_CPANM_OPT: $PERL_CPANM_OPT"
61 exit 1
62fi
63
64export PERL_MM_USE_DEFAULT=1 PERL_MM_NONINTERACTIVE=1 PERL_AUTOINSTALL_PREFER_CPAN=1 PERLBREW_CPAN_MIRROR="$TRAVIS_CPAN_MIRROR"
65
66# Fixup CPANM_OPT to behave more like a traditional cpan client
67export PERL_CPANM_OPT="$( echo $PERL_CPANM_OPT | sed 's/--skip-satisfied//' )"
68
d70070c9 69if [[ -n "$BREWVER" ]] ; then
d0b79c51 70 # .travis.yml already restricts branches to master, topic/* and smoke/*
71 # do some extra short-circuiting here
72
73 # when smoking master do not attempt bleadperl (not release-critical)
74 if [[ "$TRAVIS_BRANCH" = "master" ]] && [[ "$BREWVER" = "blead" ]]; then
75 export SHORT_CIRCUIT_SMOKE=1
76 # on topic/ branches test only with travis perls
77 elif [[ "$TRAVIS_BRANCH" =~ "topic/" ]]; then
c299fd65 78 export SHORT_CIRCUIT_SMOKE=1
d0b79c51 79 fi
80
81 if [[ -n "$SHORT_CIRCUIT_SMOKE" ]]; then
44020f08 82 echo_err "$(tstamp) non-smoke branch and custom perl compilation requested - bailing out"
e8e2b3bf 83 sleep 20 # give the console time to attach, otherwise it hangs
c299fd65 84 return # this is like an `exit 0` in sourcing
85 fi
86
44020f08 87 run_or_err "Compiling/installing Perl $BREWVER (without testing, may take up to 5 minutes)" \
dd5ee5dd 88 "perlbrew install --as $BREWVER --notest --verbose $BREWOPTS -j $NUMTHREADS $BREWVER"
44020f08 89
dd5ee5dd 90 sync
d70070c9 91 perlbrew use $BREWVER
92fi
93
44020f08 94# configure CPAN.pm - older versions go into an endless loop
95# when trying to autoconf themselves
96CPAN_CFG_SCRIPT="
97 require CPAN;
98 require CPAN::FirstTime;
99 *CPAN::FirstTime::conf_sites = sub {};
100 CPAN::Config->load;
101 \$CPAN::Config->{urllist} = [qw{ $TRAVIS_CPAN_MIRROR }];
102 \$CPAN::Config->{halt_on_failure} = 1;
103 CPAN::Config->commit;
104"
105run_or_err "Configuring CPAN.pm" "perl -e '$CPAN_CFG_SCRIPT'"
106
107extract_prereqs() {
108 # hack-hack-hack
dd5ee5dd 109 LASTEXIT=0
44020f08 110 COMBINED_OUT="$( { stdout="$(cpanm --quiet --scandeps --format tree "$@")" ; } 2>&1; echo "!!!STDERRSTDOUTSEPARATOR!!!$stdout")" \
111 || LASTEXIT=$?
112
113 OUT=${COMBINED_OUT#*!!!STDERRSTDOUTSEPARATOR!!!}
114 ERR=$(grep -v " is up to date." <<< "${COMBINED_OUT%!!!STDERRSTDOUTSEPARATOR!!!*}")
115
44020f08 116 if [[ "$LASTEXIT" != "0" ]] || [[ -n "$ERR" ]] ; then
117 echo_err "$(echo -e "Error occured (exit code $LASTEXIT) retrieving dependencies of $@:\n$ERR\n$OUT")"
118 exit 1
119 fi
120
121 # throw away non-children (what was in $@), throw away ascii art, convert to modnames
fde438ed 122 perl -p -e 's/^[a-z].+//i; s/^[^a-z]+//i; s/\-[^\-]+$/ /; s/\-/::/g' <<< "$OUT"
44020f08 123}
d70070c9 124
44020f08 125parallel_installdeps_notest() {
e8e2b3bf 126 if [[ -z "$@" ]] ; then return; fi
127
44020f08 128 # flatten list into one string
129 MODLIST=$(echo "$@")
130
e8e2b3bf 131 # The reason we do things so "non-interactively" is that xargs -P will have the
132 # latest cpanm instance overwrite the buildlog. There seems to be no way to
133 # specify a custom buildlog, hence we just collect the verbose output
134 # and display it in case of failure
44020f08 135 run_or_err "Installing (without testing) $MODLIST" \
136 "echo $MODLIST | xargs -n 1 -P $NUMTHREADS cpanm --verbose --no-interactive --notest --no-man-pages"
e8e2b3bf 137}
138
e8e2b3bf 139if [[ "$CLEANTEST" = "true" ]]; then
140 # get the last inc/ off cpan - we will get rid of MI
141 # soon enough, but till then this will do
142 # the point is to have a *really* clean perl (the ones
143 # we build are guaranteed to be clean, without side
144 # effects from travis preinstalls)
e352dd9a 145
146 # trick cpanm into executing true as shell - we just need the find+unpack
44020f08 147 run_or_err "Downloading DBIC inc/ from CPAN" \
148 "SHELL=/bin/true cpanm --look DBIx::Class"
149
150 mv ~/.cpanm/latest-build/DBIx-Class-*/inc .
e8e2b3bf 151else
6d2b5c14 152 # we will be running all dbic tests - preinstall lots of stuff, run basic tests
153 # using SQLT and set up whatever databases necessary
154
155 # do the preinstall in several passes to minimize amount of cross-deps installing
156 # multiple times, and to avoid module re-architecture breaking another install
157 # (e.g. once Carp is upgraded there's no more Carp::Heavy)
158 #
159 parallel_installdeps_notest ExtUtils::MakeMaker
160 parallel_installdeps_notest Module::Build Carp
161 parallel_installdeps_notest Module::Runtime ExtUtils::Depends File::Spec
162 parallel_installdeps_notest Test::Exception Data::Dumper LWP
163 parallel_installdeps_notest Test::Fatal Test::Warn bareword::filehandles
164 parallel_installdeps_notest namespace::clean Class::XSAccessor MRO::Compat
165 parallel_installdeps_notest DBD::SQLite Moo Class::Accessor::Grouped
166 parallel_installdeps_notest Module::Install DateTime::Format::Strptime
167 parallel_installdeps_notest JSON::DWIW JSON JSON::XS Test::Pod::Coverage Test::EOL
168 parallel_installdeps_notest MooseX::Types JSON::Any Class::DBI
e8e2b3bf 169
170 export DBICTEST_SQLT_DEPLOY=1
171
2b28f530 172### apt-get invocation - faster to grab everything at once
173 #
174 # FIXME these debconf lines should automate the firebird config but do not :(((
175 sudo bash -c 'echo -e "firebird2.5-super\tshared/firebird/enabled\tboolean\ttrue" | debconf-set-selections'
176 sudo bash -c 'echo -e "firebird2.5-super\tshared/firebird/sysdba_password/new_password\tpassword\t123" | debconf-set-selections'
177
44020f08 178 APT_PACKAGES="memcached firebird2.5-super firebird2.5-dev expect"
179 run_or_err "Installing packages ($APT_PACKAGES)" "sudo apt-get install -y $APT_PACKAGES"
d70070c9 180
2b28f530 181### memcached
d70070c9 182 export DBICTEST_MEMCACHED=127.0.0.1:11211
183
2b28f530 184### mysql
44020f08 185 run_or_err "Creating MySQL TestDB" "mysql -e 'create database dbic_test;'"
d70070c9 186 export DBICTEST_MYSQL_DSN='dbi:mysql:database=dbic_test;host=127.0.0.1'
187 export DBICTEST_MYSQL_USER=root
188
2b28f530 189### pg
44020f08 190 run_or_err "Creating PostgreSQL TestDB" "psql -c 'create database dbic_test;' -U postgres"
d70070c9 191 export DBICTEST_PG_DSN='dbi:Pg:database=dbic_test;host=127.0.0.1'
192 export DBICTEST_PG_USER=postgres
193
2b28f530 194### firebird
195 # poor man's deb config
44020f08 196 EXPECT_FB_SCRIPT='
197 spawn dpkg-reconfigure --frontend=text firebird2.5-super
198 expect "Enable Firebird server?"
199 send "\177\177\177\177yes\r"
200 expect "Password for SYSDBA"
201 send "123\r"
202 sleep 1
203 wait
204 sleep 1
205 '
206 run_or_err "Re-configuring Firebird" "
2b28f530 207 sync
44020f08 208 DEBIAN_FRONTEND=text sudo expect -c '$EXPECT_FB_SCRIPT'
209 sleep 1
47d391d5 210 sync
2b28f530 211 # restart the server for good measure
212 sudo /etc/init.d/firebird2.5-super stop || true
44020f08 213 sleep 1
214 sync
2b28f530 215 sudo /etc/init.d/firebird2.5-super start
44020f08 216 sleep 1
217 sync
218 "
2b28f530 219
220 # creating testdb
d1d19682 221 # FIXME - this step still fails from time to time >:(((
222 # has to do with the FB reconfiguration I suppose
223 # for now if it fails - simply skip FB testing
224 if run_or_err "Creating Firebird TestDB" \
44020f08 225 "echo \"CREATE DATABASE '/var/lib/firebird/2.5/data/dbic_test.fdb';\" | sudo isql-fb -u sysdba -p 123"
d1d19682 226 then
227 # the official version is full of 5.10-isms, but works perfectly fine on 5.8
228 # pull in our patched copy
229 run_or_err "Fetching patched DBD::Firebird" \
230 "git clone https://github.com/dbsrgits/perl-dbd-firebird-5.8.git ~/dbd-firebird"
231
232 # the official version is very much outdated and does not compile on 5.14+
233 # use this rather updated source tree (needs to go to PAUSE):
234 # https://github.com/pilcrow/perl-dbd-interbase
235 run_or_err "Fetching patched DBD::InterBase" \
236 "git clone https://github.com/dbsrgits/perl-dbd-interbase ~/dbd-interbase"
237
238 parallel_installdeps_notest ~/dbd-interbase/ ~/dbd-firebird/
239
240 export DBICTEST_FIREBIRD_DSN=dbi:Firebird:dbname=/var/lib/firebird/2.5/data/dbic_test.fdb
241 export DBICTEST_FIREBIRD_USER=SYSDBA
242 export DBICTEST_FIREBIRD_PASS=123
243
244 export DBICTEST_FIREBIRD_INTERBASE_DSN=dbi:InterBase:dbname=/var/lib/firebird/2.5/data/dbic_test.fdb
245 export DBICTEST_FIREBIRD_INTERBASE_USER=SYSDBA
246 export DBICTEST_FIREBIRD_INTERBASE_PASS=123
247 fi
2b28f530 248
249### oracle
d70070c9 250 # FIXME: todo
251 #DBICTEST_ORA_DSN=dbi:Oracle:host=localhost;sid=XE
252 #DBICTEST_ORA_USER=dbic_test
253 #DBICTEST_ORA_PASS=123
254 #DBICTEST_ORA_EXTRAUSER_DSN=dbi:Oracle:host=localhost;sid=XE
255 #DBICTEST_ORA_EXTRAUSER_USER=dbic_test_extra
256 #DBICTEST_ORA_EXTRAUSER_PASS=123
257 #ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/client
258fi
259
6d2b5c14 260CPAN_is_sane() { perl -MCPAN\ 1.94_56 -e 1 &>/dev/null ; }
261
262# install the rest
263if [[ "$CLEANTEST" = "true" ]]; then
264 # older perls do not have a CPAN which understands configure_requires
265 # properly and what is worse a `cpan Foo` run exits with 0 even if some
266 # modules failed to install
267 # The first CPAN which is somewhat sane is around 1.94_56 (perl 5.12)
268 # The problem is that the first sane version also brings a *lot* of
269 # deps with it, notably things like YAML and HTTP::Tiny
270 # The goal of CLEANTEST is to have as little extra stuff installed as
271 # possible, mainly to catch "but X is perl core" mistakes
272 # So instead we still use our stock (possibly old) CPAN, and add some
273 # handholding
274
275 CPAN_is_sane || \
276 run_or_err "Pre-installing ExtUtils::MakeMaker and Module::Build" \
277 "cpan ExtUtils::MakeMaker Module::Build"
278
279 if ! perl -MModule::Build -e 1 &> /dev/null ; then
280 echo_err -e "Module::Build installation failed\n$LASTOUT"
281 exit 1
282 fi
283
284 # DBI has by far the longest test runtime - run less tests
285 # FIXME horrible horrible hack, need to implement in DBI itself
286 run_or_err "Downloading latest DBI distdir from CPAN" \
287 "SHELL=/bin/true cpanm --look DBI"
288 cd ~/.cpanm/latest-build/DBI-*/
289 perl -p -i -e 's/(create_.+?_tests) => 1/$1 => 0/' Makefile.PL
290 run_or_err "Pre-installing DBI, but running less tests" "perl Makefile.PL && make && make test && make install"
291 cd - &>/dev/null
292
293 # generate the makefile which will have different deps depending on
294 # the runmode and envvars set above
295 run_or_err "Configure on current branch" "perl Makefile.PL"
296 HARD_DEPS="$(echo $(make listdeps))"
297
298 # this is a fucked CPAN - won't understand configure_requires of
299 # various pieces we may run into
300 CPAN_is_sane || HARD_DEPS="ExtUtils::Depends B::Hooks::OP::Check $HARD_DEPS"
301
302##### TEMPORARY WORKAROUNDS
303
304 # not sure what's going on here yet
305 perl -M5.008008 -e 1 &> /dev/null || \
306 parallel_installdeps_notest multidimensional bareword::filehandles
307
308 # work around Params::Validate not having a Makefile.PL so really old
309 # toolchains can not figure out what the prereqs are ;(
310 # Need to do more research before filing a bug requesting Makefile inclusion
311 perl -M5.008008 -e 1 &> /dev/null || \
312 HARD_DEPS="$(extract_prereqs Params::Validate) $HARD_DEPS"
313
314##### END TEMPORARY WORKAROUNDS
315
316 run_or_err "Installing/testing dependencies (may take up to 10 minutes): $HARD_DEPS" "cpan $HARD_DEPS"
317
318 # this is a fucked CPAN - save the log as we may need it
319 CPAN_is_sane || INSTALLDEPS_OUT="$LASTOUT"
320
321else
322 # generate the makefile which will have different deps depending on
323 # the runmode and envvars set above
324 run_or_err "Configure on current branch" "perl Makefile.PL"
325
326 # listalldeps is deliberate - will upgrade everything it can find
327 parallel_installdeps_notest $(make listalldeps)
328fi
d70070c9 329
6d2b5c14 330echo_err "$(tstamp) Module configuration finished"
331# this will display list of available versions
332perl Makefile.PL
d70070c9 333
334# make sure we got everything we need
d70070c9 335if [[ -n "$(make listdeps)" ]] ; then
44020f08 336 echo_err "$(tstamp) Not all deps installed - something went wrong :("
6d2b5c14 337 sleep 1 # without this the echo below confuses the console listener >.<
338 CPAN_is_sane || echo_err -e "Outdated CPAN.pm used - full logs follows\n$INSTALLDEPS_OUT\n\nSearch for 'NOT OK' in the text above\n\nDeps still missing:"
339 sleep 3 # without this the above echo confuses the console listener >.<
d70070c9 340 make listdeps
341 exit 1
342fi
44020f08 343
344run_or_err "Prepare blib" "make pure_all"
345
346# announce what are we running
a7291faa 347echo_err "
348========================= CONFIGURATION COMPLETE ===========================
6d2b5c14 349$(tstamp) Configuration phase seems to have taken $(date -ud "@$SECONDS" '+%H:%M:%S') (@$SECONDS)
a7291faa 350
351= CPUinfo
352$(perl -0777 -p -e 's/.+\n\n(?!\z)//s' < /proc/cpuinfo)
353
354= Meminfo
355$(free -m -t)
356
357= Environment
358$(env | grep -P 'TEST|TRAVIS|PERL|DBIC' | LC_ALL=C sort | cat -v)
359
360= Perl in use
361$(perl -V)
362============================================================================
363
364$(tstamp) Starting tests using $NUMTHREADS concurrent processes"