summaryrefslogtreecommitdiff
path: root/bin/autoconf_compile
blob: 8c3a283723daac64101029d48107a1ed3d929a90 (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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
    & eval 'exec perl -S $0 $argv:q'
    if 0;

# -*- perl -*-
# $Id$
#
# This script checkouts ACE from CVS, configures ACE, and compiles
# `ace', `tests' and finally runs `tests/run_tests.sh'.
#
# If it detects any problem it sends e-mail.
#
# DO NOT invoke this script from your crontab, use
# autoconf_compile_wrapper for that.
#
# This script requires Perl 5.
#
# TODO: Modify the script or split it in such a way that the main copy
# can be obtained either using cvs or downloading the latest beta
# from the WWW.
#

# 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.

use File::Basename;
use FileHandle;
require POSIX;

$directory_mode=0755;

# This is the module we will checkout, someday someone could define a
# smaller module.
$MODULE='ACE_wrappers';

# These are the sub-directories (in the module) we really compile.

# Find out the command name.
$CMD = basename($0);

$single_threaded = 0;
$minimum_corba = 0;
$ami = 0;
$dont_update = 0;
$dont_run = 0;
$pre_clean = 0;
$post_clean = 0;
$report_success = 0;
$debug = 0;
@BUILD_LIST= ();

@ARGS = ();
while ($#ARGV >= 0) {
  if (!($ARGV[0] =~ m/-/)) {
    push @ARGS, $ARGV[0];
    shift;
  } elsif ($ARGV[0] eq "-single_threaded") {
    $single_threaded = 1;
    shift;
  } elsif ($ARGV[0] eq "-minimum_corba") {
    $minimum_corba = 1;
    shift;
  } elsif ($ARGV[0] eq "-ami") {
      $ami =1;
      shift;
  } elsif ($ARGV[0] eq "-build_list") {
    shift;
    @BUILD_LIST = split (/,/, $ARGV[0]);
    shift;
  } elsif ($ARGV[0] eq "-dont_update") {
    $dont_update = 1;
    shift;
  } elsif ($ARGV[0] eq "-dont_run") {
    $dont_run = 1;
    shift;
  } elsif ($ARGV[0] eq "-pre_clean") {
    $pre_clean = 1;
    shift;
  } elsif ($ARGV[0] eq "-post_clean") {
    $post_clean = 1;
    shift;
  } elsif ($ARGV[0] eq "-report_success") {
    $report_success = 1;
    shift;
  } elsif ($ARGV[0] eq "-debug") {
    $debug = 1;
    shift;
  }
}

# Extract configuration information from command line.
  # TODO: Some validation and checking should be done here.
$CHECKOUT = $ARGS[0];
$BUILD    = $ARGS[1];
$LOGDIR   = $ARGS[2];
$ADMIN    = $ARGS[3];
$MAIL = "mail";
if ($#ARGS >= 4) {
  $MAIL     = $ARGS[4];
}

# We obtain our revision to report errors.
$REVISION='$Revision$ ';

# When an error is found we try to die gracefully and send some email
# to ADMIN.

$disable_file = $LOGDIR . '/.disable';
$histfile = $LOGDIR . '/history';
$LOGBASE = POSIX::strftime("%b%d_%Y.txt", localtime);
$LOGFILE = $LOGDIR . '/' . $LOGBASE;
$HOST = `hostname`;
chop $HOST;
$LOG_NAME =  $HOST . "_" . $BUILD . "_" . $LOGBASE;
$STATUS = "OK";

if ($debug) {
  print "CHECKOUT = $CHECKOUT\n";
  print "BUILD = $BUILD\n";
  print "LOGDIR = $LOGDIR\n";
  print "ADMIN = $ADMIN\n";
  print "MAIL = $MAIL\n";
}

push @INC, $CHECKOUT . '/' . $MODULE . '/bin';
#require run_all_list;
@RUN_LIST = ('tests');   # Temporary hack


if ($#BUILD_LIST == -1) {
  @BUILD_LIST=
    ('ace',
     'netsvcs',
     'tests',
     'apps/gperf');
}
if ($debug) {

  @BUILD_LIST = ('ace');
  @RUN_LIST = ('tests');
#  @SINGLE_THREADED_LIST = ('TAO/tests/OctetSeq');
#  @MINIMUM_CORBA_LIST = ('TAO/tests/OctetSeq');
  $ADMIN = $ENV{'LOGNAME'};

}

sub mydie {
  unlink $disable_file;
  die $_ . "\n";
}

sub report_errors {
  # First clear the lock, so the next execution works...
  unlink $disable_file; # Ignore errors!

  # Now send a summary of the errors to the ADMIN account...
  local $to = $ADMIN;

  open (MAIL, "|".$MAIL.' -s "[AUTO_COMPILE] '.$BUILD.'" '.$to)
    || mydie "Cannot open mail pipe for: $_\n";

  print MAIL 'The following message is brought to you by: ', "\n";
  print MAIL $CMD, ' [', $REVISION, "] for $BUILD on $CHECKOUT\n\n";

  local $m;
  foreach $m (@_) {
    print MAIL $m, "\n";
  }

  print MAIL "\nPlease check the following log for more info:\n\n";
  print MAIL 'http://www.cs.wustl.edu/~bugzilla/auto_compile_logs/',
             $LOG_NAME, "\n\n";

  close (MAIL); # Ignore errors....

  # Now send the complete log to bugzilla...
  local $bugs = 'bugzilla'.'@cs.wustl.edu';
  open (MAIL, "|".$MAIL.' -s AUTO_COMPILE_LOG='.$LOG_NAME.' '.$bugs)
    || mydie "Cannot open mail pipe for: $LOG_NAME\n";

  print MAIL 'This is the log for: ', "\n";
  print MAIL $CMD, ' [', $REVISION, "] for $BUILD on $CHECKOUT\n";

  print MAIL "\n================================================================\n";

 if (open (THELOG, "$LOGFILE"))
    {
      while (<THELOG>) {
	print MAIL $_;
      }
      close (THELOG);
    }
  close (MAIL); # Ignore errors....
}

### MAIN FUNCTION

if (-f $disable_file) {
  print 'The following message is brought to you by: ', "\n";
  print $CMD, ' [', $REVISION, "] for $BUILD on $CHECKOUT\n";

  print "DISABLED\n";

  exit 0;
}

open (DISABLE, '>' . $disable_file)
    || die "cannot open disable file";
print DISABLE "autoconf_compile <$date> is running\n";
close (DISABLE)
    || die "cannot close disable file";

open(HIST, '>>' . $histfile)
    # Do not use 'mydie' to report the problem, it tries to remove the
    # disable file  
    || mydie "cannot open history file \"$histfile\"\n";

$date = localtime;

print HIST $CMD, ': running at ', $date, ' ';

open(LOG, '>' . $LOGFILE)
    || mydie "cannot open log file";

LOG->autoflush ();

# The following lines are useful when debugging the script or wrapper.
# print LOG $CHECKOUT, " ", $BUILD, " ", $LOGDIR, " ", $ADMIN, "\n";
#while (($key,$value) = each %ENV) {
#  print LOG $key, " = ", $value, "\n";
#}

chdir($CHECKOUT)
    || mydie "Cannot chdir to $CHECKOUT";

if ($dont_update == 0) {
  $date = localtime;
  print LOG "$CMD: starting checkout at ", $date, "\n";
  open(CVS, "cvs -q checkout -P $MODULE 2>&1 |")
    || mydie "cannot start checkout of $MODULE";
#  open(CVS, "cvsup -g -L 2 -P m ace-supfile 2>&1 |")
#    || mydie "cannot start checkout";

  $conflicts = 0;
  while (<CVS>) {
    if (m/^C /) {
      $conflicts = 1;
    }
    print LOG $_;
  }
  close(CVS)
    || mydie "error while checking out $MODULE";
  $date = localtime;
  print LOG "$CMD: checkout finished at ", $date, "\n";

  if ($conflicts != 0) {
    mydie "conflicts on checkout";
  }
}

chdir($MODULE)
    || mydie "cannot chdir to $MODULE";

open (CHLOG, "ChangeLog")
  ||  mydie "cannot open Changelog";
$_ = <CHLOG>;
chop;
print LOG "ACE ChangeLogTag:", $_, "\n";
close (CHLOG);

open (CHLOG, "TAO/ChangeLog")
  ||  mydie "cannot open TAO/Changelog";
$_ = <CHLOG>;
chop;
print LOG "TAO ChangeLogTag:", $_, "\n";
close (CHLOG);

# Bootstrap the workspace
print LOG "$CMD: ==================================================\n\n";
print LOG "$CMD: bootstrapping the workspace\n";
open(BOOTSTRAP, "cd $CHECKOUT/ACE_wrappers && "
     . "sh bin/bootstrap workspace --enable-deps 2>&1 |")
    || mydie "cannot bootstrap workspace for $BUILD";
while(<BOOTSTRAP>) {
    print LOG $_;
}
close(BOOTSTRAP)
    || mydie "error while bootstrapping the workspace";
print LOG "$CMD: ==================================================\n\n";

# Begin the workspace configuration
$date = localtime;
print LOG "$CMD: starting configuration at ", $date, "\n";

# Check that we're in an ACE "top level" directory.
# We can actually build outside of the top level ACE directory, but
# let's do it this way for now.
(-d 'ace' && -d 'm4')  ||
  die "$0:  must be in top level ACE directory!\n";

# Create build directories, if needed.
-d 'build'  ||  mkdir ('build', $directory_mode);
-d "$build"  ||  mkdir ('build/' . "$BUILD", $directory_mode);

# Now enter the build directory.
chdir('build/' . $BUILD)
    || mydie "cannot chdir to $BUILD";

# Remove the configuration cache file to make sure a fresh
# configuration is created.
unlink "config.cache";

# Run the configuration script.
open(CONFIGURE, "sh $CHECKOUT/ACE_wrappers/configure 2>&1 |")
    || mydie "cannot configure for $BUILD";
while(<CONFIGURE>) {
    print LOG $_;
}
close(CONFIGURE)
    || mydie "error while configuring ACE";
$date = localtime;
print LOG "$CMD: configure finished at ", $date, "\n";


@failures = ();

if ($pre_clean) {
  foreach $i (@BUILD_LIST) {
    $date = localtime;
    print LOG "$CMD: =============================================\n";
    print LOG "$CMD: make clean in $i started at ", $date, "\n";
    open(MAKE, "make -k $MAKEFLAGS -C $i clean 2>&1 |")
      || mydie "cannot start make in $i";

    while (<MAKE>) {
      # Ignore errors....
    }
    if (close(MAKE) == 0) {
	push @failures, "errors while cleaning $i";
    }
    $date = localtime;
    print LOG "$CMD: make clean in $i finished at ", $date, "\n";
    print LOG "$CMD: ==================================================\n\n";
  }
}

$MAKEFLAGS .= "";
foreach $i (@BUILD_LIST) {
    $date = localtime;
    print LOG "$CMD: =============================================\n";
    print LOG "$CMD: make for $i started at ", $date, "\n";
    open(MAKE, "make -k $MAKEFLAGS -C $i 2>&1 |")
        || mydie "cannot start make for $i";

    local $current_dir = $i;
    local $last_error = "";
    while (<MAKE>) {
        chop;
        if ($^O eq 'hpux'
            && m/^Warning:[ \t]+[0-9]+ future errors were detected/) {
            next;
        }
        print LOG $_, "\n";

        if (m/^make(\[[0-9]+\])?: Entering directory /) {
            s/^make(\[[0-9]+\])?: Entering directory //;
            $current_dir = $_;
        }
        if (m/error:/i || m/error /i
            || m/^make(\[[0-9]+\])?: \*\*\*/) {
            if ($last_error ne $current_dir
                || STATUS eq "COMPILATION WARNING") {
              $STATUS = "COMPILATION ERROR";
              push @failures, "Error while compiling in $current_dir \n";
              $last_error = $current_dir;
            }
        }
        if (m/warning:/i || m/warning /i) {
          if ($last_error ne $current_dir) {
            if ($STATUS eq "OK") {
              $STATUS = "COMPILATION WARNING";
            }
            push @failures, "Warning while compiling in $current_dir\n";
            $last_error = $current_dir;
          }
        }
    }
    if (close(MAKE) == 0) {
        push @failures, "errors while running make in $i";
    }
    $date = localtime;
    print LOG "$CMD: make for $i finished at ", $date, "\n";
    print LOG "$CMD: =============================================\n\n";
}

if ($dont_run == 0) {
  @LIST = @RUN_LIST; 
  if ($single_threaded) {
    @LIST = @SINGLE_THREADED_LIST;
  } elsif ($minimum_corba) {
    @LIST = @MINIMUM_CORBA_LIST;
  } elsif ($ami) {
      @LIST = @AMI_CORBA_LIST;
  }

  foreach $i (@LIST) {

    $date = localtime;
    print LOG "$CMD: ==================================================\n";
    print LOG "$CMD: running checks in $i at ", $date, "\n";
    local $subdir =
	$CHECKOUT .'/'. $MODULE .'/build/'. $BUILD .'/'. $i;
    chdir ($subdir)
	|| mydie "cannot chdir to $subdir";

    $run_error = 0;
    open(CHECK, "make -k $MAKEFLAGS -C $subdir check 2>&1 |");

    local $current_dir = $i;
    local $last_error = "";
    while (<CHECK>) {
        chop;
        if ($^O eq 'hpux'
            && m/^Warning:[ \t]+[0-9]+ future errors were detected/) {
            next;
        }
        print LOG $_, "\n";

        if (m/^make(\[[0-9]+\])?: Entering directory /) {
            s/^make(\[[0-9]+\])?: Entering directory //;
            $current_dir = $_;
        }
        if (m/error:/i || m/error /i
            || m/^make(\[[0-9]+\])?: \*\*\*/) {
            if ($last_error ne $current_dir
                || STATUS eq "COMPILATION WARNING") {
              $STATUS = "COMPILATION ERROR";
              push @failures, "Error while compiling in $current_dir \n";
              $last_error = $current_dir;
            }
        }
        if (m/warning:/i || m/warning /i) {
          if ($last_error ne $current_dir) {
            if ($STATUS eq "OK") {
              $STATUS = "COMPILATION WARNING";
            }
            push @failures, "Warning while compiling in $current_dir\n";
            $last_error = $current_dir;
          }
        }
	if (m/Error/
	    || m/ERROR/
	    || m/FAILED/
	    || m/failed/
	    || m/FAIL/
	    || m/EXCEPTION/
	    || m/pure virtual /i) {
	  if ($STATUS eq "OK") {
	    $STATUS = "RUNTIME ERROR";
	  }
	  $run_error = 1;
	}
    }

    if (close(CHECK) == 0) {
      if ($STATUS eq "OK") {
	$STATUS = "RUNTIME ERROR";
      }
      push @failures, "Error when closing pipe in $i";
      next;
    }
    $date = localtime;
    print LOG "$CMD: check finished ", $date, "\n";

    if ($run_error != 0) {
      push @failures,
      "errors detected while making check in $i";
    }
  }
}

if ($post_clean) {
  foreach $i (@BUILD_LIST) {
    $date = localtime;
    print LOG "$CMD: ==================================================\n";
    print LOG "$CMD: make clean in $i started at ", $date, "\n";
    open(MAKE, "make -k $MAKEFLAGS -C $i clean 2>&1 |");

    while (<MAKE>) {
      # Ignore errors....
    }
    if (close(MAKE) == 0) {
	push @failures, "errors while cleaning $i";
    }
    $date = localtime;
    print LOG "$CMD: make clean in $i finished at ", $date, "\n";
    print LOG "$CMD: ==================================================\n\n";
  }
}

if ($#failures >= 0) {
  report_errors @failures;
}

close(LOG)
    || mydie "cannot close LOGFILE";

print HIST "$STATUS\n";
close(HIST)
    || mydie "cannot close history file";

unlink $disable_file
    || die "cannot unlink disable file";

if ($report_success && $STATUS eq "OK") {
  report_errors "Congratulations: No errors or warnings detected\n";
}

exit 0;