]> git.saurik.com Git - bison.git/blame - config/announce-gen
* config/announce-gen, Makefile.cfg: New.
[bison.git] / config / announce-gen
CommitLineData
603f1cfd
AD
1#!/usr/bin/perl -w
2# Generate an announcement message.
3use strict;
4
5use Getopt::Long;
6use Digest::MD5;
7use Digest::SHA1;
8
9(my $VERSION = '$Revision$ ') =~ tr/[0-9].//cd;
10(my $ME = $0) =~ s|.*/||;
11
12my %valid_release_types = map {$_ => 1} qw (alpha beta major);
13
14END
15{
16 # Nobody ever checks the status of print()s. That's okay, because
17 # if any do fail, we're guaranteed to get an indicator when we close()
18 # the filehandle.
19 #
20 # Close stdout now, and if there were no errors, return happy status.
21 # If stdout has already been closed by the script, though, do nothing.
22 defined fileno STDOUT
23 or return;
24 close STDOUT
25 and return;
26
27 # Errors closing stdout. Indicate that, and hope stderr is OK.
28 warn "$ME: closing standard output: $!\n";
29
30 # Don't be so arrogant as to assume that we're the first END handler
31 # defined, and thus the last one invoked. There may be others yet
32 # to come. $? will be passed on to them, and to the final _exit().
33 #
34 # If it isn't already an error, make it one (and if it _is_ an error,
35 # preserve the value: it might be important).
36 $? ||= 1;
37}
38
39sub usage ($)
40{
41 my ($exit_code) = @_;
42 my $STREAM = ($exit_code == 0 ? *STDOUT : *STDERR);
43 if ($exit_code != 0)
44 {
45 print $STREAM "Try `$ME --help' for more information.\n";
46 }
47 else
48 {
49 my @types = sort keys %valid_release_types;
50 print $STREAM <<EOF;
51Usage: $ME [OPTIONS]
52
53OPTIONS:
54
55 Generate an announcement message.
56
57 FIXME: describe the following
58
59 --release-type=TYPE TYPE must be one of @types
60 --package-name=PACKAGE_NAME
61 --previous-version=VER
62 --current-version=VER
63 --release-archive-directory=DIR
64 --url-directory=URL_DIR
65 --news=NEWS_FILE optional
66
67 --help display this help and exit
68 --version output version information and exit
69
70EOF
71 }
72 exit $exit_code;
73}
74
75sub print_changelog_deltas ($$)
76{
77 my ($package_name, $prev_version) = @_;
78
79 # Print new ChangeLog entries.
80
81 # First find all CVS-controlled ChangeLog files.
82 use File::Find;
83 my @changelog;
84 find ({wanted => sub {$_ eq 'ChangeLog' && -d 'CVS'
85 and push @changelog, $File::Find::name}},
86 '.');
87
88 # If there are no ChangeLog files, we're done.
89 @changelog
90 or return;
91 my %changelog = map {$_ => 1} @changelog;
92
93 # Reorder the list of files so that if there are ChangeLog
94 # files in the specified directories, they're listed first,
95 # in this order:
96 my @dir = qw ( . src lib m4 config doc );
97
98 # A typical @changelog array might look like this:
99 # ./ChangeLog
100 # ./po/ChangeLog
101 # ./m4/ChangeLog
102 # ./lib/ChangeLog
103 # ./doc/ChangeLog
104 # ./config/ChangeLog
105 my @reordered;
106 foreach my $d (@dir)
107 {
108 my $dot_slash = $d eq '.' ? $d : "./$d";
109 my $target = "$dot_slash/ChangeLog";
110 delete $changelog{$target}
111 and push @reordered, $target;
112 }
113
114 # Append any remaining ChangeLog files.
115 push @reordered, sort keys %changelog;
116
117 # Remove leading `./'.
118 @reordered = map { s!^\./!!; $_ } @reordered;
119
120 print "\nChangeLog entries:\n\n";
121 # print join ("\n", @reordered), "\n";
122
123 $prev_version =~ s/\./_/g;
124 my $prev_cvs_tag = "\U$package_name\E-$prev_version";
125
126 my $cmd = "cvs -n diff -u -r$prev_cvs_tag -rHEAD @reordered";
127 open DIFF, '-|', $cmd
128 or die "$ME: cannot run `$cmd': $!\n";
129 # Print two types of lines, making minor changes:
130 # Lines starting with `+++ ', e.g.,
131 # +++ ChangeLog 22 Feb 2003 16:52:51 -0000 1.247
132 # and those starting with `+'.
133 # Don't print the others.
134 my $prev_printed_line_empty = 1;
135 while (defined (my $line = <DIFF>))
136 {
137 if ($line =~ /^\+\+\+ /)
138 {
139 my $separator = "*"x70 ."\n";
140 $line =~ s///;
141 $line =~ s/\s.*//;
142 $prev_printed_line_empty
143 or print "\n";
144 print $separator, $line, $separator;
145 }
146 elsif ($line =~ /^\+/)
147 {
148 $line =~ s///;
149 print $line;
150 $prev_printed_line_empty = ($line =~ /^$/);
151 }
152 }
153 close DIFF;
154
155 # The exit code should be 1.
156 # Allow in case there are no modified ChangeLog entries.
157 $? == 256 || $? == 128
158 or warn "$ME: warning: `cmd' had unexpected exit code or signal ($?)\n";
159}
160
161{
162 my $release_type;
163 my $package_name;
164 my $prev_version;
165 my $curr_version;
166 my $release_archive_dir;
167 my @url_dir_list;
168 my $news_file;
169
170 GetOptions
171 (
172 'release-type=s' => \$release_type,
173 'package-name=s' => \$package_name,
174 'previous-version=s' => \$prev_version,
175 'current-version=s' => \$curr_version,
176 'release-archive-directory=s' => \$release_archive_dir,
177 'url-directory=s@' => \@url_dir_list,
178 'news=s@' => \$news_file,
179
180 help => sub { usage 0 },
181 version => sub { print "$ME version $VERSION\n"; exit },
182 ) or usage 1;
183
184 my $fail = 0;
185 # Ensure that sure each required option is specified.
186 $release_type
187 or (warn "$ME: release type not specified\n"), $fail = 1;
188 $package_name
189 or (warn "$ME: package name not specified\n"), $fail = 1;
190 $prev_version
191 or (warn "$ME: previous version string not specified\n"), $fail = 1;
192 $curr_version
193 or (warn "$ME: current version string not specified\n"), $fail = 1;
194 $release_archive_dir
195 or (warn "$ME: release directory name not specified\n"), $fail = 1;
196 @url_dir_list
197 or (warn "$ME: URL directory name(s) not specified\n"), $fail = 1;
198
199 exists $valid_release_types{$release_type}
200 or (warn "$ME: `$release_type': invalid release type\n"), $fail = 1;
201
202 @ARGV
203 and (warn "$ME: too many arguments\n"), $fail = 1;
204 $fail
205 and usage 1;
206
207 my $my_distdir = "$package_name-$curr_version";
208 my $tgz = "$my_distdir.tar.gz";
209 my $tbz = "$my_distdir.tar.bz2";
210 my $xd = "$package_name-$prev_version-$curr_version.xdelta";
211
212 my %size;
213
214 foreach my $f (($tgz, $tbz, $xd))
215 {
216 my $cmd = "du --human $f";
217 my $t = `$cmd`;
218 # FIXME-someday: give a better diagnostic, a la $PROCESS_STATUS
219 $@
220 and (warn "$ME: command failed: `$cmd'\n"), $fail = 1;
221 chomp $t;
222 $t =~ s/^([\d.]+[MkK]).*/${1}B/;
223 $size{$f} = $t;
224 }
225
226 $fail
227 and exit 1;
228
229 print <<EOF;
230
231Subject: $my_distdir released
232
233<#secure method=pgpmime mode=sign>
234
235FIXME: put comments here
236
237EOF
238
239 print "Here are the compressed sources:\n";
240 foreach my $url (@url_dir_list)
241 {
242 print " $url/$tgz ($size{$tgz})\n";
243 print " $url/$tbz ($size{$tbz})\n";
244 }
245
246 print "\nAnd here are xdelta-style diffs:\n";
247 foreach my $url (@url_dir_list)
248 {
249 print " $url/$xd ($size{$xd})\n";
250 }
251
252 print "\nHere are GPG detached signatures:\n";
253 foreach my $url (@url_dir_list)
254 {
255 print " $url/$tgz.asc\n";
256 print " $url/$tbz.asc\n";
257 }
258
259 # FIXME: clean up upon interrupt or die
260 my $tmpdir = $ENV{TMPDIR} || '/tmp';
261 my $tmp = "$tmpdir/$ME-$$";
262 unlink $tmp; # ignore failure
263
264 print "\nHere are the MD5 and SHA1 signatures:\n";
265 print "\n";
266 print "<#part type=text/plain filename=\"$tmp\" disposition=inline>\n"
267 . "<#/part>\n";
268
269 open OUT, '>', $tmp
270 or die "$ME: $tmp: cannot open for writing: $!\n";
271
272 foreach my $meth (qw (md5 sha1))
273 {
274 foreach my $f (($tgz, $tbz, $xd))
275 {
276 open IN, '<', $f
277 or die "$ME: $f: cannot open for reading: $!\n";
278 binmode IN;
279 my $dig =
280 ($meth eq 'md5'
281 ? Digest::MD5->new->addfile(*IN)->hexdigest
282 : Digest::SHA1->new->addfile(*IN)->hexdigest);
283 close IN;
284 print OUT "$dig $f\n";
285 }
286 }
287
288 close OUT
289 or die "$ME: $tmp: while writing: $!\n";
290 chmod 0400, $tmp; # ignore failure
291
292 if ($news_file)
293 {
294 print "\nNEWS\n\n";
295
296 # Print all lines from $news_file, starting with the first one
297 # that mentions $curr_version up to but not including
298 # the first occurrence of $prev_version.
299 my $in_items;
300 open NEWS, '<', $news_file
301 or die "$ME: $news_file: cannot open for reading: $!\n";
302 while (defined (my $line = <NEWS>))
303 {
304 if ( ! $in_items)
305 {
306 # Match lines like this one:
307 # * Major changes in release 5.0.1:
308 # but not any other line that starts with a space, *, or -.
309 $line =~ /^(\* Major changes.*|[^ *-].*)\Q$curr_version\E/o
310 or next;
311 $in_items = 1;
312 print $line;
313 }
314 else
315 {
316 # Be careful that this regexp cannot match version numbers
317 # in NEWS items -- they might well say `introduced in 4.5.5',
318 # and we don't want that to match.
319 $line =~ /^(\* Major changes.*|[^ *-].*)\Q$prev_version\E/o
320 and last;
321 print $line;
322 }
323 }
324 close NEWS;
325
326 $in_items
327 or die "$ME: $news_file: no matching lines for `$curr_version'\n";
328 }
329
330 $release_type eq 'major'
331 or print_changelog_deltas ($package_name, $prev_version);
332
333 exit 0;
334}