File: 12_authordeps.pl

package info (click to toggle)
libdbix-class-perl 0.082844-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,320 kB
  • sloc: perl: 27,215; sql: 322; sh: 29; makefile: 16
file content (139 lines) | stat: -rw-r--r-- 4,828 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
my ($optdep_msg, $opt_testdeps);

if ($args->{skip_author_deps}) {
  $optdep_msg = <<'EOW';

******************************************************************************
******************************************************************************
***                                                                        ***
*** IGNORING AUTHOR MODE: no optional test dependencies will be forced.    ***
***                                                                        ***
*** If you are using this checkout with the intention of submitting a DBIC ***
*** patch, you are *STRONGLY ENCOURAGED* to install all dependencies, so   ***
*** that every possible unit-test will run.                                ***
***                                                                        ***
******************************************************************************
******************************************************************************

EOW
}
else {
  $optdep_msg = <<'EOW';

******************************************************************************
******************************************************************************
***                                                                        ***
*** AUTHOR MODE: all optional test dependencies converted to hard requires ***
***       ( to disable re-run Makefile.PL with --skip-author-deps )        ***
***                                                                        ***
******************************************************************************
******************************************************************************

EOW

  require DBIx::Class::Optional::Dependencies;
  my %reqs_for_group = %{DBIx::Class::Optional::Dependencies->req_group_list};

  # exclude the rdbms_* groups which are for DBIC users
  $opt_testdeps = {
    map { %{$reqs_for_group{$_}} } grep { !/^rdbms_|^dist_/ } keys %reqs_for_group
  };

  print "Including all optional deps\n";
  $reqs->{test_requires} = {
    %{$reqs->{test_requires}},
    %$opt_testdeps
  };
}

# nasty hook into both M::AI init and the prompter, so that the optdep message
# comes at the right places (on top and then right above the prompt)
{
  require Module::AutoInstall;
  no warnings 'redefine';
  no strict 'refs';

  for (qw/_prompt import/) {
    my $meth = "Module::AutoInstall::$_";
    my $orig = \&{$meth};
    *{$meth} = sub {
      print $optdep_msg;
      goto $orig;
    };
  }
}

# this will run after the Makefile is written and the main Makefile.PL terminates
#
END {
  # shit already hit the fan
  return if $?;

  # Re-write META.yml at the end to _exclude_ all forced build-requires (we do not
  # want to ship this) We are also not using M::I::AuthorRequires as this will be
  # an extra dep, and deps in Makefile.PL still suck
  # Also always test the result so we stop shipping borked dependency lists to CPAN

  # FIXME test_requires is not yet part of META
  my %original_build_requires = ( %$build_requires, %$test_requires );
  my @all_build_requires = @{delete Meta->{values}{build_requires}||[]};
  my %removed_build_requires;

  for (@all_build_requires) {
    if ($original_build_requires{$_->[0]}) {
      push @{Meta->{values}{build_requires}}, $_;
    }
    else {
      $removed_build_requires{$_->[0]} = $_->[1]
        unless $_->[0] eq 'ExtUtils::MakeMaker';
    }
  }

  if (keys %removed_build_requires) {
    print "Regenerating META with author requires excluded\n";
    # M::I understands unicode in meta but does not write with the right
    # layers - fhtagn!!!
    local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /Wide character in print/ };
    Meta->write;
  }

  # strip possible crlf from META
  if ($^O eq 'MSWin32' or $^O eq 'cygwin') {
    local $ENV{PERLIO} = 'unix';
    system( $^X, qw( -MExtUtils::Command -e dos2unix -- META.yml),  );
  }

  # test that we really took things away (just in case, happened twice somehow)
  if (! -f 'META.yml') {
    warn "No META.yml generated?! aborting...\n";
    unlink 'Makefile';
    exit 1;
  }
  my $meta = do { local @ARGV = 'META.yml'; local $/; <> };

  $meta =~ /^\Qname: DBIx-Class\E$/m or do {
    warn "Seemingly malformed META.yml...?\n";
    unlink 'Makefile';
    exit 1;
  };

  # this is safe as there is a fatal check earlier in the main Makefile.PL
  # to make sure there are no duplicates (i.e. $opt_testdeps does not contain
  # any real dependencies)
  my @illegal_leftovers = grep
    { $meta =~ /^ \s+ \Q$_\E \: \s+ /mx }
    ( sort keys %$opt_testdeps )
  ;

  if (@illegal_leftovers) {
    warn join ("\n",
      "\n\nFATAL FAIL! It looks like some author dependencies made it to the META.yml:\n",
      map { "\t$_" } @illegal_leftovers
    ) . "\n\n";
    unlink 'Makefile';
    exit 1;
  }
}

# keep the Makefile.PL eval happy
1;