include full release changelog in nextrelease
[p5sagit/Distar.git] / lib / Distar.pm
CommitLineData
42e08a83 1package Distar;
2
362ec4af 3use strict;
4use warnings FATAL => 'all';
42e08a83 5use base qw(Exporter);
ca3b3b8a 6use ExtUtils::MakeMaker ();
7use ExtUtils::MM ();
42e08a83 8
f6286f60 9our $VERSION = '0.002000';
37e295d8 10$VERSION = eval $VERSION;
11
e076eedb 12my $MM_VER = eval $ExtUtils::MakeMaker::VERSION;
13
42e08a83 14our @EXPORT = qw(
be032607 15 author manifest_include readme_generator
42e08a83 16);
17
18sub import {
2852faf3 19 strict->import;
20 warnings->import(FATAL => 'all');
42e08a83 21 shift->export_to_level(1,@_);
22}
23
e076eedb 24sub author {
25 our $Author = shift;
26 $Author = [ $Author ]
27 if !ref $Author;
28}
42e08a83 29
30our @Manifest = (
31 'lib' => '.pm',
7b9318ce 32 'lib' => '.pod',
42e08a83 33 't' => '.t',
34 't/lib' => '.pm',
35 'xt' => '.t',
36 'xt/lib' => '.pm',
1d950b4a 37 '' => qr{[^/]*\.PL},
f1ef306e 38 '' => qr{Changes|MANIFEST|README|LICENSE|META\.yml},
42e08a83 39 'maint' => qr{[^.].*},
40);
41
42sub manifest_include {
43 push @Manifest, @_;
44}
45
6e83c113 46sub readme_generator {
f6286f60 47 die "readme_generator unsupported" if @_ && $_[0];
6e83c113 48}
49
42e08a83 50sub write_manifest_skip {
42e08a83 51 my @files = @Manifest;
52 my @parts;
53 while (my ($dir, $spec) = splice(@files, 0, 2)) {
54 my $re = ($dir ? $dir.'/' : '').
55 ((ref($spec) eq 'Regexp')
56 ? $spec
57 : !ref($spec)
58 ? ".*\Q${spec}\E"
a3e39afd 59 # print ref as well as stringification in case of overload ""
42e08a83 60 : die "spec must be string or regexp, was: ${spec} (${\ref $spec})");
61 push @parts, $re;
62 }
63 my $final = '^(?!'.join('|', map "${_}\$", @parts).')';
19916679 64 open my $skip, '>', 'MANIFEST.SKIP'
65 or die "can't open MANIFEST.SKIP: $!";
42e08a83 66 print $skip "${final}\n";
67 close $skip;
68}
69
ca3b3b8a 70{
71 package Distar::MM;
9af7ff2e 72 our @ISA = @MM::ISA;
73 @MM::ISA = (__PACKAGE__);
ca3b3b8a 74
75 sub new {
76 my ($class, $args) = @_;
77 return $class->SUPER::new({
180e908e 78 LICENSE => 'perl_5',
53e1282f 79 MIN_PERL_VERSION => '5.006',
0cc25268 80 AUTHOR => ($MM_VER >= 6.5702 ? $Distar::Author : join(', ', @$Distar::Author)),
c12b6d29 81 %$args,
ca3b3b8a 82 ABSTRACT_FROM => $args->{VERSION_FROM},
c194baba 83 test => { TESTS => ($args->{test}{TESTS}||'t/*.t').' xt/*.t xt/*/*.t' },
0a3fdb23 84 realclean => { FILES => (
85 ($args->{realclean}{FILES}||'')
86 . ' Distar/ MANIFEST.SKIP MANIFEST MANIFEST.bak'
87 ) },
ca3b3b8a 88 });
89 }
90
eddb1ce6 91 sub flush {
92 my $self = shift;
93 Distar::write_manifest_skip();
94 $self->SUPER::flush(@_);
95 }
96
ca3b3b8a 97 sub dist_test {
98 my $self = shift;
8ab5ea70 99 my $dist_test = $self->SUPER::dist_test(@_);
100
81d518f6 101 $dist_test .= <<"END";
b0401762 102
ca3b3b8a 103# --- Distar section:
81d518f6 104
105REMAKE = \$(PERLRUN) Makefile.PL @{[ map { $self->quote_literal($_) } @ARGV ]}
106
107END
108 $dist_test .= <<'END';
5154970c 109preflight:
be032607 110 $(ABSPERLRUN) Distar/helpers/preflight $(VERSION)
72932296 111release: preflight
112 $(MAKE) disttest
81d518f6 113 $(RM_RF) $(DISTVNAME)
27dbd26e 114 $(MAKE) $(DISTVNAME).tar$(SUFFIX)
42e08a83 115 git commit -a -m "Release commit for $(VERSION)"
401ece0b 116 git tag v$(VERSION) -m "release v$(VERSION)"
65a1f7d9 117 cpan-upload $(DISTVNAME).tar$(SUFFIX)
2c636792 118 git push origin v$(VERSION) HEAD
5154970c 119distdir: readmefile
f6286f60 120readmefile: create_distdir $(DISTVNAME)/README
121 $(NOECHO) cd $(DISTVNAME) && $(ABSPERLRUN) ../Distar/helpers/add-to-manifest README
122$(DISTVNAME)/README: $(VERSION_FROM)
123 $(NOECHO) $(MKPATH) $(DISTVNAME)
124 pod2text $(VERSION_FROM) >$(DISTVNAME)/README
de048fa8 125disttest: distmanicheck
792c9e91 126distmanicheck: create_distdir
127 cd $(DISTVNAME) && $(ABSPERLRUN) "-MExtUtils::Manifest=manicheck" -e "exit manicheck"
e7a78651 128nextrelease:
129 $(ABSPERLRUN) Distar/helpers/add-changelog-heading $(VERSION) Changes
c1a1a773 130 GIT_DIFF_OPTS=-u`$(ABSPERLRUN) Distar/helpers/changelog-context $(VERSION) Changes` git add -p Changes
0edb27b8 131refresh:
132 cd Distar && git pull
133 rm Makefile
134 $(REMAKE)
8ab5ea70 135END
ca3b3b8a 136
81d518f6 137 my $include = '';
138 if (open my $fh, '<', 'maint/Makefile.include') {
139 $include = "\n# --- Makefile.include:\n" . do { local $/; <$fh> };
140 }
141
8ab5ea70 142 for my $type ('', 'minor', 'major') {
143 if ($include !~ /^bump$type:/m) {
144 my $arg = $type || '$(V)';
145 $dist_test .= <<"END"
146bump$type:
81d518f6 147 \$(ABSPERLRUN) Distar/helpers/bump-version --git \$(VERSION) $arg
148 \$(RM_F) \$(FIRST_MAKEFILE)
ece2756d 149 \$(REMAKE)
42e08a83 150END
8ab5ea70 151 }
a2f6bc7b 152 }
8ab5ea70 153
154 $dist_test .= $include . "\n";
155
ca3b3b8a 156 return $dist_test;
42e08a83 157 }
158}
159
42e08a83 1601;