.
[coreutils.git] / announce-gen
blob834d33a6628bce2f169cead87846619330814a91
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.12 $ ') =~ 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_changelog_deltas ($$)
77 my ($package_name, $prev_version) = @_;
79 # Print new ChangeLog entries.
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 '.');
88 # If there are no ChangeLog files, we're done.
89 @changelog
90 or return;
91 my %changelog = map {$_ => 1} @changelog;
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 );
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)
108 my $dot_slash = $d eq '.' ? $d : "./$d";
109 my $target = "$dot_slash/ChangeLog";
110 delete $changelog{$target}
111 and push @reordered, $target;
114 # Append any remaining ChangeLog files.
115 push @reordered, sort keys %changelog;
117 # Remove leading `./'.
118 @reordered = map { s!^\./!!; $_ } @reordered;
120 print "ChangeLog entries:\n\n";
121 # print join ("\n", @reordered), "\n";
123 $prev_version =~ s/\./_/g;
124 my $prev_cvs_tag = "\U$package_name\E-$prev_version";
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 while (defined (my $line = <DIFF>))
136 if ($line =~ /^\+\+\+ /)
138 my $separator = "*"x70 ."\n";
139 $line =~ s///;
140 $line =~ s/\s.*//;
141 print $separator, $line, $separator;
143 elsif ($line =~ /^\+/)
145 $line =~ s///;
146 print $line;
149 close DIFF;
151 # The exit code should be 1.
152 # Allow in case there are no modified ChangeLog entries.
153 $? == 256 || $? == 128
154 or warn "$ME: warning: `cmd' had unexpected exit code or signal ($?)\n";
158 my $release_type;
159 my $package_name;
160 my $prev_version;
161 my $curr_version;
162 my $release_archive_dir;
163 my @url_dir_list;
164 my $news_file;
166 GetOptions
168 'release-type=s' => \$release_type,
169 'package-name=s' => \$package_name,
170 'previous-version=s' => \$prev_version,
171 'current-version=s' => \$curr_version,
172 'release-archive-directory=s' => \$release_archive_dir,
173 'url-directory=s@' => \@url_dir_list,
174 'news=s@' => \$news_file,
176 help => sub { usage 0 },
177 version => sub { print "$ME version $VERSION\n"; exit },
178 ) or usage 1;
180 my $fail = 0;
181 # Ensure that sure each required option is specified.
182 $release_type
183 or (warn "$ME: release type not specified\n"), $fail = 1;
184 $package_name
185 or (warn "$ME: package name not specified\n"), $fail = 1;
186 $prev_version
187 or (warn "$ME: previous version string not specified\n"), $fail = 1;
188 $curr_version
189 or (warn "$ME: current version string not specified\n"), $fail = 1;
190 $release_archive_dir
191 or (warn "$ME: release directory name not specified\n"), $fail = 1;
192 @url_dir_list
193 or (warn "$ME: URL directory name(s) not specified\n"), $fail = 1;
195 exists $valid_release_types{$release_type}
196 or (warn "$ME: `$release_type': invalid release type\n"), $fail = 1;
198 @ARGV
199 and (warn "$ME: too many arguments\n"), $fail = 1;
200 $fail
201 and usage 1;
203 my $my_distdir = "$package_name-$curr_version";
204 my $tgz = "$my_distdir.tar.gz";
205 my $tbz = "$my_distdir.tar.bz2";
206 my $xd = "$package_name-$prev_version-$curr_version.xdelta";
208 my %size;
210 foreach my $f (($tgz, $tbz, $xd))
212 my $cmd = "du --human $f";
213 my $t = `$cmd`;
214 # FIXME-someday: give a better diagnostic, a la $PROCESS_STATUS
216 and (warn "$ME: command failed: `$cmd'\n"), $fail = 1;
217 chomp $t;
218 $t =~ s/^([\d.]+[MkK]).*/${1}B/;
219 $size{$f} = $t;
222 $fail
223 and exit 1;
225 print <<EOF;
227 Subject: $my_distdir released
229 <#secure method=pgpmime mode=sign>
231 FIXME: put comments here
235 print "Here are the compressed sources:\n";
236 foreach my $url (@url_dir_list)
238 print " $url/$tgz ($size{$tgz})\n";
239 print " $url/$tbz ($size{$tbz})\n";
242 print "\nAnd here are xdelta-style diffs:\n";
243 foreach my $url (@url_dir_list)
245 print " $url/$xd ($size{$xd})\n";
248 print "\nHere are GPG detached signatures:\n";
249 foreach my $url (@url_dir_list)
251 print " $url/$tgz.sig\n";
252 print " $url/$tbz.sig\n";
255 # FIXME: clean up upon interrupt or die
256 my $tmpdir = $ENV{TMPDIR} || '/tmp';
257 my $tmp = "$tmpdir/$ME-$$";
258 unlink $tmp; # ignore failure
260 print "\nHere are the MD5 and SHA1 signatures:\n";
261 print "\n";
262 print "<#part type=text/plain filename=\"$tmp\" disposition=inline>\n"
263 . "<#/part>\n";
265 open OUT, '>', $tmp
266 or die "$ME: $tmp: cannot open for writing: $!\n";
268 foreach my $meth (qw (md5 sha1))
270 foreach my $f (($tgz, $tbz, $xd))
272 open IN, '<', $f
273 or die "$ME: $f: cannot open for reading: $!\n";
274 binmode IN;
275 my $dig =
276 ($meth eq 'md5'
277 ? Digest::MD5->new->addfile(*IN)->hexdigest
278 : Digest::SHA1->new->addfile(*IN)->hexdigest);
279 close IN;
280 print OUT "$dig $f\n";
284 close OUT
285 or die "$ME: $tmp: while writing: $!\n";
286 chmod 0400, $tmp; # ignore failure
288 if ($news_file)
290 print "\nNEWS\n\n";
292 # Print all lines from $news_file, starting with the first one
293 # that mentions $curr_version up to but not including
294 # the first occurrence of $prev_version.
295 my $in_items;
296 open NEWS, '<', $news_file
297 or die "$ME: $news_file: cannot open for reading: $!\n";
298 while (defined (my $line = <NEWS>))
300 if ( ! $in_items)
302 $line =~ /^[^ *].*\Q$curr_version\E/o
303 or next;
304 $in_items = 1;
305 print $line;
307 else
309 # Be careful that this regexp cannot match version numbers
310 # in NEWS items -- they might well say `introduced in 4.5.5',
311 # and we don't want that to match.
312 $line =~ /^[^ *].*\Q$prev_version\E/o
313 and last;
314 print $line;
317 close NEWS;
319 $in_items
320 or die "$ME: $news_file: no matching lines\n";
323 $release_type eq 'major'
324 or print_changelog_deltas ($package_name, $prev_version);
326 exit 0;