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