d23b6cd7c8122d7cb5ff2c8f9d71ab11e1c6088d
[dbsrgits/DBIx-Class.git] / maint / travis-ci_scripts / 30_before_script.bash
1 #!/bin/bash
2
3 source maint/travis-ci_scripts/common.bash
4 if [[ -n "$SHORT_CIRCUIT_SMOKE" ]] ; then return ; fi
5
6 # poison the environment - basically look through lib, find all mentioned
7 # ENVvars and set them to true and see if anything explodes
8 if [[ "$POISON_ENV" = "true" ]] ; then
9   for var in $(grep -P '\$ENV\{' -r lib/ | grep -oP 'DBIC_\w+' | sort -u | grep -v DBIC_TRACE) ; do
10     if [[ -z "${!var}" ]] ; then
11       export $var=1
12     fi
13   done
14
15   export DBI_DSN="dbi:ODBC:server=NonexistentServerAddress"
16   export DBI_DRIVER="ADO"
17
18   export DBICTEST_SQLITE_REVERSE_DEFAULT_ORDER=1
19 fi
20
21 if [[ "$CLEANTEST" = "true" ]]; then
22   # get the last inc/ off cpan - we will get rid of MI
23   # soon enough, but till then this will do
24   # the point is to have a *really* clean perl (the ones
25   # we build are guaranteed to be clean, without side
26   # effects from travis preinstalls)
27
28   # trick cpanm into executing true as shell - we just need the find+unpack
29   run_or_err "Downloading DBIC inc/ from CPAN" \
30     "SHELL=/bin/true cpanm --look DBIx::Class"
31
32   mv ~/.cpanm/latest-build/DBIx-Class-*/inc .
33
34   # older perls do not have a CPAN which understands configure_requires
35   # properly and what is worse a `cpan Foo` run exits with 0 even if some
36   # modules failed to install
37   # The first CPAN which is somewhat sane is around 1.94_56 (perl 5.12)
38   # The problem is that the first sane version also brings a *lot* of
39   # deps with it, notably things like YAML and HTTP::Tiny
40   # The goal of CLEANTEST is to have as little extra stuff installed as
41   # possible, mainly to catch "but X is perl core" mistakes
42   # So instead we still use our stock (possibly old) CPAN, and add some
43   # handholding
44   if ! CPAN_is_sane ; then
45     for m in \
46 ExtUtils::MakeMaker \
47 ExtUtils::CBuilder \
48 R/RS/RSAVAGE/Tree-DAG_Node-1.13.tgz \
49 Module::Build \
50 E/ET/ETHER/Class-Method-Modifiers-2.04.tar.gz \
51 ; do
52       run_or_err "Pre-installing $m" "cpan $m"
53       if ! perl -e '
54
55 eval ( q{require } . (
56   $ARGV[0] =~ m{ \/ .*? ([^\/]+) $ }x
57     ? do { my @p = split (/\-/, $1); pop @p; join "::", @p }
58     : $ARGV[0]
59 ) ) or ( print $@ and exit 1)' "$m" 2> /dev/null ; then
60
61         echo_err -e "$m installation failed\n$LASTOUT"
62         exit 1
63       fi
64     done
65   fi
66
67
68   # DBI has by far the longest test runtime - run less tests
69   # FIXME horrible horrible hack, need to implement in DBI itself
70   run_or_err "Downloading latest DBI distdir from CPAN" \
71     "SHELL=/bin/true cpanm --look DBI"
72   cd ~/.cpanm/latest-build/DBI-*/
73   perl -p -i -e 's/(create_.+?_tests) => 1/$1 => 0/' Makefile.PL
74   run_or_err "Pre-installing DBI, but running less tests" "perl Makefile.PL && make && make test && make install"
75   cd - &>/dev/null
76
77 else
78   # we will be running all dbic tests - preinstall lots of stuff, run basic tests
79   # using SQLT and set up whatever databases necessary
80   export DBICTEST_SQLT_DEPLOY=1
81
82   # do the preinstall in several passes to minimize amount of cross-deps installing
83   # multiple times, and to avoid module re-architecture breaking another install
84   # (e.g. once Carp is upgraded there's no more Carp::Heavy,
85   # while a File::Path upgrade may cause a parallel EUMM run to fail)
86   #
87   parallel_installdeps_notest ExtUtils::MakeMaker
88   parallel_installdeps_notest File::Path
89   parallel_installdeps_notest Carp
90   parallel_installdeps_notest Module::Build Module::Runtime
91   parallel_installdeps_notest File::Spec Data::Dumper
92   parallel_installdeps_notest Test::Exception Encode::Locale Test::Fatal R/RS/RSAVAGE/Tree-DAG_Node-1.13.tgz
93   parallel_installdeps_notest Test::Warn B::Hooks::EndOfScope Test::Differences HTTP::Status
94   parallel_installdeps_notest Test::Pod::Coverage Test::EOL Devel::GlobalDestruction Sub::Name MRO::Compat Class::XSAccessor URI::Escape HTML::Entities
95   parallel_installdeps_notest YAML LWP Class::Trigger JSON::XS DBI DateTime::Format::Builder Class::Accessor::Grouped Package::Variant
96   parallel_installdeps_notest Moose Module::Install JSON SQL::Translator File::Which
97
98   if [[ -n "DBICTEST_FIREBIRD_DSN" ]] ; then
99     # the official version is very much outdated and does not compile on 5.14+
100     # use this rather updated source tree (needs to go to PAUSE):
101     # https://github.com/pilcrow/perl-dbd-interbase
102     run_or_err "Fetching patched DBD::InterBase" \
103       "git clone https://github.com/dbsrgits/perl-dbd-interbase ~/dbd-interbase"
104
105     parallel_installdeps_notest ~/dbd-interbase/
106   fi
107
108 fi
109
110 # generate the makefile which will have different deps depending on
111 # the runmode and envvars set above
112 run_or_err "Configure on current branch" "perl Makefile.PL"
113
114 # install (remaining) dependencies, sometimes with a gentle push
115 if [[ "$CLEANTEST" = "true" ]]; then
116   # we may need to prepend some stuff to that list
117   HARD_DEPS="$(echo $(make listdeps))"
118
119 ##### TEMPORARY WORKAROUNDS
120
121   # work around Params::Validate not having a Makefile.PL so really old
122   # toolchains can not figure out what the prereqs are ;(
123   # Need to do more research before filing a bug requesting Makefile inclusion
124   perl -M5.008008 -e 1 &> /dev/null || \
125     HARD_DEPS="$(extract_prereqs Params::Validate) $HARD_DEPS"
126
127 ##### END TEMPORARY WORKAROUNDS
128
129   run_or_err "Installing/testing dependencies (may take up to 3 minutes): $HARD_DEPS" "cpan $HARD_DEPS"
130
131   # this is a fucked CPAN - save the log as we may need it
132   CPAN_is_sane || INSTALLDEPS_OUT="$LASTOUT"
133
134 else
135   # listalldeps is deliberate - will upgrade everything it can find
136   parallel_installdeps_notest $(make listalldeps)
137
138   if [[ -n "$TEST_BUILDER_BETA_CPAN_TARBALL" ]] ; then
139     parallel_installdeps_notest $TEST_BUILDER_BETA_CPAN_TARBALL
140   fi
141 fi
142
143 echo_err "$(tstamp) Dependency configuration finished"
144 # this will display list of available versions
145 perl Makefile.PL
146
147 # make sure we got everything we need
148 if [[ -n "$(make listdeps)" ]] ; then
149   echo_err "$(tstamp) Not all deps installed - something went wrong :("
150   sleep 1 # without this the echo below confuses the console listener >.<
151   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:"
152   sleep 3 # without this the above echo confuses the console listener >.<
153   make listdeps
154   exit 1
155 fi
156
157 # announce what are we running
158 echo_err "
159 ===================== DEPENDENCY CONFIGURATION COMPLETE =====================
160 $(tstamp) Configuration phase seems to have taken $(date -ud "@$SECONDS" '+%H:%M:%S') (@$SECONDS)
161
162 = CPUinfo
163 $(perl -0777 -p -e 's/.+\n\n(?!\z)//s' < /proc/cpuinfo)
164
165 = Meminfo
166 $(free -m -t)
167
168 = Environment
169 $(env | grep -P 'TEST|TRAVIS|PERL|DBIC' | LC_ALL=C sort | cat -v)
170
171 = Perl in use
172 $(perl -V)
173 ============================================================================="