move preflight to separate script
[p5sagit/Distar.git] / lib / Distar.pm
index 0fa8961..08c6046 100644 (file)
@@ -15,7 +15,7 @@ $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 {
@@ -30,8 +30,6 @@ sub author {
     if !ref $Author;
 }
 
-our $Ran_Preflight;
-
 our @Manifest = (
   'lib' => '.pm',
   'lib' => '.pod',
@@ -48,7 +46,7 @@ sub manifest_include {
   push @Manifest, @_;
 }
 
-my $readme_generator = <<README;
+my $readme_generator = <<'README';
        pod2text $(VERSION_FROM) >$(DISTVNAME)/README
        $(NOECHO) cd $(DISTVNAME) && $(ABSPERLRUN) ../Distar/helpers/add-readme-to-manifest
 README
@@ -76,77 +74,48 @@ sub write_manifest_skip {
   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`) {
-    /^(?:# )?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]),
+      AUTHOR => ($MM_VER >= 6.5702 ? $Distar::Author : join(', ', @$Distar::Author)),
       %$args,
       ABSTRACT_FROM => $args->{VERSION_FROM},
       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();
+    $self->SUPER::flush(@_);
+  }
+
   sub dist_test {
     my $self = shift;
-    my $dist_test = $self->SUPER::dist_test(@_) . <<'END'
+    my $dist_test = $self->SUPER::dist_test(@_);
+
+    my $include = '';
+    if (open my $fh, '<', 'maint/Makefile.include') {
+      $include = "\n# --- Makefile.include:\n" . do { local $/; <$fh> };
+    }
+
+    $dist_test .= "REMAKE = \$(PERLRUN) Makefile.PL @{[ map { $self->quote_literal($_) } @ARGV ]}";
+    $dist_test .= <<'END'
 
 # --- Distar section:
 preflight:
-       perl -IDistar/lib -MDistar -erun_preflight $(VERSION)
+       $(ABSPERLRUN) Distar/helpers/preflight $(VERSION)
 release: preflight
        $(MAKE) disttest
        rm -rf $(DISTVNAME)
@@ -162,17 +131,31 @@ END
 disttest: distmanicheck
 distmanicheck: create_distdir
        cd $(DISTVNAME) && $(ABSPERLRUN) "-MExtUtils::Manifest=manicheck" -e "exit manicheck"
+nextrelease:
+       $(ABSPERLRUN) Distar/helpers/add-changelog-heading $(VERSION) Changes
+       git add -p Changes
+refresh:
+       cd Distar && git pull
+       rm Makefile
+       $(REMAKE)
+END
 
+    for my $type ('', 'minor', 'major') {
+      if ($include !~ /^bump$type:/m) {
+        my $arg = $type || '$(V)';
+        $dist_test .= <<"END"
+bump$type:
+       Distar/helpers/bump-version --git \$(VERSION) $arg
+       rm Makefile
+       \$(REMAKE)
 END
-    if (open my $fh, '<', 'maint/Makefile.include') {
-      $dist_test .= do { local $/; <$fh> };
+      }
     }
+
+    $dist_test .= $include . "\n";
+
     return $dist_test;
   }
 }
 
-END {
-  write_manifest_skip() unless $Ran_Preflight
-}
-
 1;