X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDistar.pm;h=97dda68e5dbe301b39652aca9cb3aaa8b4518db2;hb=24612483d31a48f26d3a153c560ddcdbcf5af9c3;hp=02db44e8c2064689cc8bb83b61d796b29ad9ac2e;hpb=ee801c0033592e8d3c6d7a5beabc6850a7cf92b8;p=p5sagit%2FDistar.git diff --git a/lib/Distar.pm b/lib/Distar.pm index 02db44e..97dda68 100644 --- a/lib/Distar.pm +++ b/lib/Distar.pm @@ -5,9 +5,10 @@ use base qw(Exporter); use ExtUtils::MakeMaker (); use ExtUtils::MM (); use File::Spec (); +use File::Basename (); -our $VERSION = '0.002000'; -$VERSION = eval $VERSION; +our $VERSION = '0.003000'; +$VERSION =~ tr/_//d; 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,8 +77,6 @@ sub write_manifest_skip { { package Distar::MM; - our @ISA = @MM::ISA; - @MM::ISA = (__PACKAGE__); sub new { my ($class, $args) = @_; @@ -85,7 +88,9 @@ sub write_manifest_skip { return $class->SUPER::new({ LICENSE => 'perl_5', MIN_PERL_VERSION => '5.006', - AUTHOR => ($MM_VER >= 6.5702 ? $Distar::Author : join(', ', @$Distar::Author)), + ($Distar::Author ? ( + AUTHOR => ($MM_VER >= 6.5702 ? $Distar::Author : join(', ', @$Distar::Author)), + ) : ()), (exists $args->{ABSTRACT} ? () : (ABSTRACT_FROM => $args->{VERSION_FROM})), %$args, test => \%test, @@ -128,6 +133,47 @@ sub write_manifest_skip { $targets; } + sub init_dist { + my $self = shift; + my $out = $self->SUPER::init_dist(@_); + + my $dn = File::Spec->devnull; + my $tar = $self->{TAR}; + + my $tarflags = $self->{TARFLAGS}; + if (my ($flags) = $tarflags =~ /^-?([cvhlLf]+)$/) { + if ($flags =~ s/c// && $flags =~ s/f//) { + $tarflags = '--format=ustar -c'.$flags.'f'; + my $me = __FILE__; + for my $options ('--owner=0 --group=0', '--uid=0 --gid=0') { + my $try = `$tar -c $options "$me" 2>$dn`; + if (length $try) { + $tarflags = "$options $tarflags"; + last; + } + } + } + } + + $self->{TAR} = $tar; + $self->{TARFLAGS} = $tarflags; + + $out; + } + + sub libscan { + my $self = shift; + my ($path) = @_; + + # default setup for Distar involves checking it out as a subdirectory at + # the top of the dist. Without NORECURS, EUMM would try to include + # Distar's Makefile.PL. Prevent EUMM from looking inside. + return '' + if $path eq 'Distar'; + + $self->SUPER::libscan(@_); + } + sub tarfile_target { my $self = shift; my $out = $self->SUPER::tarfile_target(@_); @@ -141,41 +187,44 @@ END_FRAG 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 $distar_lib = File::Basename::dirname(__FILE__); + my $helpers = File::Spec->catdir($distar_lib, 'Distar', 'helpers'); - 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 $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)', '-I$(DISTAR)/lib', '-mDistar', '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('', - $dist_test, - "\n\n# --- Distar section:\n\n", - (map "$_ = $vars{$_}\n", sort keys %vars), - <<'END', + my $include = ''; + if (open my $fh, '<', 'maint/Makefile.include') { + $include = do { local $/; <$fh> }; + $include =~ s/\n?\z/\n/; + } + my @out; + + push @out, <<'END'; preflight: check-version check-manifest check-cpan-upload $(ABSPERLRUN) $(HELPERS)/preflight $(VERSION) --changelog=$(CHANGELOG) --branch=$(BRANCH) check-version: @@ -186,10 +235,12 @@ check-cpan-upload: $(NOECHO) cpan-upload -h $(DEV_NULL_STDOUT) releasetest: $(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) @@ -198,31 +249,55 @@ pushrelease :: pushrelease$(FAKE_RELEASE) :: cpan-upload $(DISTVNAME).tar$(SUFFIX) git push origin v$(VERSION) HEAD -distdir: readmefile +distdir: readmefile licensefile readmefile: create_distdir $(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 +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 || $(TRUE) + $(UPDATE_DISTAR) $(RM_F) $(FIRST_MAKEFILE) $(REMAKE) END - map(sprintf(<<'END', "bump$_", ($_ || '$(V)')), @bump_targets), + my @bump_targets = + grep { $include !~ /^bump$_(?: +\w+)*:/m } ('', 'minor', 'major'); + + for my $target (@bump_targets) { + push @out, sprintf <<'END', "bump$target", ($target || '$(V)'); %s: $(ABSPERLRUN) $(HELPERS)/bump-version --git $(VERSION) %s $(RM_F) $(FIRST_MAKEFILE) $(REMAKE) END - $include, + } + + join('', + $dist_test, + "\n\n# --- Distar section:\n\n", + (map "$_ = $vars{$_}\n", sort keys %vars), + "\n", + @out, + ($include ? ( + "\n", + "# --- Makefile.include:\n", + "\n", + $include, + "\n" + ) : ()), "\n", ); }