X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDistar.pm;h=8e1c51d3fdb358ff4962ca099c7567e4e983de13;hb=9b920c5cd3611f36624ec9eb87f5ef822e0fe465;hp=dc43ad051a9e7136197ea73723d0072ef57b23a6;hpb=eddb1ce69b879b31fcacd6e59fa33269fad340b5;p=p5sagit%2FDistar.git diff --git a/lib/Distar.pm b/lib/Distar.pm index dc43ad0..8e1c51d 100644 --- a/lib/Distar.pm +++ b/lib/Distar.pm @@ -1,21 +1,17 @@ package Distar; - 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'; +our $VERSION = '0.002000'; $VERSION = eval $VERSION; my $MM_VER = eval $ExtUtils::MakeMaker::VERSION; our @EXPORT = qw( - author manifest_include readme_generator run_preflight + author manifest_include readme_generator ); sub import { @@ -38,7 +34,7 @@ our @Manifest = ( 'xt' => '.t', 'xt/lib' => '.pm', '' => qr{[^/]*\.PL}, - '' => qr{Changes|MANIFEST|README|META\.yml}, + '' => qr{Changes|MANIFEST|README|LICENSE|META\.yml}, 'maint' => qr{[^.].*}, ); @@ -46,15 +42,12 @@ sub manifest_include { 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; + die "readme_generator unsupported" if @_ && $_[0]; } sub write_manifest_skip { + my ($mm) = @_; my @files = @Manifest; my @parts; while (my ($dir, $spec) = splice(@files, 0, 2)) { @@ -67,110 +60,121 @@ sub write_manifest_skip { : die "spec must be string or regexp, was: ${spec} (${\ref $spec})"); push @parts, $re; } - my $final = '^(?!'.join('|', map "${_}\$", @parts).')'; + 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 { - 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`) { - /^(?:# )?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 "Outstanding changes"; - } - my $ymd = sprintf( - "%i-%02i-%02i", (gmtime)[5]+1900, (gmtime)[4]+1, (gmtime)[3] - ); - my $changes_line = "$version - $ymd\n"; - my @cached = grep /^\+/, `git diff --cached -U0`; - @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] =~ /^\+\+\+ .\/Changes\n/ or die "Changes not changed"; - $cached[1] eq "+$changes_line" or die "Changes new line should be: \n\n$changes_line "; - - { no warnings 'exec'; `cpan-upload -h`; } - $? and die "cpan-upload not available"; -} - { package Distar::MM; - our @ISA = @ExtUtils::MM::ISA; - @ExtUtils::MM::ISA = (__PACKAGE__); + 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 : $Distar::Author->[0]), - %$args, + 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' + ) }, }); } sub flush { my $self = shift; - Distar::write_manifest_skip(); + Distar::write_manifest_skip($self); $self->SUPER::flush(@_); } + 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 $dist_test = $self->SUPER::dist_test(@_) . <<'END' -# --- Distar section: + 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), + BRANCH => $self->{BRANCH} ||= 'master', + CHANGELOG => $self->{CHANGELOG} ||= 'Changes', + ); + + 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) -release: preflight - $(MAKE) disttest - rm -rf $(DISTVNAME) + $(ABSPERLRUN) Distar/helpers/preflight $(VERSION) --changelog=$(CHANGELOG) --branch=$(BRANCH) +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 v$(VERSION) -m "release v$(VERSION)" cpan-upload $(DISTVNAME).tar$(SUFFIX) git push origin v$(VERSION) HEAD distdir: readmefile -readmefile: create_distdir -END - . $readme_generator . <<'END'; +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 --git $(VERSION) $(CHANGELOG) +refresh: + cd Distar && git pull + $(RM_F) $(FIRST_MAKEFILE) + $(REMAKE) END - if (open my $fh, '<', 'maint/Makefile.include') { - $dist_test .= do { local $/; <$fh> }; - } - return $dist_test; + map(sprintf(<<'END', "bump$_", ($_ || '$(V)')), @bump_targets), +%s: + $(ABSPERLRUN) Distar/helpers/bump-version --git $(VERSION) %s + $(RM_F) $(FIRST_MAKEFILE) + $(REMAKE) +END + $include, + "\n", + ); } }