Rewrite optdeps to accept a list of groups
[dbsrgits/DBIx-Class.git] / maint / Makefile.PL.inc / 12_authordeps.pl
CommitLineData
fc4b0448 1my ($optdep_msg, $opt_testdeps);
2
3if ($args->{skip_author_deps}) {
4 $optdep_msg = <<'EOW';
5
6******************************************************************************
7******************************************************************************
8*** ***
9*** IGNORING AUTHOR MODE: no optional test dependencies will be forced. ***
10*** ***
11*** If you are using this checkout with the intention of submitting a DBIC ***
12*** patch, you are *STRONGLY ENCOURAGED* to install all dependencies, so ***
13*** that every possible unit-test will run. ***
14*** ***
15******************************************************************************
16******************************************************************************
17
18EOW
19}
20else {
21 $optdep_msg = <<'EOW';
22
23******************************************************************************
24******************************************************************************
25*** ***
26*** AUTHOR MODE: all optional test dependencies converted to hard requires ***
df65d4da 27*** ( to disable re-run Makefile.PL with --skip-author-deps ) ***
fc4b0448 28*** ***
29******************************************************************************
30******************************************************************************
31
32EOW
33
34 require DBIx::Class::Optional::Dependencies;
fc4b0448 35
36 # exclude the rdbms_* groups which are for DBIC users
4841171c 37 # and the moose-related stuff iff we are under 5.8.3
31c31b8d 38 $opt_testdeps = DBIx::Class::Optional::Dependencies->req_list_for([
39 grep {
4841171c 40 !/^rdbms_|^dist_/
41 and
42 ($] > 5.008002 or !/^ (?: test_ )? (?: admin | admin_script | replicated ) $/x )
31c31b8d 43 } keys %{DBIx::Class::Optional::Dependencies->req_group_list}
44 ]);
fc4b0448 45
46 print "Including all optional deps\n";
47 $reqs->{test_requires} = {
48 %{$reqs->{test_requires}},
49 %$opt_testdeps
50 };
51}
52
53# nasty hook into both M::AI init and the prompter, so that the optdep message
54# comes at the right places (on top and then right above the prompt)
55{
56 require Module::AutoInstall;
57 no warnings 'redefine';
58 no strict 'refs';
59
60 for (qw/_prompt import/) {
61 my $meth = "Module::AutoInstall::$_";
62 my $orig = \&{$meth};
63 *{$meth} = sub {
64 print $optdep_msg;
65 goto $orig;
66 };
67 }
68}
69
70# this will run after the Makefile is written and the main Makefile.PL terminates
71#
72END {
745b54f5 73 # shit already hit the fan
74 return if $?;
75
fc4b0448 76 # Re-write META.yml at the end to _exclude_ all forced build-requires (we do not
77 # want to ship this) We are also not using M::I::AuthorRequires as this will be
78 # an extra dep, and deps in Makefile.PL still suck
79 # Also always test the result so we stop shipping borked dependency lists to CPAN
80
81 # FIXME test_requires is not yet part of META
82 my %original_build_requires = ( %$build_requires, %$test_requires );
83 my @all_build_requires = @{delete Meta->{values}{build_requires}||[]};
84 my %removed_build_requires;
85
86 for (@all_build_requires) {
87 if ($original_build_requires{$_->[0]}) {
88 push @{Meta->{values}{build_requires}}, $_;
89 }
90 else {
91 $removed_build_requires{$_->[0]} = $_->[1]
92 unless $_->[0] eq 'ExtUtils::MakeMaker';
93 }
94 }
95
96 if (keys %removed_build_requires) {
97 print "Regenerating META with author requires excluded\n";
3440100b 98 # M::I understands unicode in meta but does not write with the right
99 # layers - fhtagn!!!
100 local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /Wide character in print/ };
fc4b0448 101 Meta->write;
102 }
103
204f57da 104 # strip possible crlf from META
105 if ($^O eq 'MSWin32' or $^O eq 'cygwin') {
106 local $ENV{PERLIO} = 'unix';
107 system( $^X, qw( -MExtUtils::Command -e dos2unix -- META.yml), );
108 }
109
fc4b0448 110 # test that we really took things away (just in case, happened twice somehow)
111 if (! -f 'META.yml') {
112 warn "No META.yml generated?! aborting...\n";
113 unlink 'Makefile';
114 exit 1;
115 }
116 my $meta = do { local @ARGV = 'META.yml'; local $/; <> };
117
90d4cbcc 118 $meta =~ /^\Qname: DBIx-Class\E$/m or do {
119 warn "Seemingly malformed META.yml...?\n";
120 unlink 'Makefile';
121 exit 1;
122 };
123
fc4b0448 124 # this is safe as there is a fatal check earlier in the main Makefile.PL
65a231a8 125 # to make sure there are no duplicates (i.e. $opt_testdeps does not contain
fc4b0448 126 # any real dependencies)
127 my @illegal_leftovers = grep
128 { $meta =~ /^ \s+ \Q$_\E \: \s+ /mx }
129 ( sort keys %$opt_testdeps )
130 ;
131
132 if (@illegal_leftovers) {
133 warn join ("\n",
134 "\n\nFATAL FAIL! It looks like some author dependencies made it to the META.yml:\n",
135 map { "\t$_" } @illegal_leftovers
136 ) . "\n\n";
137 unlink 'Makefile';
138 exit 1;
139 }
140}
141
142# keep the Makefile.PL eval happy
1431;