File::Spec is much better suited for finding /dev/null
[p5sagit/Distar.git] / lib / Distar.pm
CommitLineData
42e08a83 1package Distar;
2
3use strictures 1;
4use base qw(Exporter);
5
ca313d5a 6use Config;
28268771 7use File::Spec;
ca313d5a 8
42e08a83 9our @EXPORT = qw(
5154970c 10 author manifest_include run_preflight
42e08a83 11);
12
13sub import {
14 strictures->import;
15 shift->export_to_level(1,@_);
16}
17
18sub author { our $Author = shift }
19
d7998bfa 20our $Ran_Preflight;
21
42e08a83 22our @Manifest = (
23 'lib' => '.pm',
24 't' => '.t',
25 't/lib' => '.pm',
26 'xt' => '.t',
27 'xt/lib' => '.pm',
1d950b4a 28 '' => qr{[^/]*\.PL},
42e08a83 29 '' => qr{Changes|MANIFEST|README|META\.yml},
42e08a83 30 'maint' => qr{[^.].*},
31);
32
33sub manifest_include {
34 push @Manifest, @_;
35}
36
37sub write_manifest_skip {
38 use autodie;
39 my @files = @Manifest;
40 my @parts;
41 while (my ($dir, $spec) = splice(@files, 0, 2)) {
42 my $re = ($dir ? $dir.'/' : '').
43 ((ref($spec) eq 'Regexp')
44 ? $spec
45 : !ref($spec)
46 ? ".*\Q${spec}\E"
a3e39afd 47 # print ref as well as stringification in case of overload ""
42e08a83 48 : die "spec must be string or regexp, was: ${spec} (${\ref $spec})");
49 push @parts, $re;
50 }
51 my $final = '^(?!'.join('|', map "${_}\$", @parts).')';
52 open my $skip, '>', 'MANIFEST.SKIP';
53 print $skip "${final}\n";
54 close $skip;
55}
56
5154970c 57sub run_preflight {
d7998bfa 58 $Ran_Preflight = 1;
59
5154970c 60 system("git fetch");
61
ca313d5a 62 my $make = $Config{make};
28268771 63 my $null = File::Spec->devnull;
ca313d5a 64
4df609ef 65 for (scalar `"$make" manifest 2>&1 >$null`) {
ca313d5a 66 $_ && die "$make manifest changed:\n$_ Go check it and retry";
41c39fda 67 }
68
5154970c 69 for (scalar `git status`) {
50d3c4ad 70 /^# On branch master/ || die "Not on master. EEEK";
5154970c 71 /Your branch is (behind|ahead of)/ && die "Not synced with upstream";
72 }
73
74 for (scalar `git diff`) {
75 length && die "Oustanding changes";
76 }
5154970c 77 my $ymd = sprintf(
78 "%i-%02i-%02i", (localtime)[5]+1900, (localtime)[4]+1, (localtime)[3]
79 );
59fcfa65 80 my @cached = grep /^\+/, `git diff --cached -U0`;
81 @cached > 0 or die "Please add:\n\n$ARGV[0] - $ymd\n\nto Changes and git add";
82 @cached == 2 or die "Pre-commit Changes not just Changes line";
83 $cached[0] eq "+++ b/Changes\n" or die "Changes not changed";
5154970c 84 $cached[1] eq "+$ARGV[0] - $ymd\n" or die "Changes new line should be: \n\n$ARGV[0] - $ymd\n ";
85}
86
42e08a83 87sub MY::postamble { <<'END'; }
5154970c 88preflight:
584b890c 89 perl -IDistar/lib -MDistar -erun_preflight $(VERSION)
72932296 90release: preflight
91 $(MAKE) disttest
27dbd26e 92 rm -rf $(DISTVNAME)
93 $(MAKE) $(DISTVNAME).tar$(SUFFIX)
5154970c 94 cpan-upload $(DISTVNAME).tar$(SUFFIX)
42e08a83 95 git commit -a -m "Release commit for $(VERSION)"
401ece0b 96 git tag v$(VERSION) -m "release v$(VERSION)"
42e08a83 97 git push --tags
1fcacfb8 98 git push
5154970c 99distdir: readmefile
100readmefile: create_distdir
101 pod2text $(VERSION_FROM) >$(DISTVNAME)/README
046ee554 102 $(NOECHO) cd $(DISTVNAME) && $(ABSPERLRUN) ../Distar/helpers/add-readme-to-manifest
42e08a83 103END
104
105{
106 no warnings 'redefine';
107 sub main::WriteMakefile {
108 my %args = @_;
42e08a83 109 ExtUtils::MakeMaker::WriteMakefile(
2f88acd6 110 LICENSE => 'perl',
42e08a83 111 @_, AUTHOR => our $Author, ABSTRACT_FROM => $args{VERSION_FROM},
281cfaad 112 test => { TESTS => ($args{test}{TESTS}||'t/*.t').' xt/*.t' },
42e08a83 113 );
114 }
115}
116
117END {
d7998bfa 118 write_manifest_skip() unless $Ran_Preflight
42e08a83 119}
120
1211;