Commit | Line | Data |
42e08a83 |
1 | package Distar; |
2 | |
3 | use strictures 1; |
4 | use base qw(Exporter); |
5 | |
ca313d5a |
6 | use Config; |
28268771 |
7 | use File::Spec; |
ca313d5a |
8 | |
42e08a83 |
9 | our @EXPORT = qw( |
5154970c |
10 | author manifest_include run_preflight |
42e08a83 |
11 | ); |
12 | |
13 | sub import { |
14 | strictures->import; |
15 | shift->export_to_level(1,@_); |
16 | } |
17 | |
18 | sub author { our $Author = shift } |
19 | |
d7998bfa |
20 | our $Ran_Preflight; |
21 | |
42e08a83 |
22 | our @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 | |
33 | sub manifest_include { |
34 | push @Manifest, @_; |
35 | } |
36 | |
37 | sub 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 |
57 | sub 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"; |
325f6231 |
71 | /Your branch is behind|Your branch and .*? have diverged/ && die "Not synced with upstream"; |
5154970c |
72 | } |
73 | |
74 | for (scalar `git diff`) { |
7374f43f |
75 | length && die "Outstanding changes"; |
5154970c |
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`; |
4477708b |
81 | @cached > 0 or die "Please add:\n\n$ARGV[0] - $ymd\n\nto Changes stage Changes (git add Changes)"; |
59fcfa65 |
82 | @cached == 2 or die "Pre-commit Changes not just Changes line"; |
c373c51b |
83 | $cached[0] =~ /^\+\+\+ .\/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 | |
7ac9c6a6 |
87 | sub MY::postamble { |
b0401762 |
88 | my ($self, %extra) = @_; |
89 | |
a2f6bc7b |
90 | my $post = <<'END'; |
5154970c |
91 | preflight: |
584b890c |
92 | perl -IDistar/lib -MDistar -erun_preflight $(VERSION) |
72932296 |
93 | release: preflight |
94 | $(MAKE) disttest |
27dbd26e |
95 | rm -rf $(DISTVNAME) |
96 | $(MAKE) $(DISTVNAME).tar$(SUFFIX) |
42e08a83 |
97 | git commit -a -m "Release commit for $(VERSION)" |
401ece0b |
98 | git tag v$(VERSION) -m "release v$(VERSION)" |
65a1f7d9 |
99 | cpan-upload $(DISTVNAME).tar$(SUFFIX) |
452dfa09 |
100 | git push origin --tags HEAD |
5154970c |
101 | distdir: readmefile |
102 | readmefile: create_distdir |
103 | pod2text $(VERSION_FROM) >$(DISTVNAME)/README |
046ee554 |
104 | $(NOECHO) cd $(DISTVNAME) && $(ABSPERLRUN) ../Distar/helpers/add-readme-to-manifest |
42e08a83 |
105 | END |
a2f6bc7b |
106 | if (open my $fh, '<', 'maint/Makefile.include') { |
107 | $post .= do { local $/; <$fh> }; |
108 | } |
dfee3207 |
109 | |
110 | # add on any extra args that WriteMakefile chose to pass us |
111 | # (note that Devel::Declare, and possibly others, use this) |
b0401762 |
112 | $post .= "\n" . join('', %extra) if keys %extra; |
dfee3207 |
113 | |
a2f6bc7b |
114 | return $post; |
7ac9c6a6 |
115 | } |
42e08a83 |
116 | |
117 | { |
118 | no warnings 'redefine'; |
119 | sub main::WriteMakefile { |
120 | my %args = @_; |
42e08a83 |
121 | ExtUtils::MakeMaker::WriteMakefile( |
2f88acd6 |
122 | LICENSE => 'perl', |
42e08a83 |
123 | @_, AUTHOR => our $Author, ABSTRACT_FROM => $args{VERSION_FROM}, |
281cfaad |
124 | test => { TESTS => ($args{test}{TESTS}||'t/*.t').' xt/*.t' }, |
42e08a83 |
125 | ); |
126 | } |
127 | } |
128 | |
129 | END { |
d7998bfa |
130 | write_manifest_skip() unless $Ran_Preflight |
42e08a83 |
131 | } |
132 | |
133 | 1; |