summaryrefslogtreecommitdiff
path: root/bin/make_release
blob: 371d8f2292bf377b0221c44873a6f1c0d5b9ae56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}'
    & eval 'exec perl -S $0 $argv:q'
    if 0;

# $Id$
#
# Creates an ACE or TAO kit.  Intended to be called from the
# ACE or TAO top-level Makefiles.
#
# The first three lines above let this script run without specifying the
# full path to perl, as long as it is in the user's PATH.
# Taken from perlrun man page.

$usage="usage: $0 [-?] [-k <kit>] [-n] [-t <type>] " .
         "[-c <controlled files>] [-r <release files>] " .
         "[-l <release lib files]\n";
$long_usage="   -? option prints this message\n" .
            "   -k <kit>, where <kit> is ace, tao, or ace+tao\n" .
            "   -n option prints what would be done, but doesn't do it\n" .
            "   -t <type>, where <type> is major, minor, or beta (default)\n" .
            "   -c <controlled files> lists the CVS-controlled files\n" .
            "   -r <release files> lists the files to be released\n" .
            "   -l <release lib files> list the files to put in the lib kit\n";

########
######## Configuration parameters.
########
if (-d '/pkg/gnu/bin') {
  $gnu = '/pkg/gnu/bin/';
} else {
  #### The default utilities had better be GNU.
  $gnu = '';
}

$exec_prefix = $exec_suffix = '';
$kit = '';
$release_type = 'beta';
$controlled_files = '';
$release_files = '';
$release_filter = '-name CVS -prune -name build -prune -o ! -name \'.\#*\' ' .
                  '! -name \'\#*\' ! -name \'*~\' ' .
                  '! -name \'*.MAK\' -print';

########
######## Process command line args.
########
while ($#ARGV >= $[  &&  $ARGV[0] =~ /^-/) {
  if ($ARGV[0] eq '-k') {
    if ($ARGV[1] =~ /^[^-]+/  &&
        ($ARGV[1] eq 'ace' || $ARGV[1] eq 'tao' || $ARGV[1] eq 'ace+tao')) {
      $kit = $ARGV[1]; shift;
    } else {
      print STDERR "$0:  must provide argument for -k option\n";
      die "$usage$long_usage";
    }
  } elsif ($ARGV[0] eq '-n') {
    $exec_prefix = 'echo \'';
    $exec_suffix = '\'';
  } elsif ($ARGV[0] eq '-t') {
    if ( $ARGV[1] =~ /^[^-]+/  &&
         ($ARGV[1] eq 'major' || $ARGV[1] eq 'minor' ||
          $ARGV[1] eq 'beta')) {
      $release_type = $ARGV[1]; shift;
    } else {
      print STDERR "$0:  must provide argument for -t option\n";
      die "$usage$long_usage";
    }
  } elsif ($ARGV[0] eq '-c') {
    if ( $ARGV[1] =~ /^[^-]+/) {
      $controlled_files = $ARGV[1]; shift;
    } else {
      print STDERR "$0:  must provide argument for -c option\n";
      die "$usage$long_usage";
    }
  } elsif ($ARGV[0] eq '-r') {
    if ( $ARGV[1] =~ /^[^-]+/) {
      $release_files = $ARGV[1]; shift;
    } else {
      print STDERR "$0:  must provide argument for -r option\n";
      die "$usage$long_usage";
    }
  } elsif ($ARGV[0] eq '-l') {
    if ( $ARGV[1] =~ /^[^-]+/) {
      $release_lib_files = $ARGV[1]; shift;
    } else {
      print STDERR "$0:  must provide argument for -l option\n";
      die "$usage$long_usage";
    }
  } elsif ($ARGV[0] eq '-?') {
    print "$usage$long_usage";
    exit;
  } else {
    print STDERR "$0:  unknown option $ARGV[0]\n";
    die "$usage$long_usage";
  }
  shift;
}

