X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDistar.pm;h=804f684daaa499d9a3603553e7b5569f326a2a21;hb=66a2ecde04b7004b20253b7a777ffbc8997c5504;hp=c58915065968d8ce7454d499c8b213c1d6d342da;hpb=5154970c57b68f91b9c82f3e671a3c64d55609e8;p=p5sagit%2FDistar.git diff --git a/lib/Distar.pm b/lib/Distar.pm index c589150..804f684 100644 --- a/lib/Distar.pm +++ b/lib/Distar.pm @@ -1,27 +1,40 @@ package Distar; - -use strictures 1; +use strict; +use warnings FATAL => 'all'; use base qw(Exporter); +use ExtUtils::MakeMaker (); +use ExtUtils::MM (); + +our $VERSION = '0.002000'; +$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 } +sub author { + our $Author = shift; + $Author = [ $Author ] + if !ref $Author; +} our @Manifest = ( 'lib' => '.pm', + 'lib' => '.pod', 't' => '.t', 't/lib' => '.pm', 'xt' => '.t', 'xt/lib' => '.pm', - '' => '.PL', - '' => qr{Changes|MANIFEST|README|META\.yml}, + '' => qr{[^/]*\.PL}, + '' => qr{Changes|MANIFEST|README|LICENSE|META\.yml}, 'maint' => qr{[^.].*}, ); @@ -29,8 +42,12 @@ sub manifest_include { push @Manifest, @_; } +sub readme_generator { + die "readme_generator unsupported" if @_ && $_[0]; +} + sub write_manifest_skip { - use autodie; + my ($mm) = @_; my @files = @Manifest; my @parts; while (my ($dir, $spec) = splice(@files, 0, 2)) { @@ -39,62 +56,125 @@ sub write_manifest_skip { ? $spec : !ref($spec) ? ".*\Q${spec}\E" + # print ref as well as stringification in case of overload "" : die "spec must be string or regexp, was: ${spec} (${\ref $spec})"); push @parts, $re; } - my $final = '^(?!'.join('|', map "${_}\$", @parts).')'; - open my $skip, '>', 'MANIFEST.SKIP'; + my $dist_name = $mm->{DISTNAME}; + my $include = join '|', map "${_}\$", @parts; + my $final = "^(?:\Q$dist_name\E-v?[0-9_.]+/|(?!$include))"; + open my $skip, '>', 'MANIFEST.SKIP' + or die "can't open MANIFEST.SKIP: $!"; print $skip "${final}\n"; close $skip; } -sub run_preflight { - system("git fetch"); +{ + package Distar::MM; + our @ISA = @MM::ISA; + @MM::ISA = (__PACKAGE__); - for (scalar `git status`) { - /Your branch is (behind|ahead of)/ && die "Not synced with upstream"; + 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)), + ABSTRACT_FROM => $args->{VERSION_FROM}, + %$args, + 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 diff`) { - length && die "Oustanding changes"; + sub flush { + my $self = shift; + Distar::write_manifest_skip($self); + $self->SUPER::flush(@_); } - my @cached = grep /^\+/, `git diff --cached -U0`; - @cached == 2 or die "Pre-commit Changes not just Changes line"; - $cached[0] eq "+++ b/Changes\n" or die "Changes not changed"; - my $ymd = sprintf( - "%i-%02i-%02i", (localtime)[5]+1900, (localtime)[4]+1, (localtime)[3] - ); - $cached[1] eq "+$ARGV[0] - $ymd\n" or die "Changes new line should be: \n\n$ARGV[0] - $ymd\n "; -} -sub MY::postamble { <<'END'; } + sub special_targets { + my $self = shift; + my $targets = $self->SUPER::special_targets(@_); + my $phony_targets = join ' ', qw( + preflight + releasetest + release + readmefile + distmanicheck + nextrelease + refresh + bump + bumpmajor + bumpminor + ); + $targets =~ s/^(\.PHONY *:.*)/$1 $phony_targets/m; + $targets; + } + + sub dist_test { + my $self = shift; + + my $include = ''; + if (open my $fh, '<', 'maint/Makefile.include') { + $include = "\n# --- Makefile.include:\n\n" . do { local $/; <$fh> }; + $include =~ s/\n?\z/\n/; + } + + my @bump_targets = + grep { $include !~ /^bump$_(?: +\w+)*:/m } ('', 'minor', 'major'); + + my %vars = ( + REMAKE => join(' ', '$(PERLRUN)', 'Makefile.PL', map { $self->quote_literal($_) } @ARGV), + ); + + join('', + $self->SUPER::dist_test(@_), + "\n\n# --- Distar section:\n\n", + (map "$_ = $vars{$_}\n", sort keys %vars), + <<'END', + preflight: - perl -Idistar/lib -MDistar -erun_preflight $(VERSION) -upload: preflight disttest $(DISTVNAME).tar$(SUFFIX) - cpan-upload $(DISTVNAME).tar$(SUFFIX) -release: upload + $(ABSPERLRUN) Distar/helpers/preflight $(VERSION) +releasetest: + $(MAKE) disttest RELEASE_TESTING=1 PASTHRU="$(PASTHRU) TEST_FILES=\"$(TEST_FILES)\"" +release: preflight releasetest + $(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 +readmefile: create_distdir $(DISTVNAME)/README + $(NOECHO) cd $(DISTVNAME) && $(ABSPERLRUN) ../Distar/helpers/add-to-manifest README +$(DISTVNAME)/README: $(VERSION_FROM) + $(NOECHO) $(MKPATH) $(DISTVNAME) pod2text $(VERSION_FROM) >$(DISTVNAME)/README +disttest: distmanicheck +distmanicheck: create_distdir + cd $(DISTVNAME) && $(ABSPERLRUN) "-MExtUtils::Manifest=manicheck" -e "exit manicheck" +nextrelease: + $(ABSPERLRUN) Distar/helpers/add-changelog-heading $(VERSION) Changes + GIT_DIFF_OPTS=-u`$(ABSPERLRUN) Distar/helpers/changelog-context $(VERSION) Changes` git add -p Changes +refresh: + cd Distar && git pull + $(RM_F) $(FIRST_MAKEFILE) + $(REMAKE) END - -{ - no warnings 'redefine'; - sub main::WriteMakefile { - my %args = @_; - ExtUtils::MakeMaker::WriteMakefile( - @_, AUTHOR => our $Author, ABSTRACT_FROM => $args{VERSION_FROM}, - test => { TESTS => ($args{test}{TESTS}||'').' xt/*.t' }, + map(sprintf(<<'END', "bump$_", ($_ || '$(V)')), @bump_targets), +%s: + $(ABSPERLRUN) Distar/helpers/bump-version --git $(VERSION) %s + $(RM_F) $(FIRST_MAKEFILE) + $(REMAKE) +END + $include, + "\n", ); } } -END { - write_manifest_skip() -} - 1;