Commit | Line | Data |
---|---|---|
da2ead5e ES |
1 | ####################################################################### |
2 | # $URL$ | |
3 | # $Date$ | |
4 | # $Author$ | |
5 | # $Revision$ | |
6 | ######################################################################## | |
7 | ||
8 | package Perl::Critic::Module::Build; | |
9 | ||
10 | use 5.006001; | |
11 | ||
12 | use strict; | |
13 | use warnings; | |
46f91981 | 14 | |
9b6b3b02 | 15 | our $VERSION = '1.105_01'; |
46f91981 | 16 | |
8a8ef23d ES |
17 | use Carp; |
18 | use English qw< $OS_ERROR $EXECUTABLE_NAME -no_match_vars >; | |
b005b12c | 19 | use Perl::Critic::PolicySummaryGenerator qw< generate_policy_summary >; |
0a630832 | 20 | |
da2ead5e ES |
21 | use base 'Module::Build'; |
22 | ||
23 | ||
da2ead5e ES |
24 | sub ACTION_authortest { |
25 | my ($self) = @_; | |
26 | ||
506d38ff ES |
27 | $self->_authortest_dependencies(); |
28 | $self->depends_on('test'); | |
da2ead5e | 29 | |
506d38ff ES |
30 | return; |
31 | } | |
da2ead5e | 32 | |
8a8ef23d | 33 | |
506d38ff ES |
34 | sub ACTION_authortestcover { |
35 | my ($self) = @_; | |
36 | ||
37 | $self->_authortest_dependencies(); | |
38 | $self->depends_on('testcover'); | |
da2ead5e ES |
39 | |
40 | return; | |
41 | } | |
42 | ||
8a8ef23d | 43 | |
b005b12c ES |
44 | sub ACTION_policysummary { |
45 | my ($self) = @_; | |
46 | ||
47 | my $policy_summary_file = generate_policy_summary(); | |
48 | $self->add_to_cleanup( $policy_summary_file ); | |
49 | ||
50 | return; | |
51 | } | |
52 | ||
53 | ||
da2ead5e | 54 | sub ACTION_distdir { |
cc277542 | 55 | my ($self, @arguments) = @_; |
da2ead5e ES |
56 | |
57 | $self->depends_on('authortest'); | |
58 | ||
cc277542 | 59 | return $self->SUPER::ACTION_distdir(@arguments); |
da2ead5e ES |
60 | } |
61 | ||
8a8ef23d ES |
62 | |
63 | sub ACTION_nytprof { | |
64 | my ($self) = @_; | |
b005b12c | 65 | |
8a8ef23d ES |
66 | $self->depends_on('build'); |
67 | $self->_run_nytprof(); | |
b005b12c | 68 | |
8a8ef23d ES |
69 | return; |
70 | } | |
71 | ||
72 | ||
0a630832 ES |
73 | sub ACTION_manifest { |
74 | my ($self, @arguments) = @_; | |
75 | ||
76 | if (-e 'MANIFEST') { | |
77 | unlink 'MANIFEST' or die "Can't unlink MANIFEST: $OS_ERROR"; | |
78 | } | |
79 | ||
80 | return $self->SUPER::ACTION_manifest(@arguments); | |
81 | } | |
82 | ||
da2ead5e | 83 | |
0b1167d5 ES |
84 | sub tap_harness_args { |
85 | my ($self) = @_; | |
86 | return $self->_tap_harness_args() if $ENV{RUNNING_UNDER_TEAMCITY}; | |
87 | return; | |
88 | } | |
89 | ||
90 | ||
91 | sub _tap_harness_args { | |
92 | return {formatter_class => 'TAP::Formatter::TeamCity', merge => 1}; | |
93 | } | |
94 | ||
95 | ||
506d38ff ES |
96 | sub _authortest_dependencies { |
97 | my ($self) = @_; | |
98 | ||
99 | $self->depends_on('build'); | |
b005b12c | 100 | $self->depends_on('policysummary'); |
b6682bc3 | 101 | $self->depends_on('manifest'); |
506d38ff ES |
102 | $self->depends_on('distmeta'); |
103 | ||
104 | $self->test_files( qw< t xt/author > ); | |
105 | $self->recursive_test_files(1); | |
106 | ||
107 | return; | |
108 | } | |
109 | ||
110 | ||
8a8ef23d ES |
111 | sub _run_nytprof { |
112 | my ($self) = @_; | |
113 | ||
114 | ||
115 | eval {require Devel::NYTProf} | |
116 | or croak 'Devel::NYTProf is required to run nytprof'; | |
117 | ||
118 | eval {require File::Which; File::Which->import('which'); 1} | |
119 | or croak 'File::Which is required to run nytprof'; | |
120 | ||
121 | my $nytprofhtml = which('nytprofhtml') | |
122 | or croak 'Could not find nytprofhtml in your PATH'; | |
123 | ||
124 | my $this_perl = $EXECUTABLE_NAME; | |
125 | my @perl_args = qw(-Iblib/lib -d:NYTProf blib/script/perlcritic); | |
126 | my @perlcritic_args = qw(-noprofile -severity=1 -theme=core -exclude=TidyCode -exclude=PodSpelling blib); | |
127 | warn join q{ }, 'Running:', $this_perl, @perl_args, @perlcritic_args, "\n"; | |
128 | ||
129 | my $status_perlcritic = system $this_perl, @perl_args, @perlcritic_args; | |
130 | croak "perlcritic failed with status $status_perlcritic" if $status_perlcritic == 1; | |
131 | ||
132 | my $status_nytprofhtml = system $nytprofhtml; | |
133 | croak "nytprofhtml failed with status $status_nytprofhtml" if $status_nytprofhtml; | |
134 | ||
135 | return; | |
136 | } | |
137 | ||
b005b12c | 138 | |
da2ead5e ES |
139 | 1; |
140 | ||
141 | ||
142 | __END__ | |
143 | ||
144 | #----------------------------------------------------------------------------- | |
145 | ||
146 | =pod | |
147 | ||
148 | =for stopwords | |
149 | ||
150 | =head1 NAME | |
151 | ||
152 | Perl::Critic::Module::Build - Customization of L<Module::Build> for L<Perl::Critic>. | |
153 | ||
154 | ||
155 | =head1 DESCRIPTION | |
156 | ||
157 | This is a custom subclass of L<Module::Build> that enhances existing | |
158 | functionality and adds more for the benefit of installing and | |
b005b12c ES |
159 | developing L<Perl::Critic>. The following actions have been added |
160 | or redefined: | |
da2ead5e ES |
161 | |
162 | ||
b005b12c | 163 | =head1 ACTIONS |
da2ead5e ES |
164 | |
165 | =over | |
166 | ||
b005b12c | 167 | =item test |
da2ead5e ES |
168 | |
169 | In addition to the standard action, this adds a dependency upon the | |
170 | C<manifest> action. | |
171 | ||
172 | ||
b005b12c | 173 | =item authortest |
da2ead5e ES |
174 | |
175 | Runs the regular tests plus the author tests (those in F<xt/author>). | |
176 | It used to be the case that author tests were run if an environment | |
177 | variable was set or if a F<.svn> directory existed. What ended up | |
178 | happening was that people that had that environment variable set for | |
179 | other purposes or who had done a checkout of the code repository would | |
180 | run those tests, which would fail, and we'd get bug reports for | |
181 | something not expected to run elsewhere. Now, you've got to | |
182 | explicitly ask for the author tests to be run. | |
183 | ||
184 | ||
b005b12c | 185 | =item authortestcover |
506d38ff ES |
186 | |
187 | As C<authortest> is to the standard C<test> action, C<authortestcover> | |
188 | is to the standard C<testcover> action. | |
189 | ||
190 | ||
b005b12c | 191 | =item distdir |
da2ead5e ES |
192 | |
193 | In addition to the standard action, this adds a dependency upon the | |
194 | C<authortest> action so you can't do a release without passing the | |
195 | author tests. | |
196 | ||
b005b12c ES |
197 | |
198 | =item policysummary | |
199 | ||
200 | Generates the F<PolicySummary.pod> file. This should only be used by | |
201 | C<Perl::Critic> developers. This action is also invoked by the C<authortest> | |
202 | action, so the F<PolicySummary.pod> file will be generated whenever you create | |
203 | a distribution with the C<dist> or C<distdir> targets. | |
204 | ||
205 | ||
206 | =item nytprof | |
8a8ef23d ES |
207 | |
208 | Runs perlcritic under the L<Devel::NYTProf> profiler and generates | |
209 | an HTML report in F<nytprof/index.html>. | |
210 | ||
da2ead5e ES |
211 | |
212 | =back | |
213 | ||
214 | ||
215 | =head1 AUTHOR | |
216 | ||
217 | Elliot Shank <perl@galumph.com> | |
218 | ||
219 | =head1 COPYRIGHT | |
220 | ||
072692c8 | 221 | Copyright (c) 2007-2010 Elliot Shank. All rights reserved. |
da2ead5e ES |
222 | |
223 | This program is free software; you can redistribute it and/or modify | |
224 | it under the same terms as Perl itself. The full text of this license | |
225 | can be found in the LICENSE file included with this module. | |
226 | ||
227 | =cut | |
228 | ||
229 | ||
230 | ############################################################################## | |
231 | # Local Variables: | |
232 | # mode: cperl | |
233 | # cperl-indent-level: 4 | |
234 | # fill-column: 78 | |
235 | # indent-tabs-mode: nil | |
236 | # c-indentation-style: bsd | |
237 | # End: | |
238 | # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |