73cbcebe78d2887edc39c35756732d0e567419b5
[dbsrgits/DBIx-Class.git] / Makefile.PL
1 use inc::Module::Install 1.00;
2 use strict;
3 use warnings;
4
5 use 5.008001;
6
7 use FindBin;
8 use lib "$FindBin::Bin/lib";
9 use DBIx::Class::Optional::Dependencies;
10
11 # adjust ENV for $AUTHOR system() calls
12 use Config;
13 $ENV{PERL5LIB} = join ($Config{path_sep}, @INC);
14
15 use Getopt::Long ();
16
17 my $getopt = Getopt::Long::Parser->new(
18   config => [qw/gnu_getopt bundling_override no_ignore_case pass_through/]
19 );
20 my $args = {
21   skip_author_deps => undef,
22 };
23 $getopt->getoptions($args, 'skip_author_deps');
24 if (@ARGV) {
25   warn "\nIgnoring unrecognized option(s): @ARGV\n\n";
26 }
27
28 # get cpanX --installdeps . to behave in a checkout (most users do not need
29 # the deps for a full test suite run, and if they do - there's MI::AutoInstall
30 # for that)
31 ##
32 ## DO NOT USE THIS HACK IN YOUR DISTS!!! (it makes #toolchain sad)
33 ##
34 $Module::Install::AUTHOR = 0 if (grep { $ENV{"PERL5_${_}_IS_RUNNING"} } (qw/CPANM CPANPLUS CPAN/) );
35
36 ###
37 ### DO NOT ADD OPTIONAL DEPENDENCIES HERE, EVEN AS recommends()
38 ### All of them should go to DBIx::Class::Optional::Dependencies
39 ###
40
41 name     'DBIx-Class';
42 perl_version '5.008001';
43 all_from 'lib/DBIx/Class.pm';
44
45 my $build_requires = {
46   # needed for testing only, not for operation
47   'DBD::SQLite'              => '1.29',
48 };
49
50 my $test_requires = {
51   'File::Temp'               => '0.22',
52   'Test::Builder'            => '0.33',
53   'Test::Exception'          => '0.31',
54   'Test::More'               => '0.92',
55   'Test::Warn'               => '0.21',
56 };
57
58 my $runtime_requires = {
59   'Carp::Clan'               => '6.0',
60   'Class::Accessor::Grouped' => '0.10002',
61   'Class::C3::Componentised' => '1.0005',
62   'Class::Inspector'         => '1.24',
63   'Config::Any'              => '0.20',
64   'Context::Preserve'        => '0.01',
65   'Data::Dumper::Concise'    => '1.000',
66   'Data::Page'               => '2.00',
67   'Hash::Merge'              => '0.12',
68   'MRO::Compat'              => '0.09',
69   'Module::Find'             => '0.06',
70   'Path::Class'              => '0.18',
71   'Scope::Guard'             => '0.03',
72   'SQL::Abstract'            => '1.72',
73   'Try::Tiny'                => '0.04',
74
75   # XS (or XS-dependent) libs
76   'DBI'                      => '1.609',
77   'namespace::clean'         => '0.14',
78   'Sub::Name'                => '0.04',
79   'Variable::Magic'          => '0.44',
80
81   # dual-life corelibs needing a specific bugfixed version
82   'File::Path'               => '2.07',
83 };
84
85 # this is so we can order requires alphabetically
86 # copies are needed for author requires injection
87 my $reqs = {
88   build_requires => { %$build_requires },
89   requires => { %$runtime_requires },
90   test_requires => { %$test_requires },
91 };
92
93 my %reqs_for_group = %{DBIx::Class::Optional::Dependencies->req_group_list};
94
95 # exclude the rdbms_* groups which are for DBIC users
96 my $opt_testdeps = {
97   map { %{$reqs_for_group{$_}} } grep { !/^rdbms_/ } keys %reqs_for_group
98 };
99
100 # require extra modules for testing if we're in a checkout
101 my $optdep_msg;
102 if ($Module::Install::AUTHOR) {
103   if ($args->{skip_author_deps}) {
104     $optdep_msg = <<'EOW';
105
106 ******************************************************************************
107 ******************************************************************************
108 ***                                                                        ***
109 *** IGNORING AUTHOR MODE: no optional test dependencies will be forced.    ***
110 ***                                                                        ***
111 *** If you are using this checkout with the intention of submitting a DBIC ***
112 *** patch, you are *STRONGLY ENCOURAGED* to install all dependencies, so   ***
113 *** that every possible unit-test will run.                                ***
114 ***                                                                        ***
115 ******************************************************************************
116 ******************************************************************************
117
118 EOW
119   }
120   else {
121     $optdep_msg = <<'EOW';
122
123 ******************************************************************************
124 ******************************************************************************
125 ***                                                                        ***
126 *** AUTHOR MODE: all optional test dependencies converted to hard requires ***
127 ***       ( to disable re-run Makefile.PL with --skip_author_deps )        ***
128 ***                                                                        ***
129 ******************************************************************************
130 ******************************************************************************
131
132 EOW
133
134     $reqs->{test_requires} = {
135       %{$reqs->{test_requires}},
136       %$opt_testdeps
137     };
138   }
139 }
140
141 # compose final req list, for alphabetical ordering
142 my %final_req;
143 for my $rtype (keys %$reqs) {
144   for my $mod (keys %{$reqs->{$rtype}} ) {
145
146     # sanity check req duplications
147     if ($final_req{$mod}) {
148       die "$mod specified as both a '$rtype' and a '$final_req{$mod}[0]'\n";
149     }
150
151     $final_req{$mod} = [ $rtype, $reqs->{$rtype}{$mod}||0 ],
152   }
153 }
154
155 # actual require
156 for my $mod (sort keys %final_req) {
157   my ($rtype, $ver) = @{$final_req{$mod}};
158   no strict 'refs';
159   $rtype->($mod, $ver);
160 }
161
162 # output twice since the deplist is > 70 lines
163 warn $optdep_msg if $Module::Install::AUTHOR;
164 auto_install();
165 warn $optdep_msg if $Module::Install::AUTHOR;
166
167 # if this is a smoker, and some known-to-be-trouble reqs are already present
168 # (are not missing reqs) - we can exit 1 now so that we register an N/A report
169 # instead of a FAIL
170 if ($ENV{AUTOMATED_TESTING} && ! $ENV{PERL5_CPANM_IS_RUNNING} && ! $ENV{RELEASE_TESTING}) {
171
172   eval {
173     require Package::Stash;
174     my $psv = Package::Stash->VERSION;
175     if ($psv != 0.13 and $psv >= 0.09 and $psv <= 0.15) {
176       warn "A trial version $psv of Package::Stash detected (known to break namespace::clean). "
177           ."Aborting useless smoke test\n";
178       exit 1;
179     }
180   };
181 }
182
183 # re-create various autogenerated documentation bits
184 if ($Module::Install::AUTHOR) {
185
186   print "Regenerating README\n";
187   system('pod2text lib/DBIx/Class.pm > README');
188
189   if (-f 'MANIFEST') {
190     print "Removing MANIFEST\n";
191     unlink 'MANIFEST';
192   }
193
194   print "Regenerating Optional/Dependencies.pod\n";
195   require DBIx::Class::Optional::Dependencies;
196   DBIx::Class::Optional::Dependencies->_gen_pod (Meta->version);
197
198   # FIXME Disabled due to unsolved issues, ask theorbtwo
199   #  require Module::Install::Pod::Inherit;
200   #  PodInherit();
201 }
202
203
204 tests_recursive (qw|
205     t
206 |);
207
208 # temporary(?) until I get around to fix M::I wrt xt/
209 # needs Module::Install::AuthorTests
210 eval {
211   recursive_author_tests (qw/xt/);
212   1;
213 } || do {
214   if ($Module::Install::AUTHOR && ! $args->{skip_author_deps}) {
215     my $err = $@;
216     eval { require Module::Install::AuthorTests }
217       || die "\nYou need Module::Install::AuthorTests installed to run this Makefile.PL in author mode (or supply --skip_author_deps):\n\n$@\n";
218     die $@;
219   }
220 };
221
222
223 install_script (qw|
224     script/dbicadmin
225 |);
226
227
228 ### Mangle makefile - read the comments for more info
229 #
230 postamble <<"EOP";
231
232 # This will add an extra dep-spec for the distdir target,
233 # which `make` will fold together in a first-come first-serve
234 # fashion. What we do here is essentially adding extra
235 # commands to execute once the distdir is assembled (via
236 # create_distdir), but before control is returned to a higher
237 # calling rule.
238 distdir : dbicadmin_pod_inject
239
240 # The pod self-injection code is in fact a hidden option in
241 # dbicadmin itself
242 dbicadmin_pod_inject :
243 \tcd \$(DISTVNAME) && \$(ABSPERL) -Ilib script/dbicadmin --selfinject-pod
244
245 # Regenerate manifest before running create_distdir.
246 create_distdir : manifest
247
248 EOP
249
250 homepage 'http://www.dbix-class.org/';
251 resources 'IRC'         => 'irc://irc.perl.org/#dbix-class';
252 resources 'license'     => 'http://dev.perl.org/licenses/';
253 resources 'repository'  => 'git://git.shadowcat.co.uk/dbsrgits/DBIx-Class.git';
254 resources 'MailingList' => 'http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class';
255 resources 'bugtracker'  => 'http://rt.cpan.org/NoAuth/Bugs.html?Dist=DBIx-Class';
256
257 # Deprecated/internal modules need no exposure
258 no_index directory => $_ for (qw|
259   lib/DBIx/Class/Admin
260   lib/DBIx/Class/PK/Auto
261   lib/DBIx/Class/CDBICompat
262 |);
263 no_index package => $_ for (qw/
264   DBIx::Class::Storage::DBIHacks
265 /);
266
267 WriteAll();
268
269 # Re-write META.yml to _exclude_ all forced build-requires (we do not want to ship
270 # this) We are also not using M::I::AuthorRequires as this will be an extra dep,
271 # and deps in Makefile.PL still suck
272 # Also always test the result so we stop shipping borked dependency lists to CPAN
273
274 # FIXME test_requires is not yet part of META
275 my %original_build_requires = ( %$build_requires, %$test_requires );
276 my @all_build_requires = @{delete Meta->{values}{build_requires}};
277 my %removed_build_requires;
278
279 for (@all_build_requires) {
280   if ($original_build_requires{$_->[0]}) {
281     push @{Meta->{values}{build_requires}}, $_;
282   }
283   else {
284     $removed_build_requires{$_->[0]} = $_->[1]
285       unless $_->[0] eq 'ExtUtils::MakeMaker';
286   }
287 }
288
289 # Rewrite only in author mode, the original META should not contain anything anyway
290 # if we executed as non-author
291 if ($Module::Install::AUTHOR && keys %removed_build_requires) {
292   print "Regenerating META with author requires excluded\n";
293   Meta->write;
294 }
295
296 # test that we really took things away (just in case, happened twice somehow)
297 if (! -f 'META.yml') {
298   warn "No META.yml generated?! aborting...\n";
299   exit 1;
300 }
301 my $meta = do { local @ARGV = 'META.yml'; local $/; <> };
302
303 # this is safe as there is a fatal check earlier to make sure $opt_testdeps does
304 # not contain any real dependencies
305 my @illegal_leftovers = grep
306   { $meta =~ /^ \s+ \Q$_\E \: \s+ /mx }
307   ( sort keys %$opt_testdeps )
308 ;
309
310 if (@illegal_leftovers) {
311   die join ("\n",
312     "\n\nFATAL FAIL! It looks like some author dependencies made it to the META.yml:\n",
313     map { "\t$_" } @illegal_leftovers
314   ) . "\n\n";
315 }