package Distar;
-use strictures 1;
+use strict;
+use warnings FATAL => 'all';
use base qw(Exporter);
+use ExtUtils::MakeMaker ();
+use ExtUtils::MM ();
+
+use Config;
+use File::Spec;
+
+our $VERSION = '0.001000';
+$VERSION = eval $VERSION;
+
+my $MM_VER = eval $ExtUtils::MakeMaker::VERSION;
our @EXPORT = qw(
- author manifest_include run_preflight
+ author manifest_include readme_generator
);
sub import {
- strictures->import;
+ strict->import;
+ warnings->import(FATAL => 'all');
shift->export_to_level(1,@_);
}
-sub author { our $Author = shift }
-
-our $Ran_Preflight;
+sub author {
+ our $Author = shift;
+ $Author = [ $Author ]
+ if !ref $Author;
+}
our @Manifest = (
'lib' => '.pm',
+ 'lib' => '.pod',
't' => '.t',
't/lib' => '.pm',
'xt' => '.t',
push @Manifest, @_;
}
+my $readme_generator = <<'README';
+ pod2text $(VERSION_FROM) >$(DISTVNAME)/README
+ $(NOECHO) cd $(DISTVNAME) && $(ABSPERLRUN) ../Distar/helpers/add-readme-to-manifest
+README
+sub readme_generator {
+ $readme_generator = shift;
+}
+
sub write_manifest_skip {
- use autodie;
my @files = @Manifest;
my @parts;
while (my ($dir, $spec) = splice(@files, 0, 2)) {
push @parts, $re;
}
my $final = '^(?!'.join('|', map "${_}\$", @parts).')';
- open my $skip, '>', 'MANIFEST.SKIP';
+ open my $skip, '>', 'MANIFEST.SKIP'
+ or die "can't open MANIFEST.SKIP: $!";
print $skip "${final}\n";
close $skip;
}
-sub run_preflight {
- $Ran_Preflight = 1;
-
- system("git fetch");
-
- for (scalar `make manifest 2>&1 >/dev/null`) {
- $_ && die "make manifest changed:\n$_ Go check it and retry";
+{
+ package Distar::MM;
+ our @ISA = @MM::ISA;
+ @MM::ISA = (__PACKAGE__);
+
+ sub new {
+ my ($class, $args) = @_;
+ return $class->SUPER::new({
+ LICENSE => 'perl_5',
+ MIN_PERL_VERSION => '5.006',
+ AUTHOR => ($MM_VER >= 6.5702 ? $Distar::Author : join(', ', @$Distar::Author)),
+ %$args,
+ ABSTRACT_FROM => $args->{VERSION_FROM},
+ test => { TESTS => ($args->{test}{TESTS}||'t/*.t').' xt/*.t xt/*/*.t' },
+ realclean => { FILES => (
+ ($args->{realclean}{FILES}||'')
+ . ' Distar/ MANIFEST.SKIP MANIFEST MANIFEST.bak'
+ ) },
+ });
}
- for (scalar `git status`) {
- /^# On branch master/ || die "Not on master. EEEK";
- /Your branch is (behind|ahead of)/ && die "Not synced with upstream";
+ sub flush {
+ my $self = shift;
+ Distar::write_manifest_skip();
+ $self->SUPER::flush(@_);
}
- for (scalar `git diff`) {
- length && die "Oustanding changes";
- }
- my $ymd = sprintf(
- "%i-%02i-%02i", (localtime)[5]+1900, (localtime)[4]+1, (localtime)[3]
- );
- my @cached = grep /^\+/, `git diff --cached -U0`;
- @cached > 0 or die "Please add:\n\n$ARGV[0] - $ymd\n\nto Changes and git add";
- @cached == 2 or die "Pre-commit Changes not just Changes line";
- $cached[0] eq "+++ b/Changes\n" or die "Changes not changed";
- $cached[1] eq "+$ARGV[0] - $ymd\n" or die "Changes new line should be: \n\n$ARGV[0] - $ymd\n ";
-}
+ sub dist_test {
+ my $self = shift;
+ my $dist_test = $self->SUPER::dist_test(@_);
+
+ $dist_test .= <<"END";
-sub MY::postamble { <<'END'; }
+# --- Distar section:
+
+REMAKE = \$(PERLRUN) Makefile.PL @{[ map { $self->quote_literal($_) } @ARGV ]}
+
+END
+ $dist_test .= <<'END';
preflight:
- perl -IDistar/lib -MDistar -erun_preflight $(VERSION)
-release: preflight disttest
- rm -rf $(DISTVNAME)
+ $(ABSPERLRUN) Distar/helpers/preflight $(VERSION)
+release: preflight
+ $(MAKE) disttest
+ $(RM_RF) $(DISTVNAME)
$(MAKE) $(DISTVNAME).tar$(SUFFIX)
- cpan-upload $(DISTVNAME).tar$(SUFFIX)
git commit -a -m "Release commit for $(VERSION)"
git tag v$(VERSION) -m "release v$(VERSION)"
- git push --tags
- git push
+ cpan-upload $(DISTVNAME).tar$(SUFFIX)
+ git push origin v$(VERSION) HEAD
distdir: readmefile
readmefile: create_distdir
- pod2text $(VERSION_FROM) >$(DISTVNAME)/README
- $(NOECHO) cd $(DISTVNAME) && $(ABSPERLRUN) -MExtUtils::Manifest=maniadd -e 'eval { maniadd({q{README} => q{README file (added by Distar)}}) } ' \
- -e ' or print "Could not add README to MANIFEST: $${'\''@'\''}\n"' --
+END
+ . $readme_generator . <<'END';
+disttest: distmanicheck
+distmanicheck: create_distdir
+ cd $(DISTVNAME) && $(ABSPERLRUN) "-MExtUtils::Manifest=manicheck" -e "exit manicheck"
+nextrelease:
+ $(ABSPERLRUN) Distar/helpers/add-changelog-heading $(VERSION) Changes
+ git add -p Changes
+refresh:
+ cd Distar && git pull
+ rm Makefile
+ $(REMAKE)
END
-{
- no warnings 'redefine';
- sub main::WriteMakefile {
- my %args = @_;
- ExtUtils::MakeMaker::WriteMakefile(
- LICENSE => 'perl',
- @_, AUTHOR => our $Author, ABSTRACT_FROM => $args{VERSION_FROM},
- test => { TESTS => ($args{test}{TESTS}||'t/*.t').' xt/*.t' },
- );
- }
-}
+ my $include = '';
+ if (open my $fh, '<', 'maint/Makefile.include') {
+ $include = "\n# --- Makefile.include:\n" . do { local $/; <$fh> };
+ }
+
+ for my $type ('', 'minor', 'major') {
+ if ($include !~ /^bump$type:/m) {
+ my $arg = $type || '$(V)';
+ $dist_test .= <<"END"
+bump$type:
+ \$(ABSPERLRUN) Distar/helpers/bump-version --git \$(VERSION) $arg
+ \$(RM_F) \$(FIRST_MAKEFILE)
+ \$(REMAKE)
+END
+ }
+ }
+
+ $dist_test .= $include . "\n";
-END {
- write_manifest_skip() unless $Ran_Preflight
+ return $dist_test;
+ }
}
1;