(travis) Attempt to revert 86370cc74, SC is too slow on uptake. Grumble
[dbsrgits/DBIx-Class.git] / maint / travis-ci_scripts / 20_install.bash
1 #!/bin/bash
2
3 source maint/travis-ci_scripts/common.bash
4 if [[ -n "$SHORT_CIRCUIT_SMOKE" ]] ; then return ; fi
5
6 CPAN_MIRROR=$(echo "$PERL_CPANM_OPT" | grep -oP -- '--mirror\s+\S+' | head -n 1 | cut -d ' ' -f 2)
7 if ! [[ "$CPAN_MIRROR" =~ "http://" ]] ; then
8   echo_err "Unable to extract primary cpan mirror from PERL_CPANM_OPT - something is wrong"
9   echo_err "PERL_CPANM_OPT: $PERL_CPANM_OPT"
10   CPAN_MIRROR="http://cpan.metacpan.org/"
11   PERL_CPANM_OPT="$PERL_CPANM_OPT --mirror $CPAN_MIRROR"
12   echo_err "Using $CPAN_MIRROR for the time being"
13 fi
14
15 # do not set PERLBREW_CPAN_MIRROR - not all backpan-like mirrors have the perl tarballs
16 export PERL_MM_USE_DEFAULT=1 PERL_MM_NONINTERACTIVE=1 PERL_AUTOINSTALL_PREFER_CPAN=1 HARNESS_TIMER=1 MAKEFLAGS="-j$NUMTHREADS"
17
18 # try CPAN's latest offering if requested
19 if [[ "$DEVREL_DEPS" == "true" ]] ; then
20
21   PERL_CPANM_OPT="$PERL_CPANM_OPT --dev"
22
23   # FIXME inline-upgrade cpanm, work around https://github.com/travis-ci/travis-ci/issues/1477
24   cpanm_loc="$(which cpanm)"
25   run_or_err "Upgrading cpanm ($cpanm_loc) to latest stable" \
26     "wget -q -O $cpanm_loc cpanmin.us && chmod a+x $cpanm_loc"
27 fi
28
29 # Fixup CPANM_OPT to behave more like a traditional cpan client
30 export PERL_CPANM_OPT="--verbose --no-interactive --no-man-pages $( echo $PERL_CPANM_OPT | sed 's/--skip-satisfied//' )"
31
32 if [[ -n "$BREWVER" ]] ; then
33   # since perl 5.14 a perl can safely be built concurrently with -j$large
34   # (according to brute force testing and my power bill)
35   if [[ "$BREWVER" == "blead" ]] || perl -Mversion -e "exit !!(version->new(q($BREWVER)) < 5.014)" ; then
36     perlbrew_jopt="$NUMTHREADS"
37   fi
38
39   run_or_err "Compiling/installing Perl $BREWVER (without testing, using ${perlbrew_jopt:-1} threads, may take up to 5 minutes)" \
40     "perlbrew install --as $BREWVER --notest --noman --verbose $BREWOPTS -j${perlbrew_jopt:-1}  $BREWVER"
41
42   # can not do 'perlbrew uss' in the run_or_err subshell above, or a $()
43   # furthermore `perlbrew use` returns 0 regardless of whether the perl is
44   # found (won't be there unless compilation suceeded, wich *ALSO* returns 0)
45   perlbrew use $BREWVER
46
47   if [[ "$( perlbrew use | grep -oP '(?<=Currently using ).+' )" != "$BREWVER" ]] ; then
48     echo_err "Unable to switch to $BREWVER - compilation failed...?"
49     echo_err "$LASTOUT"
50     exit 1
51   fi
52
53 # no brewver - this means a travis perl, which means we want to clean up
54 # the presently installed libs
55 # Idea stolen from
56 # https://github.com/kentfredric/Dist-Zilla-Plugin-Prereqs-MatchInstalled-All/blob/master/maint-travis-ci/sterilize_env.pl
57 elif [[ "$CLEANTEST" == "true" ]] && [[ "$POISON_ENV" != "true" ]] ; then
58
59   echo_err "$(tstamp) Cleaning precompiled Travis-Perl"
60   perl -MConfig -MFile::Find -e '
61     my $sitedirs = {
62       map { $Config{$_} => 1 }
63         grep { $_ =~ /site(lib|arch)exp$/ }
64           keys %Config
65     };
66     find({ bydepth => 1, no_chdir => 1, follow_fast => 1, wanted => sub {
67       ! $sitedirs->{$_} and ( -d _ ? rmdir : unlink )
68     } }, keys %$sitedirs )
69   '
70
71   echo_err "Post-cleanup contents of sitelib of the pre-compiled Travis-Perl $TRAVIS_PERL_VERSION:"
72   echo_err "$(tree $(perl -MConfig -e 'print $Config{sitelib_stem}'))"
73   echo_err
74 fi
75
76 # configure CPAN.pm - older versions go into an endless loop
77 # when trying to autoconf themselves
78 CPAN_CFG_SCRIPT="
79   require CPAN;
80   require CPAN::FirstTime;
81   *CPAN::FirstTime::conf_sites = sub {};
82   CPAN::Config->load;
83   \$CPAN::Config->{urllist} = [qw{ $CPAN_MIRROR }];
84   \$CPAN::Config->{halt_on_failure} = 1;
85   CPAN::Config->commit;
86 "
87 run_or_err "Configuring CPAN.pm" "perl -e '$CPAN_CFG_SCRIPT'"