die "must specify a -k option\n" unless "$kit";
$update_versions = 0;
if ($kit eq 'ace') {
  $KIT = 'ACE';
  $update_versions = (`pwd` eq "/project/adaptive/ACE_wrappers\n");
} elsif ($kit eq 'tao') {
  $KIT = 'TAO';
  $update_versions = (`pwd` eq "/project/adaptive/ACE_wrappers/TAO\n");
} else {
  #### Creating combined ACE+TAO kit.  Don't use $KIT.
};

$chmod = '/bin/chmod';
$cpio = "${gnu}cpio";
$cvs = "${exec_prefix}${gnu}cvs";
$date = "${gnu}date";
$find = "${gnu}find";
$gzip = "${gnu}gzip";
$mv = '/bin/mv';
chop ($now = `$date +"%a %b %d %T %Y"`);

########
######## Setup signal handler.
########
$SIG{'HUP'} = $SIG{'INT'} = $SIG{'QUIT'} = $SIG{'TERM'} = 'cleanup';

########
######## Defend against fascist umasks.
########
umask 022;

########
######## Main execution thread.
########
if ($update_versions  &&  "$kit" ne 'ace+tao') {
  $major_version = $minor_version = $beta_version = 0;
  $previous_version = $version = '';

  &check_workspace ()  ||
  &get_versions ()  ||
  &update_version_files ()  ||
  &update_changelog ()  ||
  &tag ()  ||
  &diff ()  ||
  &create_kit ();
} else {
  &create_kit ();
}
&cleanup;

########
######## Clean up when done or on signal.
########
sub cleanup {
  exit;
}

########
######## Check that the workspace is up-to-date, if releasing from
######## the official release directory.
########
sub check_workspace () {
  if ("$controlled_files") {
    my @out_of_date = ();
    open (CVS, "$cvs -nq update $controlled_files |")  ||
      die "$0: unable to open $cvs\n";
    while (<CVS>) {
      next if m%/tests/log/%;
      push (@out_of_date, $_) if "$_";
    }
    close CVS;

    if (! "$exec_prefix"  &&  @out_of_date) {
      warn "ERROR: workspace must be updated or cleaned: " .
           join ("\n  ", @out_of_date) . "\n";
      return 1;
    }
  }

  0;
}

########
######## Retrieve version information from VERSION file(s).
########
sub get_versions () {
  open (VERSION, '< VERSION')  ||
    die "$0: unable to open VERSION\n";
  while (<VERSION>) {
    if (/$KIT version (\d+)\.(\d+)\.(\d+)/o) {
      $major_version = $1;
      $minor_version = $2;
      $beta_version = $3;
      last;
    } elsif (/$KIT version (\d+)\.(\d+)[^\.]/o) {
      #### Previous release was a minor.
      $major_version = $1;
      $minor_version = $2;
      last;
    } elsif (/$KIT version (\d+)[^\.]/o) {
      #### Previous release was a major.
      $major_version = $1;
      last;
    }
  }
  close VERSION;

  if ($release_type eq 'beta') {
    if ($beta_version > 0) {
      $previous_version = "$major_version.$minor_version.$beta_version";
    } elsif ($minor_version > 0) {
      $previous_version = "$major_version.$minor_version";
    } else {
      $previous_version = "$major_version";
    }

    ++$beta_version;
    $version = "$major_version.$minor_version.$beta_version";
  } elsif ($release_type eq 'minor' ) {
    $beta_version = 0;
    ++$minor_version;
    $version = "$major_version.$minor_version";
  } elsif ($release_type eq 'major' ) {
    $minor_version = $beta_version = 0;
    ++$major_version;
    $version = "$major_version";
  }

  print "new $KIT version: $version\n";

  0;
}

