More tests and tighter code with better error reporting in collapser maker
[dbsrgits/DBIx-Class.git] / Makefile.PL
1 use strict;
2 use warnings;
3
4 use 5.008001;
5 use inc::Module::Install 1.06;
6 BEGIN {
7   # needs to happen early for old EUMM
8   makemaker_args( NORECURS => 1 );
9
10   local @INC = ('lib', @INC);
11   require DBIx::Class::Optional::Dependencies;
12 }
13
14 ##
15 ## DO NOT USE THIS HACK IN YOUR DISTS!!! (it makes #toolchain sad)
16 ##
17 # get cpanX --installdeps . to behave in a checkout (most users do not expect
18 # the deps for a full test suite run, and if they do - there's MI::AutoInstall
19 # for that)
20 BEGIN {
21   $Module::Install::AUTHOR = 0 if (grep { $ENV{"PERL5_${_}_IS_RUNNING"} } (qw/CPANM CPANPLUS CPAN/) );
22 }
23
24 name         'DBIx-Class';
25 version_from 'lib/DBIx/Class.pm';
26 perl_version '5.008001';
27
28 ###
29 ### DO NOT ADD OPTIONAL DEPENDENCIES HERE, EVEN AS recommends()
30 ### All of them *MUST* go to DBIx::Class::Optional::Dependencies
31 ###
32 my $runtime_requires = {
33
34   # DBI itself should be capable of installation and execution in pure-perl
35   # mode. However it has never been tested yet, so consider XS for the time
36   # being
37 ###
38 ### IMPORTANT - do not raise this dependency
39 ### even though many bugfixes are present in newer versions, the general DBIC
40 ### rule is to bend over backwards for available DBI versions (given upgrading
41 ### them is often *not* easy or even possible)
42 ###
43   'DBI'                      => '1.57',
44
45   # on older versions first() leaks
46   # for the time being make it a hard dep - when we get
47   # rid of Sub::Name will revisit this (possibility is
48   # to use Devel::HideXS to force the pure-perl version
49   # or something like that)
50   'List::Util'               => '1.16',
51
52   # XS (or XS-dependent) libs
53   'Sub::Name'                => '0.04',
54
55   # pure-perl (FatPack-able) libs
56   'Class::Accessor::Grouped' => '0.10012',
57   'Class::C3::Componentised' => '1.0009',
58   'Class::Inspector'         => '1.24',
59   'Context::Preserve'        => '0.01',
60   'Data::Page'               => '2.00',
61   'Devel::GlobalDestruction' => '0.09',
62   'Hash::Merge'              => '0.12',
63   'Moo'                      => '2.000',
64   'MRO::Compat'              => '0.12',
65   'Module::Find'             => '0.07',
66   'namespace::clean'         => '0.24',
67   'Scope::Guard'             => '0.03',
68   'SQL::Abstract'            => '1.81',
69   'Try::Tiny'                => '0.07',
70
71   # Technically this is not a core dependency - it is only required
72   # by the MySQL codepath. However this particular version is bundled
73   # since 5.10.0 and is a pure-perl module anyway - let it slide
74   'Text::Balanced'           => '2.00',
75 };
76
77 my $build_requires = {
78 };
79
80 my $test_requires = {
81   'File::Temp'               => '0.22',
82   'Test::Deep'               => '0.101',
83   'Test::Exception'          => '0.31',
84   'Test::Warn'               => '0.21',
85   'Test::More'               => '0.94',
86
87   # this is already a dep of n::c, but just in case - used by t/55namespaces_cleaned.t
88   # remove and do a manual glob-collection if n::c is no longer a dep
89   'Package::Stash'           => '0.28',
90
91   # needed for testing only, not for operation
92   # we will move away from this dep eventually, perhaps to DBD::CSV or something
93   %{ DBIx::Class::Optional::Dependencies->req_list_for('test_rdbms_sqlite') },
94 };
95
96 # if the user has some of these env vars set and the deps are not available,
97 # tests will fail
98 # Note - these are added as test_requires *directly*, so they get properly
99 # excluded on META.yml cleansing (even though no dist can be created from this)
100 # we force these reqs regarless of --with-optdeps, worst case scenario they will
101 # be specified twice
102 #
103 # also note that we *do* set dynamic_config => 0, as these are the only things
104 # that we determine dynamically, and in all fairness if someone sets these
105 # envvars *and* is not running a full Makefile/make/maketest cycle - they get
106 # to keep the pieces
107 if ( my @optdeps = (
108   $ENV{DBICTEST_SQLT_DEPLOY} ? 'deploy' : (),
109   $ENV{DBICTEST_VIA_REPLICATED} ? 'replicated' : (),
110 )) {
111   my $extra_deps = DBIx::Class::Optional::Dependencies->req_list_for(\@optdeps);
112   for (keys %$extra_deps) {
113     test_requires ($_ => $extra_deps->{$_})
114   }
115 }
116
117 tests_recursive ('t');
118 tests_recursive ('xt') if (
119   $Module::Install::AUTHOR
120     or
121   $ENV{DBICTEST_RUN_ALL_TESTS}
122     or
123   ( $ENV{TRAVIS}||'' ) eq 'true'
124     or
125   ( $ENV{AUTOMATED_TESTING} and ! $ENV{PERL5_CPANM_IS_RUNNING} and ! $ENV{RELEASE_TESTING} )
126 );
127
128 install_script (qw|
129     script/dbicadmin
130 |);
131
132 # this is so we can order requires alphabetically
133 # copies are needed for potential author requires injection
134 my $reqs = {
135   build_requires => { %$build_requires },
136   requires => { %$runtime_requires },
137   test_requires => { %$test_requires },
138 };
139
140 # only do author-includes if not part of a `make` run
141 if ($Module::Install::AUTHOR  and ! $ENV{MAKELEVEL}) {
142   invoke_author_mode()
143 }
144 else {
145   # make sure this Makefile can not be used to make a dist
146   # (without the author includes there are no meta cleanup, no sanity checks, etc)
147   postamble <<EOP;
148 create_distdir: nonauthor_stop_distdir_creation
149 nonauthor_stop_distdir_creation:
150 \t\$(NOECHO) \$(ECHO) Creation of dists in non-author mode is not allowed
151 \t\$(NOECHO) \$(FALSE)
152 EOP
153 }
154
155 # compose final req list, for alphabetical ordering
156 my %final_req;
157 for my $rtype (keys %$reqs) {
158   for my $mod (keys %{$reqs->{$rtype}} ) {
159
160     # sanity check req duplications
161     die "$mod specified as both a '$rtype' and a '$final_req{$mod}[0]'\n"
162       if $final_req{$mod};
163
164     $final_req{$mod} = [ $rtype, $reqs->{$rtype}{$mod}||0 ],
165   }
166 }
167
168 # actual require
169 for my $mod (sort keys %final_req) {
170   my ($rtype, $ver) = @{$final_req{$mod}};
171   no strict 'refs';
172   $rtype->($mod, $ver);
173 }
174
175 # author-mode or not - this is where we show a list of missing deps
176 # IFF we are running interactively
177 auto_install();
178
179 {
180   # M::I understands unicode in meta but does not write with the right
181   # layers - fhtagn!!!
182   local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /Wide character in print/ };
183   WriteAll();
184 }
185
186 exit 0;
187
188
189 ###
190 ### Nothing user-serviceable beyond this point
191 ### (none of this executes on regular install)
192 ###
193
194
195 # needs to be here to keep 5.8 string eval happy
196 # (the include of Makefile.PL.inc loop)
197 my $mm_proto;
198
199 sub invoke_author_mode {
200   # get options here, make $args available to all snippets
201   require Getopt::Long;
202   my $getopt = Getopt::Long::Parser->new(
203     config => [qw/gnu_getopt bundling_override no_ignore_case pass_through/]
204   );
205   my $args = {
206     with_optdeps => undef,
207   };
208   $getopt->getoptions($args, qw/
209     with_optdeps|with-optdeps
210   /);
211   if (@ARGV) {
212     warn "\nIgnoring unrecognized option(s): @ARGV\n\n";
213   }
214
215   # We need the MM facilities to generate the pieces for the final MM run.
216   # Just instantiate a throaway object here
217   #
218   # Also EUMM and MI disagree on what is the format of Meta->name, just
219   # punt here until a new M::I is shipped (if at all)
220   my $name = Meta->name || die 'The Module::Install metadata must be available at this point but is not - did you rearrange the Makefile.PL...?';
221   $name =~ s/\-/::/g;
222   $mm_proto = ExtUtils::MakeMaker->new({
223     NORECURS => 1,
224     NAME => $name,
225   });
226
227   # Crutch for DISTBUILDING_IN_HELL
228   # Spits back a working dos2unix snippet to be used on the supplied path(s)
229   # Ironically EUMM's dos2unix is broken on win32 itself - it does
230   # not take into account the CRLF layer present on win32
231   my $crlf_fixup = sub {
232     return '' unless ($^O eq 'MSWin32' or $^O eq 'cygwin');
233     my $targets = join ', ', map { "q($_)" } @_;
234     "\t" . $mm_proto->oneliner( qq(\$ENV{PERLIO}='unix' and system( \$^X, qw( -MExtUtils::Command -e dos2unix -- ), $targets ) ) );
235   };
236
237   # string-eval, not do(), because we need to provide the
238   # $mm_proto, $reqs and $*_requires lexicals to the included file
239   # (some includes *do* modify $reqs above)
240   for my $inc (sort glob ( 'maint/Makefile.PL.inc/*' ) ) {
241     my $src = do { local (@ARGV, $/) = $inc; <> } or die $!;
242     eval "use warnings; use strict; $src" or die sprintf
243       "Failed execution of %s: %s\n",
244       $inc,
245       ($@ || $! || 'Unknown error'),
246     ;
247   }
248 }