*** empty log message ***
[coreutils.git] / announce-gen
blob0c507d4de4636ee22412df4f2f8e8ef982feddd9
1 #!/usr/bin/perl -w
2 # Generate an announcement message.
3 use strict;
5 use Getopt::Long;
6 use Digest::MD5;
7 use Digest::SHA1;
9 (my $VERSION = '$Revision: 1.20 $ ') =~ tr/[0-9].//cd;
10 (my $ME = $0) =~ s|.*/||;
12 my %valid_release_types = map {$_ => 1} qw (alpha beta major);
14 END
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.
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;
27 # Errors closing stdout. Indicate that, and hope stderr is OK.
28 warn "$ME: closing standard output: $!\n";
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().
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;
39 sub usage ($)
41 my ($exit_code) = @_;
42 my $STREAM = ($exit_code == 0 ? *STDOUT : *STDERR);
43 if ($exit_code != 0)
45 print $STREAM "Try `$ME --help' for more information.\n";
47 else
49 my @types = sort keys %valid_release_types;
50 print $STREAM <<EOF;
51 Usage: $ME [OPTIONS]
53 OPTIONS:
55 Generate an announcement message.
57 FIXME: describe the following
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
67 --help display this help and exit
68 --version output version information and exit
70 EOF
72 exit $exit_code;
75 sub print_news_deltas ($$$)
77 my ($news_file, $prev_version, $curr_version) = @_;
79 print "\n$news_file\n\n";
81 # Print all lines from $news_file, starting with the first one
82 # that mentions $curr_version up to but not including
83 # the first occurrence of $prev_version.
84 my $in_items;
86 open NEWS, '<', $news_file
87 or die "$ME: $news_file: cannot open for reading: $!\n";
88 while (defined (my $line = <NEWS>))
90 if ( ! $in_items)
92 # Match lines like this one:
93 # * Major changes in release 5.0.1:
94 # but not any other line that starts with a space, *, or -.
95 $line =~ /^(\* Major changes.*|[^ *-].*)\Q$curr_version\E/o
96 or next;
97 $in_items = 1;
98 print $line;
100 else
102 # Be careful that this regexp cannot match version numbers
103 # in NEWS items -- they might well say `introduced in 4.5.5',
104 # and we don't want that to match.
105 $line =~ /^(\* Major changes.*|[^ *-].*)\Q$prev_version\E/o
106 and last;
107 print $line;
110 close NEWS;
112 $in_items
113 or die "$ME: $news_file: no matching lines for `$curr_version'\n";
116 sub print_changelog_deltas ($$)
118 my ($package_name, $prev_version) = @_;
120 # Print new ChangeLog entries.
122 # First find all CVS-controlled ChangeLog files.
123 use File::Find;
124 my @changelog;
125 find ({wanted => sub {$_ eq 'ChangeLog' && -d 'CVS'
126 and push @changelog, $File::Find::name}},
127 '.');
129 # If there are no ChangeLog files, we're done.
130 @changelog
131 or return;
132 my %changelog = map {$_ => 1} @changelog;
134 # Reorder the list of files so that if there are ChangeLog
135 # files in the specified directories, they're listed first,
136 # in this order:
137 my @dir = qw ( . src lib m4 config doc );
139 # A typical @changelog array might look like this:
140 # ./ChangeLog
141 # ./po/ChangeLog
142 # ./m4/ChangeLog
143 # ./lib/ChangeLog
144 # ./doc/ChangeLog
145 # ./config/ChangeLog
146 my @reordered;
147 foreach my $d (@dir)
149 my $dot_slash = $d eq '.' ? $d : "./$d";
150 my $target = "$dot_slash/ChangeLog";
151 delete $changelog{$target}
152 and push @reordered, $target;
155 # Append any remaining ChangeLog files.
156 push @reordered, sort keys %changelog;
158 # Remove leading `./'.
159 @reordered = map { s!^\./!!; $_ } @reordered;
161 print "\nChangeLog entries:\n\n";
162 # print join ("\n", @reordered), "\n";
164 $prev_version =~ s/\./_/g;
165 my $prev_cvs_tag = "\U$package_name\E-$prev_version";
167 my $cmd = "cvs -n diff -u -r$prev_cvs_tag -rHEAD @reordered";
168 open DIFF, '-|', $cmd
169 or die "$ME: cannot run `$cmd': $!\n";
170 # Print two types of lines, making minor changes:
171 # Lines starting with `+++ ', e.g.,
172 # +++ ChangeLog 22 Feb 2003 16:52:51 -0000 1.247
173 # and those starting with `+'.
174 # Don't print the others.
175 my $prev_printed_line_empty = 1;
176 while (defined (my $line = <DIFF>))
178 if ($line =~ /^\+\+\+ /)
180 my $separator = "*"x70 ."\n";
181 $line =~ s///;
182 $line =~ s/\s.*//;
183 $prev_printed_line_empty
184 or print "\n";
185 print $separator, $line, $separator;
187 elsif ($line =~ /^\+/)
189 $line =~ s///;
190 print $line;
191 $prev_printed_line_empty = ($line =~ /^$/);
194 close DIFF;
196 # The exit code should be 1.
197 # Allow in case there are no modified ChangeLog entries.
198 $? == 256 || $? == 128
199 or warn "$ME: warning: `cmd' had unexpected exit code or signal ($?)\n";
203 my $release_type;
204 my $package_name;
205 my $prev_version;
206 my $curr_version;
207 my $release_archive_dir;
208 my @url_dir_list;
209 my @news_file;
211 GetOptions
213 'release-type=s' => \$release_type,
214 'package-name=s' => \$package_name,
215 'previous-version=s' => \$prev_version,
216 'current-version=s' => \$curr_version,
217 'release-archive-directory=s' => \$release_archive_dir,
218 'url-directory=s' => \@url_dir_list,
219 'news=s' => \@news_file,
221 help => sub { usage 0 },
222 version => sub { print "$ME version $VERSION\n"; exit },
223 ) or usage 1;
225 my $fail = 0;
226 # Ensure that sure each required option is specified.
227 $release_type
228 or (warn "$ME: release type not specified\n"), $fail = 1;
229 $package_name
230 or (warn "$ME: package name not specified\n"), $fail = 1;
231 $prev_version
232 or (warn "$ME: previous version string not specified\n"), $fail = 1;
233 $curr_version
234 or (warn "$ME: current version string not specified\n"), $fail = 1;
235 $release_archive_dir
236 or (warn "$ME: release directory name not specified\n"), $fail = 1;
237 @url_dir_list
238 or (warn "$ME: URL directory name(s) not specified\n"), $fail = 1;
240 exists $valid_release_types{$release_type}
241 or (warn "$ME: `$release_type': invalid release type\n"), $fail = 1;
243 @ARGV
244 and (warn "$ME: too many arguments\n"), $fail = 1;
245 $fail
246 and usage 1;
248 my $my_distdir = "$package_name-$curr_version";
249 my $tgz = "$my_distdir.tar.gz";
250 my $tbz = "$my_distdir.tar.bz2";
251 my $xd = "$package_name-$prev_version-$curr_version.xdelta";
253 my %size;
255 foreach my $f ($tgz, $tbz, $xd)
257 my $cmd = "du --human $f";
258 my $t = `$cmd`;
259 # FIXME-someday: give a better diagnostic, a la $PROCESS_STATUS
261 and (warn "$ME: command failed: `$cmd'\n"), $fail = 1;
262 chomp $t;
263 $t =~ s/^([\d.]+[MkK]).*/${1}B/;
264 $size{$f} = $t;
267 $fail
268 and exit 1;
270 # The markup is escaped as <\# so that when this script is sent by
271 # mail (or part of a diff), Gnus is not triggered.
272 print <<EOF;
274 Subject: $my_distdir released
276 <\#secure method=pgpmime mode=sign>
278 FIXME: put comments here
282 print "Here are the compressed sources:\n";
283 foreach my $url (@url_dir_list)
285 print " $url/$tgz ($size{$tgz})\n";
286 print " $url/$tbz ($size{$tbz})\n";
289 print "\nAnd here are xdelta-style diffs:\n";
290 foreach my $url (@url_dir_list)
292 print " $url/$xd ($size{$xd})\n";
295 print "\nHere are GPG detached signatures:\n";
296 foreach my $url (@url_dir_list)
298 print " $url/$tgz.sig\n";
299 print " $url/$tbz.sig\n";
302 # FIXME: clean up upon interrupt or die
303 my $tmpdir = $ENV{TMPDIR} || '/tmp';
304 my $tmp = "$tmpdir/$ME-$$";
305 unlink $tmp; # ignore failure
307 print "\nHere are the MD5 and SHA1 signatures:\n";
308 print "\n";
309 # The markup is escaped as <\# so that when this script is sent by
310 # mail (or part of a diff), Gnus is not triggered.
311 print "<\#part type=text/plain filename=\"$tmp\" disposition=inline>\n"
312 . "<\#/part>\n";
314 open OUT, '>', $tmp
315 or die "$ME: $tmp: cannot open for writing: $!\n";
317 foreach my $meth (qw (md5 sha1))
319 foreach my $f ($tgz, $tbz, $xd)
321 open IN, '<', $f
322 or die "$ME: $f: cannot open for reading: $!\n";
323 binmode IN;
324 my $dig =
325 ($meth eq 'md5'
326 ? Digest::MD5->new->addfile(*IN)->hexdigest
327 : Digest::SHA1->new->addfile(*IN)->hexdigest);
328 close IN;
329 print OUT "$dig $f\n";
333 close OUT
334 or die "$ME: $tmp: while writing: $!\n";
335 chmod 0400, $tmp; # ignore failure
337 print_news_deltas ($_, $prev_version, $curr_version)
338 foreach @news_file;
340 $release_type eq 'major'
341 or print_changelog_deltas ($package_name, $prev_version);
343 exit 0;
348 ### Setup "GNU" style for perl-mode and cperl-mode.
349 ## Local Variables:
350 ## perl-indent-level: 2
351 ## perl-continued-statement-offset: 2
352 ## perl-continued-brace-offset: 0
353 ## perl-brace-offset: 0
354 ## perl-brace-imaginary-offset: 0
355 ## perl-label-offset: -2
356 ## cperl-indent-level: 2
357 ## cperl-brace-offset: 0
358 ## cperl-continued-brace-offset: 0
359 ## cperl-label-offset: -2
360 ## cperl-extra-newline-before-brace: t
361 ## cperl-merge-trailing-else: nil
362 ## cperl-continued-statement-offset: 2
363 ## End: