X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDistar.pm;h=2efc6d22ed117f153902d029f6a681bc54767c3a;hb=9153428be91f1aa1682937954db85ec23c3e54b2;hp=0aa784a78102ea4c4d0e374997255c650ae63fec;hpb=8aac77fc0d942ece99b96bbeb55e87cbcdf4639c;p=p5sagit%2FDistar.git diff --git a/lib/Distar.pm b/lib/Distar.pm index 0aa784a..2efc6d2 100644 --- a/lib/Distar.pm +++ b/lib/Distar.pm @@ -5,8 +5,9 @@ use base qw(Exporter); use ExtUtils::MakeMaker (); use ExtUtils::MM (); use File::Spec (); +use File::Basename (); -our $VERSION = '0.002000'; +our $VERSION = '0.003000'; $VERSION = eval $VERSION; my $MM_VER = eval $ExtUtils::MakeMaker::VERSION; @@ -18,7 +19,11 @@ our @EXPORT = qw( sub import { strict->import; warnings->import(FATAL => 'all'); - shift->export_to_level(1,@_); + if (!(@MM::ISA == 1 && $MM::ISA[0] eq 'Distar::MM')) { + @Distar::MM::ISA = @MM::ISA; + @MM::ISA = qw(Distar::MM); + } + goto &Exporter::import; } sub author { @@ -72,18 +77,23 @@ sub write_manifest_skip { { package Distar::MM; - our @ISA = @MM::ISA; - @MM::ISA = (__PACKAGE__); sub new { my ($class, $args) = @_; + my %test = %{$args->{test}||{}}; + my $tests = $test{TESTS} || 't/*.t'; + $tests !~ /\b\Q$_\E\b/ and $tests .= " $_" + for 'xt/*.t', 'xt/*/*.t'; + $test{TESTS} = $tests; 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}, + ($Distar::Author ? ( + AUTHOR => ($MM_VER >= 6.5702 ? $Distar::Author : join(', ', @$Distar::Author)), + ) : ()), + (exists $args->{ABSTRACT} ? () : (ABSTRACT_FROM => $args->{VERSION_FROM})), %$args, - test => { TESTS => ($args->{test}{TESTS}||'t/*.t').' xt/*.t xt/*/*.t' }, + test => \%test, realclean => { FILES => ( ($args->{realclean}{FILES}||'') . ' Distar/ MANIFEST.SKIP MANIFEST MANIFEST.bak' @@ -93,7 +103,11 @@ sub write_manifest_skip { sub flush { my $self = shift; - Distar::write_manifest_skip($self); + `git ls-files --error-unmatch MANIFEST.SKIP 2>&1`; + my $maniskip_tracked = !$?; + + Distar::write_manifest_skip($self) + unless $maniskip_tracked; $self->SUPER::flush(@_); } @@ -119,6 +133,79 @@ sub write_manifest_skip { $targets; } + sub init_dist { + my $self = shift; + my $pre_tar = $self->{TAR}; + my $out = $self->SUPER::init_dist(@_); + + my $dn = File::Spec->devnull; + my $tar = $self->{TAR}; + my $gtar; + my $set_user; + for my $maybe_tar ($tar, qw(gtar gnutar)) { + my $version = `$maybe_tar --version 2>$dn`; + if ($version =~ /GNU tar/) { + $tar = $maybe_tar; + $gtar = 1; + last; + } + } + my $tarflags = $self->{TARFLAGS}; + if (my ($flags) = $tarflags =~ /^-?([cvhlLf]+)$/) { + if ($flags =~ s/c// && $flags =~ s/f//) { + $tarflags = '--format=ustar -c'.$flags.'f'; + if ($gtar) { + $tarflags = '--owner=0 --group=0 '.$tarflags; + $set_user = 1; + } + } + } + + if (!$set_user) { + my $warn = ''; + if ($> >= 2**21) { + $warn .= "uid ($>)"; + } + if ($) >= 2**21) { + $warn .= ($warn ? ' and ' : '').'gid('.(0+$)).')'; + } + if ($warn) { + warn "Current $warn too large to create portable dist archives! Max is ".(2**21-1).".\n" + ."Dist creation will most likely fail. Install GNU tar and re-run Makefile.PL to fix this issue.\n"; + my @try; + my $brew = `which brew 2>$dn`; + chomp $brew; + if (-x $brew) { + push @try, 'brew install gnu-tar'; + } + my $ports = `which ports 2>$dn`; + chomp $ports; + if (-x $ports) { + push @try, 'sudo ports install gnutar'; + } + if (@try) { + warn "Try" . (@try > 1 ? ' one of' : '') . ":\n" + . join '', map " $_\n", @try; + } + } + } + + $self->{TAR} = $tar; + $self->{TARFLAGS} = $tarflags; + + $out; + } + + sub tarfile_target { + my $self = shift; + my $out = $self->SUPER::tarfile_target(@_); + my $verify = <<'END_FRAG'; + $(ABSPERLRUN) $(HELPERS)/verify-tarball $(DISTVNAME).tar $(DISTVNAME)/MANIFEST --tar="$(TAR)" +END_FRAG + $out =~ s{(\$\(TAR\).*\n)}{$1$verify}; + $out; + } + sub dist_test { my $self = shift; @@ -131,24 +218,37 @@ sub write_manifest_skip { my @bump_targets = grep { $include !~ /^bump$_(?: +\w+)*:/m } ('', 'minor', 'major'); - my $distar = File::Spec->catdir( - File::Spec->catpath((File::Spec->splitpath(__FILE__))[0,1], ''), - File::Spec->updir, - ); - my $helpers = File::Spec->catdir($distar, 'helpers'); + my $distar_lib = File::Basename::dirname(__FILE__); + my $helpers = File::Spec->catdir($distar_lib, File::Spec->updir, 'helpers'); + + my $licenses = $self->{LICENSE} || $self->{META_ADD}{license} || $self->{META_MERGE}{license}; + my $authors = $self->{AUTHOR}; + $_ = ref $_ ? $_ : [$_ || ()] + for $licenses, $authors; my %vars = ( - DISTAR => $self->quote_literal($distar), + DISTAR_LIB => $self->quote_literal($distar_lib), HELPERS => $self->quote_literal($helpers), - REMAKE => join(' ', '$(PERLRUN)', 'Makefile.PL', map { $self->quote_literal($_) } @ARGV), + REMAKE => join(' ', '$(PERLRUN)', '-I$(DISTAR_LIB)', '-MDistar', 'Makefile.PL', map { $self->quote_literal($_) } @ARGV), BRANCH => $self->{BRANCH} ||= 'master', CHANGELOG => $self->{CHANGELOG} ||= 'Changes', DEV_NULL_STDOUT => ($self->{DEV_NULL} ? '>'.File::Spec->devnull : ''), - FAKE_RELEASE => '', + DISTTEST_MAKEFILE_PARAMS => '', + AUTHORS => $self->quote_literal(join(', ', @$authors)), + LICENSES => join(' ', map $self->quote_literal($_), @$licenses), + GET_CHANGELOG => '$(ABSPERLRUN) $(HELPERS)/get-changelog $(VERSION) $(CHANGELOG)', + UPDATE_DISTAR => ( + -e File::Spec->catdir($distar_lib, File::Spec->updir, '.git') + ? 'git -C $(DISTAR_LIB) pull' + : '$(ECHO) "Distar code is not in a git repo, unable to update!"' + ), ); + my $dist_test = $self->SUPER::dist_test(@_); + $dist_test =~ s/(\bMakefile\.PL\b)/$1 \$(DISTTEST_MAKEFILE_PARAMS)/; + join('', - $self->SUPER::dist_test(@_), + $dist_test, "\n\n# --- Distar section:\n\n", (map "$_ = $vars{$_}\n", sort keys %vars), <<'END', @@ -162,11 +262,13 @@ check-manifest: check-cpan-upload: $(NOECHO) cpan-upload -h $(DEV_NULL_STDOUT) releasetest: - $(MAKE) disttest RELEASE_TESTING=1 PASTHRU="$(PASTHRU) TEST_FILES=\"$(TEST_FILES)\"" + $(MAKE) disttest RELEASE_TESTING=1 DISTTEST_MAKEFILE_PARAMS="PREREQ_FATAL=1" PASTHRU="$(PASTHRU) TEST_FILES=\"$(TEST_FILES)\"" + $(NOECHO) $(TEST_F) $(DISTVNAME)/LICENSE || $(ECHO) "Failed to generate $(DISTVNAME)/LICENSE!" >&2 + $(NOECHO) $(TEST_F) $(DISTVNAME)/LICENSE release: preflight $(MAKE) releasetest - git commit -a -m "Release commit for $(VERSION)" - git tag v$(VERSION) -m "release v$(VERSION)" + $(GET_CHANGELOG) -p"Release commit for $(VERSION)" | git commit -a -F - + $(GET_CHANGELOG) -p"release v$(VERSION)" | git tag -a -F - "v$(VERSION)" $(RM_RF) $(DISTVNAME) $(MAKE) $(DISTVNAME).tar$(SUFFIX) $(NOECHO) $(MAKE) pushrelease FAKE_RELEASE=$(FAKE_RELEASE) @@ -175,23 +277,29 @@ pushrelease :: pushrelease$(FAKE_RELEASE) :: cpan-upload $(DISTVNAME).tar$(SUFFIX) git push origin v$(VERSION) HEAD -distdir: readmefile +distdir: readmefile licensefile readmefile: create_distdir - $(NOECHO) $(MAKE) $(DISTVNAME)/README + $(NOECHO) $(TEST_F) $(DISTVNAME)/README || $(MAKE) $(DISTVNAME)/README $(DISTVNAME)/README: $(VERSION_FROM) $(NOECHO) $(MKPATH) $(DISTVNAME) pod2text $(VERSION_FROM) >$(DISTVNAME)/README $(NOECHO) $(ABSPERLRUN) $(HELPERS)/add-to-manifest -d $(DISTVNAME) README +distsignature: readmefile licensefile +licensefile: create_distdir + $(NOECHO) $(TEST_F) $(DISTVNAME)/LICENSE || $(MAKE) $(DISTVNAME)/LICENSE || $(TRUE) +$(DISTVNAME)/LICENSE: Makefile.PL + $(NOECHO) $(MKPATH) $(DISTVNAME) + $(ABSPERLRUN) $(HELPERS)/generate-license -o $(DISTVNAME)/LICENSE $(AUTHORS) $(LICENSES) + $(NOECHO) $(ABSPERLRUN) $(HELPERS)/add-to-manifest -d $(DISTVNAME) LICENSE disttest: distmanicheck distmanicheck: create_distdir cd $(DISTVNAME) && $(ABSPERLRUN) "-MExtUtils::Manifest=manicheck" -e "exit manicheck" nextrelease: $(ABSPERLRUN) $(HELPERS)/add-changelog-heading --git $(VERSION) $(CHANGELOG) refresh: - cd $(DISTAR) && git pull + $(UPDATE_DISTAR) $(RM_F) $(FIRST_MAKEFILE) $(REMAKE) -$(FIRST_MAKEFILE): $(DISTAR)/lib/Distar.pm END map(sprintf(<<'END', "bump$_", ($_ || '$(V)')), @bump_targets), %s: @@ -217,7 +325,7 @@ Distar - Additions to ExtUtils::MakeMaker for dist authors F: use ExtUtils::MakeMaker; - (do 'maint/Makefile.PL.include' or die $@) unless -f 'META.yml'; + (do './maint/Makefile.PL.include' or die $@) unless -f 'META.yml'; WriteMakefile(...); @@ -242,8 +350,12 @@ make commmands: $ make nextrelease # add version heading to Changes file $ make releasetest # build dist and test (with xt/ and RELEASE_TESTING=1) $ make preflight # check that repo and file state is release ready - $ make release # check releasetest and preflight, then build and - # upload to CPAN, tag release, push tag and branch + $ make release # check releasetest and preflight, commits and tags, + # builds and uploads to CPAN, and pushes commits and + # tag + $ make release FAKE_RELEASE=1 + # builds a release INCLUDING committing and tagging, + # but does not upload to cpan or push anything to git =head1 DESCRIPTION @@ -309,7 +421,7 @@ C and C commands. Releasing will generate a dist tarball and upload it to CPAN using cpan-upload. It will also create a git tag for the release, and push the tag and branch. -=head2 FAKE_RELEASE +=head3 FAKE_RELEASE If release is run with FAKE_RELEASE=1 set, it will skip uploading to CPAN and pushing to git. A release commit will still be created and tagged locally. @@ -353,13 +465,40 @@ change. =head2 bump Bumps the version number. This will try to preserve the length and format of -the version number. The least significant digit will be incremented. +the version number. The least significant digit will be incremented. Versions +with underscores will preserve the underscore in the same position. Optionally accepts a C option to set the version to a specific value. The version changes will automatically be committed. Unstaged modifications to the files will be left untouched. +=head3 V + +The V option will be passed along to the version bumping script. It can accept +a space separated list of options, including an explicit version number. + +Options: + +=over 4 + +=item --force + +Updates version numbers even if they do not match the current expected version +number. + +=item --stable + +Attempts to convert the updated version to a stable version, removing any +underscore. + +=item --alpha + +Attempts to convert the updated version to an alpha version, adding an +underscore in an appropriate place. + +=back + =head2 bumpminor Like bump, but increments the minor segment of the version. This will treat @@ -389,7 +528,7 @@ mst - Matt S. Trout (cpan:MSTROUT) haarg - Graham Knop (cpan:HAARG) -ether = Karen Etheridge (cpan:ETHER) +ether - Karen Etheridge (cpan:ETHER) frew - Arthur Axel "fREW" Schmidt (cpan:FREW)