X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDistar.pm;h=f27036d1d796070010aa4765318a571de61ca9cc;hb=a2c84d6cd7819ab96d06f980cad9da4c9ee1cf88;hp=d5b40b8c9867f0b4a8287d683d7a8f58fb751b3c;hpb=59fcfa653aedcc97b143a0a6bcf73f90733bf862;p=p5sagit%2FDistar.git diff --git a/lib/Distar.pm b/lib/Distar.pm index d5b40b8..f27036d 100644 --- a/lib/Distar.pm +++ b/lib/Distar.pm @@ -1,7 +1,16 @@ 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; our @EXPORT = qw( author manifest_include run_preflight @@ -14,13 +23,15 @@ sub import { sub author { our $Author = shift } +our $Ran_Preflight; + our @Manifest = ( 'lib' => '.pm', 't' => '.t', 't/lib' => '.pm', 'xt' => '.t', 'xt/lib' => '.pm', - '' => '.PL', + '' => qr{[^/]*\.PL}, '' => qr{Changes|MANIFEST|README|META\.yml}, 'maint' => qr{[^.].*}, ); @@ -30,7 +41,6 @@ sub manifest_include { } sub write_manifest_skip { - use autodie; my @files = @Manifest; my @parts; while (my ($dir, $spec) = splice(@files, 0, 2)) { @@ -44,62 +54,102 @@ sub write_manifest_skip { 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; + my $version = $ARGV[0]; + + my $make = $Config{make}; + my $null = File::Spec->devnull; + system("git fetch"); + if (system("git rev-parse --quiet --verify v$version >$null") == 0) { + die "Tag v$version already exists!"; + } + + require File::Find; + File::Find::find({ no_chdir => 1, wanted => sub { + return + unless -f && /\.pm$/; + my $file_version = MM->parse_version($_); + die "Module $_ version $file_version doesn't match dist version $version" + unless $file_version eq 'undef' || $file_version eq $version; + }}, 'lib'); + + for (scalar `"$make" manifest 2>&1 >$null`) { + $_ && die "$make manifest changed:\n$_ Go check it and retry"; + } for (scalar `git status`) { - /Your branch is (behind|ahead of)/ && die "Not synced with upstream"; + /^(?:# )?On branch master/ || die "Not on master. EEEK"; + /Your branch is behind|Your branch and .*? have diverged/ && die "Not synced with upstream"; } for (scalar `git diff`) { - length && die "Oustanding changes"; + length && die "Outstanding changes"; } my $ymd = sprintf( "%i-%02i-%02i", (localtime)[5]+1900, (localtime)[4]+1, (localtime)[3] ); + my $changes_line = "$version - $ymd\n"; 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 > 0 or die "Please add:\n\n$changes_line\nto Changes stage Changes (git add Changes)"; @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 "; + $cached[0] =~ /^\+\+\+ .\/Changes\n/ or die "Changes not changed"; + $cached[1] eq "+$changes_line" or die "Changes new line should be: \n\n$changes_line "; } -sub MY::postamble { <<'END'; } +{ + package Distar::MM; + our @ISA = @ExtUtils::MM::ISA; + @ExtUtils::MM::ISA = (__PACKAGE__); + + sub new { + my ($class, $args) = @_; + return $class->SUPER::new({ + LICENSE => 'perl', + %$args, + AUTHOR => $Distar::Author, + ABSTRACT_FROM => $args->{VERSION_FROM}, + test => { TESTS => ($args->{test}{TESTS}||'t/*.t').' xt/*.t' }, + }); + } + + sub dist_test { + my $self = shift; + my $dist_test = $self->SUPER::dist_test(@_) . <<'END'; + +# --- Distar section: preflight: - perl -Idistar/lib -MDistar -erun_preflight $(VERSION) -upload: preflight $(DISTVNAME).tar$(SUFFIX) - cpan-upload $(DISTVNAME).tar$(SUFFIX) -release: upload + perl -IDistar/lib -MDistar -erun_preflight $(VERSION) +release: preflight + $(MAKE) disttest + rm -rf $(DISTVNAME) + $(MAKE) $(DISTVNAME).tar$(SUFFIX) git commit -a -m "Release commit for $(VERSION)" - git tag release_$(VERSION) - git push - git push --tags + git tag v$(VERSION) -m "release v$(VERSION)" + 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 + $(NOECHO) cd $(DISTVNAME) && $(ABSPERLRUN) ../Distar/helpers/add-readme-to-manifest -{ - 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}||'').' xt/*.t' }, - ); +END + if (open my $fh, '<', 'maint/Makefile.include') { + $dist_test .= do { local $/; <$fh> }; + } + return $dist_test; } } END { - write_manifest_skip() + write_manifest_skip() unless $Ran_Preflight } 1;