Changed the commands used to "make gen" without any stoppage.
[rsync/rsync.git] / packaging / release-rsync
1 #!/usr/bin/perl
2 use strict;
3 use 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
10 use Cwd;
11 use Getopt::Long;
12 use Term::ReadKey;
13 use Date::Format;
14
15 my $dest = $ENV{HOME} . '/samba-rsync-ftp';
16 my $passfile = $ENV{HOME} . '/.rsyncpass';
17 my $path = $ENV{PATH};
18 my $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
27 my $now = time;
28 my $cl_today = time2str('* %a %b %d %Y', $now);
29 my $year = time2str('%Y', $now);
30 my $ztoday = time2str('%d %b %Y', $now);
31 (my $today = $ztoday) =~ s/^0//;
32
33 my $curdir = Cwd::cwd;
34
35 END {
36     unlink($passfile);
37 }
38
39 my @extra_files;
40 open(IN, '<', 'Makefile.in') or die "Couldn't open Makefile.in: $!\n";
41 while (<IN>) {
42     if (s/^GENFILES=//) {
43         while (s/\\$//) {
44             $_ .= <IN>;
45         }
46         @extra_files = split(' ', $_);
47         last;
48     }
49 }
50 close IN;
51
52 my $break = <<EOT;
53 ==========================================================================
54 EOT
55
56 print $break, <<EOT, $break, "\n";
57 == This will release a new version of rsync onto an unsuspecting world. ==
58 EOT
59
60 die "$dest does not exist\n" unless -d $dest;
61 die "There is no .git dir in the current directory.\n" unless -d '.git';
62 die "'a' must not exist in the current directory.\n" if -e 'a';
63 die "'b' must not exist in the current directory.\n" if -e 'b';
64
65 open(IN, '-|', 'git status') or die $!;
66 my $status = join('', <IN>);
67 close IN;
68 die "The checkout is not clean:\n", $status unless $status =~ /\nnothing to commit \(working directory clean\)/;
69 my($cur_branch) = $status =~ /^# On branch (.+)\n/;
70 if ($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
79 my $confversion;
80 open(IN, '<', 'configure.in') or die $!;
81 while (<IN>) {
82     if (/^RSYNC_VERSION=(.*)/) {
83         $confversion = $1;
84         last;
85     }
86 }
87 close IN;
88 die "Unable to find RSYNC_VERSION in configure.in\n" unless defined $confversion;
89
90 open(IN, '<', 'OLDNEWS') or die $!;
91 $_ = <IN>;
92 my($lastversion) = /(\d+\.\d+\.\d+)/;
93 my($last_protocol_version, %pdate);
94 while (<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 }
100 close IN;
101 die "Unable to determine protocol_version for $lastversion.\n" unless defined $last_protocol_version;
102
103 my $protocol_version;
104 open(IN, '<', 'rsync.h') or die $!;
105 while (<IN>) {
106     if (/^#define\s+PROTOCOL_VERSION\s+(\d+)/) {
107         $protocol_version = $1;
108         last;
109     }
110 }
111 close IN;
112 die "Unable to determine the current PROTOCOL_VERSION.\n" unless defined $protocol_version;
113
114 my $version = $confversion;
115 $version =~ s/dev/pre1/ || $version =~ s/pre(\d+)/ 'pre' . ($1 + 1) /e;
116
117 print "Please enter the version number of this release: [$version] ";
118 chomp($_ = <STDIN>);
119 if ($_ eq '.') {
120     $version =~ s/pre\d+//;
121 } elsif ($_ ne '') {
122     $version = $_;
123 }
124 die "Invalid version: `$version'\n" unless $version =~ /^[\d.]+(pre\d+)?$/;
125
126 if (`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
133 if ($version =~ s/[-.]*pre[-.]*/pre/ && $confversion !~ /dev$/) {
134     $lastversion = $confversion;
135 }
136
137 print "Enter the previous version to produce a patch against: [$lastversion] ";
138 chomp($_ = <STDIN>);
139 $lastversion = $_ if $_ ne '';
140 $lastversion =~ s/[-.]*pre[-.]*/pre/;
141
142 my $pre = $version =~ /(pre\d+)/ ? $1 : '';
143
144 my $release = $pre ? '0.1' : '1';
145 print "Please enter the RPM release number of this release: [$release] ";
146 chomp($_ = <STDIN>);
147 $release = $_ if $_ ne '';
148 $release .= ".$pre" if $pre;
149
150 (my $finalversion = $version) =~ s/pre\d+//;
151 my($proto_changed,$proto_change_date);
152 if ($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
167 my($srcdir,$srcdiffdir,$lastsrcdir,$skipping);
168 if ($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
184 print "\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
194 About 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
202 EOT
203 print "<Press Enter to continue> ";
204 $_ = <STDIN>;
205
206 my %specvars = ( 'Version:' => $finalversion, 'Release:' => $release,
207                  '%define fullversion' => "\%{version}$pre", 'Released' => "$version.",
208                  '%define srcdir' => $srcdir );
209 my @tweak_files = ( glob('packaging/*.spec'), glob('packaging/*/*.spec'), glob('*.yo'),
210                     qw( configure.in rsync.h NEWS OLDNEWS options.c ) );
211
212 foreach 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
262 print $break;
263 system "git diff --color | less -p '^diff .*'";
264
265 my $srctar_name = "rsync-$version.tar.gz";
266 my $pattar_name = "rsync-patches-$version.tar.gz";
267 my $diff_name = "rsync-$lastversion-$version.diffs.gz";
268 my $srctar_file = "$dest/$srcdir/$srctar_name";
269 my $pattar_file = "$dest/$srcdir/$pattar_name";
270 my $diff_file = "$dest/$srcdiffdir/$diff_name";
271 my $news_file = "$dest/$srcdir/rsync-$version-NEWS";
272 my $lasttar_file = "$dest/$lastsrcdir/rsync-$lastversion.tar.gz";
273
274 print $break, <<EOT;
275
276 About 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
282 EOT
283 print "<Press Enter OR 'y' to continue> ";
284 my $ans = <STDIN>;
285
286 system "git commit -a -m 'Preparing for release of $version'" and exit 1;
287
288 print "Updating files in \"patches\" dir ...\n";
289 system "packaging/patch-update --branch=$master_branch";
290
291 if ($ans =~ /^y/i) {
292     print "\nVisiting all \"patch/*\" branches ...\n";
293     system "packaging/patch-update --branch=$master_branch --shell";
294 }
295
296 print $break, <<EOT;
297
298 About 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
309 EOT
310 print "<Press Enter to continue> ";
311 $_ = <STDIN>;
312
313 my $passphrase;
314 while (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;
343 map { s#^#rsync-$lastversion/# } @_;
344 system "tar xzf $lasttar_file @_";
345 rename("rsync-$lastversion", 'a');
346
347 print "Creating $diff_file ...\n";
348 system "$make_gen_cmd && rsync -a @extra_files b/" and exit 1;
349 my $sed_script = 's:^((---|\+\+\+) [ab]/[^\t]+)\t.*:\1:';
350 system "(git diff v$lastversion v$version; diff -upN a b | sed -r '$sed_script') | gzip -9 >$diff_file";
351 system "rm -rf a";
352 rename('b', "rsync-$version");
353
354 print "Creating $srctar_file ...\n";
355 system "git archive --format=tar --prefix=rsync-$version/ v$version | tar xf -";
356 system "support/git-set-file-times --prefix=rsync-$version/";
357 system "fakeroot tar czf $srctar_file rsync-$version; rm -rf rsync-$version";
358
359 print "Updating files in \"rsync-$version/patches\" dir ...\n";
360 mkdir("rsync-$version", 0755);
361 mkdir("rsync-$version/patches", 0755);
362 system "packaging/patch-update --skip-check --branch=$master_branch --gen=rsync-$version/patches";
363
364 print "Creating $pattar_file ...\n";
365 system "fakeroot tar chzf $pattar_file rsync-$version/patches; rm -rf rsync-$version";
366
367 print "Updating the other files in $dest ...\n";
368 system "rsync -a README NEWS OLDNEWS TODO $dest";
369 unlink($news_file);
370 link("$dest/NEWS", $news_file);
371 system "git log --name-status | gzip -9 >$dest/ChangeLog.gz";
372
373 system "yodl2html -o $dest/rsync.html rsync.yo";
374 system "yodl2html -o $dest/rsyncd.conf.html rsyncd.conf.yo";
375
376 foreach 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
383 if (!$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
394 print $break, <<'EOT';
395
396 Local changes are done.  When you're satisfied, push the git repository
397 and rsync the release files.  Remember to announce the release on *BOTH*
398 rsync-announce@lists.samba.org and rsync@lists.samba.org (and the web)!
399 EOT
400
401 exit;
402
403 sub 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
412 sub usage
413 {
414     die <<EOT;
415 Usage: release-rsync [OPTIONS]
416
417 -b, --branch=BRANCH   The branch to release (default: master)
418 -h, --help            Display this help message
419 EOT
420 }