########
######## Update VERSION file(s).
########
sub update_version_files () {
  system ("$exec_prefix" .
    "perl -pi -e " .
    "'s/$KIT version .*/$KIT version $version, released $now./' " .
    "VERSION $exec_suffix");
  return 1 if $? >> 8;

  if (! "$exec_prefix"  &&  $kit =~ /^ace/) {
    open (ACE_VERSION_H, "> ace/Version.h")  ||
      die "$0: unable to open ace/Version.h\n";

    print ACE_VERSION_H
      "// \$Id\$\n" .
      "// This is an automatically generated file.\n\n" .
      "\#define ACE_MAJOR_VERSION (${major_version}u)\n" .
      "\#define ACE_MINOR_VERSION (${minor_version}u)\n" .
      "\#define ACE_BETA_VERSION (${beta_version}u)\n" .
      "\#define ACE_VERSION \"${version}\\0\"\n";

    close ACE_VERSION_H;
  }

  0;
}

########
######## Add ChangeLog entries, and make sure that they have proper
######## permissions.
########
sub update_changelog () {
  my $logname = $ENV{'LOGNAME'};
  my $signature = $ENV{'SIGNATURE'} || $logname;
  my $message = "$now  $signature  <$logname\\\@cs.wustl.edu>\n\n" .
                "        * $KIT version $version released.\n\n";
  my $message_insert = "perl -pi -e 'BEGIN {\$message_printed = 0;}
     if (! \$message_printed) {
       print \"$message\";
       ++\$message_printed; }' ChangeLog";

  if ("$exec_prefix") {
    print "$message_insert\n";
  } else {
    system ($message_insert);
  }

  if ($kit =~ /^ace/) {
    system ("$cvs commit -m'$version' VERSION ChangeLog ace/Version.h " .
            "&& chmod 0644 VERSION ChangeLog ace/Version.h");
  } elsif ($kit =~ /tao/) {
    system ("$cvs commit -m'$version' VERSION ChangeLog " .
            "&& chmod 0644 VERSION ChangeLog");
  }
  return 1 if $? >> 8;

  0;
}

########
######## Tag the release.
########
sub tag () {
  my $tag = "$KIT-$version";
  #### cvs tag does not allow dots.
  $tag =~ tr/./_/;

  print "start tagging $tag\n";
  system ("$cvs -q tag $tag $controlled_files > /dev/null");
  return 1 if $? >> 8;
  print "finished tagging $tag\n";

  0;
}

########
######## If building a beta, create a diff from the previos version.
########
sub diff () {
  if ("$previous_version") {
    #### Only create a diff for a beta version.

    my $previous_tag = "$KIT-$previous_version";
    my $tag = "$KIT-$version";

    #### cvs tag does not allow dots.
    $previous_tag =~ tr/./_/;
    $tag =~ tr/./_/;

    my $module = $kit eq 'ace'  ?  'ACE_wrappers'  :  'ACE_wrappers/TAO';

    system ("$cvs -q rdiff -u -r $previous_tag -r $tag $module | " .
            "$gzip -9 > diffs/$previous_tag-$tag.diff.gz &");
  }

  #### Ignore return value.  No promises on diffs.
  0;
}

########
######## Create the tar file(s) and move to their proper location.
########
sub create_kit () {
  if ("$exec_prefix") {
    print "chdir '..'\n";
  } else {
    chdir '..'  ||  die "$0: unable to chdir ..\n";
  }

  if ($kit eq 'ace') {
    system ("$exec_prefix" .
            "$find $release_files $release_filter | $cpio -o -H tar | " .
            "$gzip -9 > ACE.tar.gz && " .
            "$find $release_lib_files $release_filter | $cpio -o -H tar | " .
            "$gzip -9 > ACE-lib.tar.gz && " .
            "$chmod a+r ACE.tar.gz ACE-lib.tar.gz && " .
            "$mv ACE.tar.gz ACE-lib.tar.gz ACE_wrappers/ $exec_suffix");
  } elsif ($kit eq 'ace+tao') {
    system ("$exec_prefix" .
            "$find $release_files $release_filter | $cpio -o -H tar | " .
            "$gzip -9 > ACE+TAO.tar.gz && " .
            "$chmod a+r ACE+TAO.tar.gz && " .
            "$mv ACE+TAO.tar.gz ACE_wrappers/ $exec_suffix");
  }

  0;
}