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