Changed the commands used to "make gen" without any stoppage.
[rsync/rsync.git] / packaging / release-rsync
... / ...
CommitLineData
1#!/usr/bin/perl
2use strict;
3use warnings;
4
5# This script expects the directory ~/samba-rsync-ftp to exist and to be a
6# copy of the /home/ftp/pub/rsync dir on samba.org. When the script is done,
7# the git repository in the current directory will be updated, and the local
8# ~/samba-rsync-ftp dir will be ready to be rsynced to samba.org.
9
10use Cwd;
11use Getopt::Long;
12use Term::ReadKey;
13use Date::Format;
14
15my $dest = $ENV{HOME} . '/samba-rsync-ftp';
16my $passfile = $ENV{HOME} . '/.rsyncpass';
17my $path = $ENV{PATH};
18my $make_gen_cmd = 'make -f prepare-source.mak conf && ./config.status && make gen';
19
20&Getopt::Long::Configure('bundling');
21&usage if !&GetOptions(
22 'branch|b=s' => \( my $master_branch = 'master' ),
23 'help|h' => \( my $help_opt ),
24);
25&usage if $help_opt;
26
27my $now = time;
28my $cl_today = time2str('* %a %b %d %Y', $now);
29my $year = time2str('%Y', $now);
30my $ztoday = time2str('%d %b %Y', $now);
31(my $today = $ztoday) =~ s/^0//;
32
33my $curdir = Cwd::cwd;
34
35END {
36 unlink($passfile);
37}
38
39my @extra_files;
40open(IN, '<', 'Makefile.in') or die "Couldn't open Makefile.in: $!\n";
41while (<IN>) {
42 if (s/^GENFILES=//) {
43 while (s/\\$//) {
44 $_ .= <IN>;
45 }
46 @extra_files = split(' ', $_);
47 last;
48 }
49}
50close IN;
51
52my $break = <<EOT;
53==========================================================================
54EOT
55
56print $break, <<EOT, $break, "\n";
57== This will release a new version of rsync onto an unsuspecting world. ==
58EOT
59
60die "$dest does not exist\n" unless -d $dest;
61die "There is no .git dir in the current directory.\n" unless -d '.git';
62die "'a' must not exist in the current directory.\n" if -e 'a';
63die "'b' must not exist in the current directory.\n" if -e 'b';
64
65open(IN, '-|', 'git status') or die $!;
66my $status = join('', <IN>);
67close IN;
68die "The checkout is not clean:\n", $status unless $status =~ /\nnothing to commit \(working directory clean\)/;
69my($cur_branch) = $status =~ /^# On branch (.+)\n/;
70if ($cur_branch ne $master_branch) {
71 print "The checkout is not on the $master_branch branch.\n";
72 exit 1 if $master_branch ne 'master';
73 print "Do you want to release branch $cur_branch? [n] ";
74 $_ = <STDIN>;
75 exit 1 unless /^y/i;
76 $master_branch = $cur_branch;
77}
78
79my $confversion;
80open(IN, '<', 'configure.in') or die $!;
81while (<IN>) {
82 if (/^RSYNC_VERSION=(.*)/) {
83 $confversion = $1;
84 last;
85 }
86}
87close IN;
88die "Unable to find RSYNC_VERSION in configure.in\n" unless defined $confversion;
89
90open(IN, '<', 'OLDNEWS') or die $!;
91$_ = <IN>;
92my($lastversion) = /(\d+\.\d+\.\d+)/;
93my($last_protocol_version, %pdate);
94while (<IN>) {
95 if (my($ver,$pdate,$pver) = /^\s+\S\S\s\S\S\S\s\d\d\d\d\s+(\d+\.\d+\.\d+)\s+(\d\d \w\w\w \d\d\d\d\s+)?(\d+)$/) {
96 $pdate{$ver} = $pdate if defined $pdate;
97 $last_protocol_version = $pver if $ver eq $lastversion;
98 }
99}
100close IN;
101die "Unable to determine protocol_version for $lastversion.\n" unless defined $last_protocol_version;
102
103my $protocol_version;
104open(IN, '<', 'rsync.h') or die $!;
105while (<IN>) {
106 if (/^#define\s+PROTOCOL_VERSION\s+(\d+)/) {
107 $protocol_version = $1;
108 last;
109 }
110}
111close IN;
112die "Unable to determine the current PROTOCOL_VERSION.\n" unless defined $protocol_version;
113
114my $version = $confversion;
115$version =~ s/dev/pre1/ || $version =~ s/pre(\d+)/ 'pre' . ($1 + 1) /e;
116
117print "Please enter the version number of this release: [$version] ";
118chomp($_ = <STDIN>);
119if ($_ eq '.') {
120 $version =~ s/pre\d+//;
121} elsif ($_ ne '') {
122 $version = $_;
123}
124die "Invalid version: `$version'\n" unless $version =~ /^[\d.]+(pre\d+)?$/;
125
126if (`git tag -l v$version` ne '') {
127 print "Tag v$version already exists.\n\nDelete tag or quit? [q/del] ";
128 $_ = <STDIN>;
129 exit 1 unless /^del/i;
130 system "git tag -d v$version";
131}
132
133if ($version =~ s/[-.]*pre[-.]*/pre/ && $confversion !~ /dev$/) {
134 $lastversion = $confversion;
135}
136
137print "Enter the previous version to produce a patch against: [$lastversion] ";
138chomp($_ = <STDIN>);
139$lastversion = $_ if $_ ne '';
140$lastversion =~ s/[-.]*pre[-.]*/pre/;
141
142my $pre = $version =~ /(pre\d+)/ ? $1 : '';
143
144my $release = $pre ? '0.1' : '1';
145print "Please enter the RPM release number of this release: [$release] ";
146chomp($_ = <STDIN>);
147$release = $_ if $_ ne '';
148$release .= ".$pre" if $pre;
149
150(my $finalversion = $version) =~ s/pre\d+//;
151my($proto_changed,$proto_change_date);
152if ($protocol_version eq $last_protocol_version) {
153 $proto_changed = 'unchanged';
154 $proto_change_date = "\t\t";
155} else {
156 $proto_changed = 'changed';
157 if (!defined($proto_change_date = $pdate{$finalversion})) {
158 while (1) {
159 print "On what date did the protocol change to $protocol_version get checked in? (dd Mmm yyyy) ";
160 chomp($_ = <STDIN>);
161 last if /^\d\d \w\w\w \d\d\d\d$/;
162 }
163 $proto_change_date = "$_\t";
164 }
165}
166
167my($srcdir,$srcdiffdir,$lastsrcdir,$skipping);
168if ($lastversion =~ /pre/) {
169 if (!$pre) {
170 die "You should not diff a release version against a pre-release version.\n";
171 }
172 $srcdir = $srcdiffdir = $lastsrcdir = 'src-previews';
173 $skipping = ' ** SKIPPING **';
174} elsif ($pre) {
175 $srcdir = $srcdiffdir = 'src-previews';
176 $lastsrcdir = 'src';
177 $skipping = ' ** SKIPPING **';
178} else {
179 $srcdir = $lastsrcdir = 'src';
180 $srcdiffdir = 'src-diffs';
181 $skipping = '';
182}
183
184print "\n", $break, <<EOT;
185\$version is "$version"
186\$lastversion is "$lastversion"
187\$dest is "$dest"
188\$curdir is "$curdir"
189\$srcdir is "$srcdir"
190\$srcdiffdir is "$srcdiffdir"
191\$lastsrcdir is "$lastsrcdir"
192\$release is "$release"
193
194About to:
195 - tweak SUBPROTOCOL_VERSION in rsync.h, if needed
196 - tweak the version in configure.in and the spec files
197 - tweak NEWS and OLDNEWS to ensure header values are correct
198 - tweak the date in the *.yo files and generate the manpages
199 - generate configure.sh, config.h.in, and proto.h
200 - page through the differences
201
202EOT
203print "<Press Enter to continue> ";
204$_ = <STDIN>;
205
206my %specvars = ( 'Version:' => $finalversion, 'Release:' => $release,
207 '%define fullversion' => "\%{version}$pre", 'Released' => "$version.",
208 '%define srcdir' => $srcdir );
209my @tweak_files = ( glob('packaging/*.spec'), glob('packaging/*/*.spec'), glob('*.yo'),
210 qw( configure.in rsync.h NEWS OLDNEWS options.c ) );
211
212foreach my $fn (@tweak_files) {
213 open(IN, '<', $fn) or die $!;
214 undef $/; $_ = <IN>; $/ = "\n";
215 close IN;
216 if ($fn =~ /configure/) {
217 s/^RSYNC_VERSION=.*/RSYNC_VERSION=$version/m
218 or die "Unable to update RSYNC_VERSION in $fn\n";
219 } elsif ($fn =~ /\.spec/) {
220 while (my($str, $val) = each %specvars) {
221 s/^\Q$str\E .*/$str $val/m
222 or die "Unable to update $str in $fn\n";
223 }
224 s/^\* \w\w\w \w\w\w \d\d \d\d\d\d (.*)/$cl_today $1/m
225 or die "Unable to update ChangeLog header in $fn\n";
226 } elsif ($fn =~ /\.yo/) {
227 s/^(manpage\([^)]+\)\(\d+\)\()[^)]+(\).*)/$1$today$2/m
228 or die "Unable to update date in manpage() header in $fn\n";
229 s/^(This man ?page is current for version) \S+ (of rsync)/$1 $version $2/m
230 or die "Unable to update current version info in $fn\n";
231 } elsif ($fn eq 'rsync.h') {
232 s{(#define\s+SUBPROTOCOL_VERSION)\s+(\d+)}
233 { $1 . ' ' . get_subprotocol_version($2) }e
234 or die "Unable to find SUBPROTOCOL_VERSION define in $fn\n";
235 } elsif ($fn eq 'NEWS') {
236 s{^(NEWS for rsync \Q$finalversion\E )(\(UNRELEASED\))\s*(\nProtocol: )(\d+) (\([^)]+\))\n}
237 { $1 . ($pre ? $2 : "($today)") . "$3$protocol_version ($proto_changed)\n" }ei
238 or die "The first 2 lines of $fn are not in the right format. They must be:\n"
239 . "NEWS for rsync $finalversion (UNRELEASED)\n"
240 . "Protocol: $protocol_version ($proto_changed)\n";
241 } elsif ($fn eq 'OLDNEWS') {
242 s{^(\t\S\S\s\S\S\S\s\d\d\d\d)(\t\Q$finalversion\E\t).*}
243 { ($pre ? $1 : "\t$ztoday") . $2 . $proto_change_date . $protocol_version }em
244 or die "Unable to find \"?? ??? $year\t$finalversion\" line in $fn\n";
245 } elsif ($fn eq 'options.c') {
246 if (s/(Copyright \(C\) 2002-)(\d+)( Wayne Davison)/$1$year$3/
247 && $2 ne $year) {
248 die "Copyright comments need to be updated to $year in all files!\n";
249 }
250 # Adjust the year in the --version output.
251 s/(rprintf\(f, "Copyright \(C\) 1996-)(\d+)/$1$year/
252 or die "Unable to find Copyright string in --version output of $fn\n";
253 next if $2 eq $year;
254 } else {
255 die "Unrecognized file in \@tweak_files: $fn\n";
256 }
257 open(OUT, '>', $fn) or die $!;
258 print OUT $_;
259 close OUT;
260}
261
262print $break;
263system "git diff --color | less -p '^diff .*'";
264
265my $srctar_name = "rsync-$version.tar.gz";
266my $pattar_name = "rsync-patches-$version.tar.gz";
267my $diff_name = "rsync-$lastversion-$version.diffs.gz";
268my $srctar_file = "$dest/$srcdir/$srctar_name";
269my $pattar_file = "$dest/$srcdir/$pattar_name";
270my $diff_file = "$dest/$srcdiffdir/$diff_name";
271my $news_file = "$dest/$srcdir/rsync-$version-NEWS";
272my $lasttar_file = "$dest/$lastsrcdir/rsync-$lastversion.tar.gz";
273
274print $break, <<EOT;
275
276About to:
277 - commit all version changes
278 - merge the $master_branch branch into the patch/* branches
279 - update the files in the "patches" dir and OPTIONALLY
280 (if you type 'y') to launch a shell for each patch
281
282EOT
283print "<Press Enter OR 'y' to continue> ";
284my $ans = <STDIN>;
285
286system "git commit -a -m 'Preparing for release of $version'" and exit 1;
287
288print "Updating files in \"patches\" dir ...\n";
289system "packaging/patch-update --branch=$master_branch";
290
291if ($ans =~ /^y/i) {
292 print "\nVisiting all \"patch/*\" branches ...\n";
293 system "packaging/patch-update --branch=$master_branch --shell";
294}
295
296print $break, <<EOT;
297
298About to:
299 - create signed tag for this release: v$version
300 - create release diffs, "$diff_name"
301 - create release tar, "$srctar_name"
302 - generate rsync-$version/patches/* files
303 - create patches tar, "$pattar_name"
304 - update top-level README, *NEWS, TODO, and ChangeLog
305 - update top-level rsync*.html manpages
306 - gpg-sign the release files
307 - update hard-linked top-level release files$skipping
308
309EOT
310print "<Press Enter to continue> ";
311$_ = <STDIN>;
312
313my $passphrase;
314while (1) {
315 ReadMode('noecho');
316 print "\nEnter your GPG pass-phrase: ";
317 chomp($passphrase = <STDIN>);
318 ReadMode(0);
319 print "\n";
320
321 # Briefly create a temp file with the passphrase for git's tagging use.
322 my $oldmask = umask 077;
323 unlink($passfile);
324 open(OUT, '>', $passfile) or die $!;
325 print OUT $passphrase, "\n";
326 close OUT;
327 umask $oldmask;
328 $ENV{'GPG_PASSFILE'} = $passfile;
329
330 # We want to use our passphrase-providing "gpg" script, so modify the PATH.
331 $ENV{PATH} = "packaging/bin:$path";
332 $_ = `git tag -s -m 'Version $version.' v$version 2>&1`;
333 $ENV{PATH} = $path;
334 unlink($passfile);
335 print $_;
336 next if /bad passphrase/;
337 last unless /failed/;
338 exit 1;
339}
340
341# Extract the generated files from the old tar.
342@_ = @extra_files;
343map { s#^#rsync-$lastversion/# } @_;
344system "tar xzf $lasttar_file @_";
345rename("rsync-$lastversion", 'a');
346
347print "Creating $diff_file ...\n";
348system "$make_gen_cmd && rsync -a @extra_files b/" and exit 1;
349my $sed_script = 's:^((---|\+\+\+) [ab]/[^\t]+)\t.*:\1:';
350system "(git diff v$lastversion v$version; diff -upN a b | sed -r '$sed_script') | gzip -9 >$diff_file";
351system "rm -rf a";
352rename('b', "rsync-$version");
353
354print "Creating $srctar_file ...\n";
355system "git archive --format=tar --prefix=rsync-$version/ v$version | tar xf -";
356system "support/git-set-file-times --prefix=rsync-$version/";
357system "fakeroot tar czf $srctar_file rsync-$version; rm -rf rsync-$version";
358
359print "Updating files in \"rsync-$version/patches\" dir ...\n";
360mkdir("rsync-$version", 0755);
361mkdir("rsync-$version/patches", 0755);
362system "packaging/patch-update --skip-check --branch=$master_branch --gen=rsync-$version/patches";
363
364print "Creating $pattar_file ...\n";
365system "fakeroot tar chzf $pattar_file rsync-$version/patches; rm -rf rsync-$version";
366
367print "Updating the other files in $dest ...\n";
368system "rsync -a README NEWS OLDNEWS TODO $dest";
369unlink($news_file);
370link("$dest/NEWS", $news_file);
371system "git log --name-status | gzip -9 >$dest/ChangeLog.gz";
372
373system "yodl2html -o $dest/rsync.html rsync.yo";
374system "yodl2html -o $dest/rsyncd.conf.html rsyncd.conf.yo";
375
376foreach my $fn ($srctar_file, $pattar_file, $diff_file) {
377 unlink("$fn.asc");
378 open(GPG, '|-', "gpg --batch --passphrase-fd=0 -ba $fn") or die $!;
379 print GPG $passphrase, "\n";
380 close GPG;
381}
382
383if (!$pre) {
384 system "rm $dest/rsync-*.gz $dest/rsync-*.asc $dest/rsync-*-NEWS $dest/src-previews/rsync-*diffs.gz*";
385
386 foreach my $fn ($srctar_file, "$srctar_file.asc",
387 $pattar_file, "$pattar_file.asc",
388 $diff_file, "$diff_file.asc", $news_file) {
389 (my $top_fn = $fn) =~ s#/src(-\w+)?/#/#;
390 link($fn, $top_fn);
391 }
392}
393
394print $break, <<'EOT';
395
396Local changes are done. When you're satisfied, push the git repository
397and rsync the release files. Remember to announce the release on *BOTH*
398rsync-announce@lists.samba.org and rsync@lists.samba.org (and the web)!
399EOT
400
401exit;
402
403sub get_subprotocol_version
404{
405 my($subver) = @_;
406 if ($pre && $proto_changed eq 'changed') {
407 return $subver == 0 ? 1 : $subver;
408 }
409 0;
410}
411
412sub usage
413{
414 die <<EOT;
415Usage: release-rsync [OPTIONS]
416
417-b, --branch=BRANCH The branch to release (default: master)
418-h, --help Display this help message
419EOT
420}