summaryrefslogtreecommitdiff
path: root/bin/make_pretty.pl
blob: a1e12de934ff165dcf0b309f87e366417dbf5ed0 (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
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
    & eval 'exec perl -S $0 $argv:q'
    if 0;

# $Id$
# Make the build output prettier.

use Getopt::Std;
use English;

if (!getopts ('bc:hm:pt') || $opt_h) {
    print "Output Beautifier\n";
    print "\n";
    print "make_pretty.pl [-bpthr] [-c compiler] [-m msg]\n";
    print "    -b           Brief-ify the output (only errors and warnings)\n";
    print "    -c compiler  Specify the compiler type [msvc (default)/makefile]\n";
    print "    -h           Show this help output\n";
    print "    -m           Message to attach to the end of the output\n";
    print "    -p           Plain text mode (default is html)\n";
    print "    -t           Only give totals for warnings and errors (auto -b)\n";
    exit (1);
}

if (!$opt_c) {
  $opt_c = 'makefile';
  $opt_c = 'msvc' if ($OSNAME eq 'Win32');
}

if ($opt_c ne 'makefile' && $opt_c ne 'msvc') {
    print STDERR "Error: Must specify msvc or makefile as the compiler type\n";
    exit (1);
}

$opt_b = 1 if ($opt_t);

###############################################################################
sub set_html_output ()
{
    $header = "<html>".
              "<head>".
              "<title>Error/Warning Summary of Daily Build</title></head>".
              "<body bgcolor=\"white\">".
              "<h1>Error/Warning Summary of Daily Build</h1>".
              "<TT>\n";

    $trailer = "</TT></body></html>";

    $bookmark_table = "<hr>".
                      "<h2>Quick links</h2>".
                      "<ul>".
                      "<li><a href=\"#cvs\">CVS</a>".
                      "<li><a href=\"#compiler\">Compilation</a>".
                      "<li><a href=\"#tests\">Tests</a>".
                      "</ul>";

    $bookmark_cvs = "<a name=\"cvs\"></a>";
    $bookmark_compiler = "<a name=\"compiler\"></a>";
    $bookmark_tests = "<a name=\"tests\"></a>";

    $pre_section_title = "<H2>";
    $post_section_title = "</H2>";

    $pre_error = "<FONT COLOR=\"FF0000\">";
    $post_error = "</FONT>";

    $pre_warning = "<FONT COLOR=\"FF7700\">";
    $post_warning = "</FONT>";

    $pre_config = "";
    $post_config = "";

    $line_break = "<BR>";
    $separator = "<HR>";
}

sub set_text_output ()
{
    $header = "" ;
    $trailer = "" ;

    $bookmark_table = "";

    $bookmark_cvs = "";
    $bookmark_compiler = "";
    $bookmark_tests = "";

    $pre_section_title = "\n================================================".
                         "================================\n";
    $post_section_title = "\n================================================".
                          "================================\n";

    $pre_error = "";
    $post_error = "";

    $pre_warning = "";
    $post_warning = "";

    $pre_config = "";
    $post_config = "";

    $line_break = "";
    $separator = "------------------------------------------------".
                 "--------------------------------\n";
}

# is_warning checks for warnings.  It returns
# 0 = no warning
# 1 = warning line
# 2 = possible warning
# 3 = false warning
sub is_warning ()
{
    # Look for any warnings we should ignore
    return 3 if (/^LINK : warning LNK4089:/);

    # For some reason, there's a false license warning
    return 3 if (/\(W\).*Compilation will proceed shortly./);

    # AIX reports a bazillion multiple defines when doing templates.
    return 3 if (m/^ld: \d+\-\d+ WARNING: Duplicate symbol:/);

    # HP-UX uses 'nocompatwarnings' as an option to the compiler.
    return 3 if (m/vnocompatwarnings/);

    # SUN CC 5.0 defines __pthread_cleanup_push as a macro which causes
    # warnings. See /usr/include/pthread.h and
    # $ACE_ROOT/examples/Timer_Queue/Thread_Timer_Queue_Test.cpp for more
    # information.
    return 0 if (m/in call to __pthread_cleanup_push\(extern/);

    # Look for lines that also should be color coded, but not counted
    # as warnings.
    return 2 if (/see declaration of/);

    # Look for warnings

    return 1 if ((/warning/i && !/ warning\(s\)/)
                 || /info: /i
                 || /^make.*\*\*\*/
                 || /^error \(future\)/i);

    if (/^.*\.h: /
        || /^.*\.i: /
        || /^.*\.inl: /
        || /^.*\.cpp: /
        || /^.*\.java: /) {
      return 1;
    }

    # IBM's compilers don't say the word "warning" - check for their code
    return 1 if (m/^.*\d+\-\d+:? \(W\)/);

    # didn't find anything
    return 0;
}

# is_error checks for errors. It returns
# 0 = no error
# 1 = error line
# 2 = possible error
# 3 = false errors
sub is_error ()
{
    # Look for any errors we should ignore

    # AIX reports a bazillion multiple defines when doing templates; some
    # have the word 'error' in the symbol name - ignore those.
    return 0 if (m/^ld: \d+\-\d+ WARNING: Duplicate symbol:/);

    # Linux has this annoying mktemp, mkstemp stuff. Ignore that
    # for the timebeing
    return 0 if (/is dangerous, better use/);

    # Look for lines that also should be color coded, but not counted
    # as errors.
    return 2 if (/Types pointed to are unrelated/
                 || /while compiling class-template/
                 || /requires an explicit cast/);

    if (/^.*:[0-9]+: /
        && !/^.*:[0-9]+: warning:/) {
      return 1;
    }

    # AIX linking errors from ld
    # But don't report the extra "check the map" message
    return 0 if (/^ld: 0711\-345/);
    return 1 if (/^ld: \d+\-\d+/);

    # Look for linking errors too
    return 1 if (/undefined reference to/
                 || /: cannot open/
                 || /: multiple definition of/
                 || /path name does not exist/);

    # Look for possible errors
    return 1 if ((/error/i && !/ error\(s\), / && !/error \(future\)/i)
                 || /^Fatal\:/
                 || /: fatal:/);

    # Again, IBM's compilers speak in code langauge
    if (m/.*\d+\-\d+:? \([SI]\)/) {
        # Ignore licensing messages
        return 3 if (/.*Compilation will proceed shortly./);
        return 1;
    }

    # didn't find anything
    return 0;
}

sub print_build_header ($$)
{
    my $directory = shift;
    my $config = shift;

    print "$separator$line_break";
    print "$pre_config$directory$post_config$line_break\n";
    print "$pre_config$config$post_config$line_break$line_break";
}

################################################################################
sub cvs_output ()
{
    my $patched = 0;
    my $updated = 0;
    my $modified = 0;
    my $conflicts = 0;
    my $unknown = 0;

    if (!$opt_t) {
        print $separator;
        print $bookmark_cvs;
        print $pre_section_title."CVS".$post_section_title;
    }

    LOOP: while (<>) {
        ++$patched if (/^P /);
        ++$updated if (/^U /);
        ++$modified if (/^M /);
        ++$conflicts if (/^C /);
        ++$unknown if (/^\? /);

        ### Isn't really a conflict, but easiest place to put it.
        ++$conflicts if (/aborted/);

        last LOOP if (/^####################/);

        if ($opt_t) {
        }
        elsif (/aborted/) {
            print "$pre_error$_$post_error$line_break";
        }
        elsif (/^C /) {
            print "$pre_error$_$post_error$line_break";
        }
        elsif  (/^M /) {
            print "$pre_warning$_$post_warning$line_break";
        }
        elsif (!$opt_b) {
            print "$_$line_break";
        }
    }

    print $line_break;
    print "\nCVS Totals: ";
    print " Patched: $patched  Updated:$updated  Modified: $modified ".
          " Conflicts: $conflicts Unknown: $unknown\n\n$line_break";
}

sub msvc_compiler_output ()
{
    my $project = "NULL";
    my $configuration = "NULL";
    my $dsp = "NULL";
    my $first_problem = 1;
    my $total_warnings = 0;
    my $total_errors = 0;
    my $bogus_warnings = 0;
    my $bogus_errors = 0;

    if (!$opt_t) {
        print $separator;
        print $bookmark_compiler;
        print $pre_section_title."Compilation".$post_section_title;
    }

    LOOP: while (<>)
    {
        last LOOP if (/^####################/);

        s/</&lt;/g if !$opt_p;
        s/>/&gt;/g if !$opt_p;

        my $is_warning = is_warning ();
        my $is_error = is_error ();

        if (/^Auto_compiling (.*)/) {
            print "$separator$line_break$pre_config$_$post_config$line_break"
                if (!$opt_b && !$opt_t);
            $dsp = $1;
            $first_problem = 1;
        }
        elsif (/^--------------------Configuration: (.*) - (.*)--------------------/) {
            print $pre_config.$_.$post_config.$line_break
                if (!$opt_b && !$opt_t);
            $project = $1;
            $configuration = $2;
            $first_problem = 1;
        }
        elsif (/\- (.*) error\(s\)\, (.*) warning\(s\)/) {
            my $errors = $1 - $bogus_errors;
            my $warnings = $2 - $bogus_warnings;
            print "$project - $errors error(s), $warnings warnings(s)$line_break\n"
                if (!$opt_b || ($opt_t && ($errors > 0 || $warnings > 0)));
            $total_errors = $total_errors + $errors;
            $total_warnings = $total_warnings +$warnings;

            $bogus_warnings = 0;
            $bogus_errors = 0;
        }
        elsif ($is_error == 3) {
            ++$bogus_errors;
        }
        elsif ($is_error == 2 || $is_error == 1) {
            if (!$opt_t) {
                print_build_header ($dsp, "$project: $configuration")
                    if ($first_problem && $opt_b);
                $first_problem = 0;
                print "$pre_error$_$post_error$line_break";
            }
        }
        elsif ($is_warning == 3) {
            ++$bogus_warnings;
        }
        elsif ($is_warning == 2 || $is_warning == 1) {
            if (!$opt_t) {
                print_build_header ($dsp, "$project: $configuration")
                    if ($first_problem && $opt_b);
                $first_problem = 0;
                print "$pre_warning$_$post_warning$line_break";
            }
        }
        else
        {
            print "$_$line_break"
                if (!$opt_b && !$opt_t);
        }
    }
    print $line_break;
    print "\nCompiler Totals: ";
    print " Errors: $total_errors  Warnings: $total_warnings\n\n$line_break";
}

sub makefile_compiler_output ()
{
    local $directory = 'NULL';
    my $first_problem = 1;
    local $total_warnings = 0;
    local $total_errors = 0;
    local $project_warnings = 0;
    local $project_errors = 0;

    if (!$opt_t) {
        print $separator;
        print $bookmark_compiler;
        print $pre_section_title."Compilation".$post_section_title;
    }

    sub print_summary ()
    {
        print $_.$line_break if (!$opt_b);
        $total_errors = $total_errors + $project_errors;
        $total_warnings = $total_warnings + $project_warnings;
        $project_errors = 0;
        $project_warnings = 0;
        $directory = 'NULL';
    }

    sub set_directory ($)
    {
        my $dir = shift;

        # Strip off the ACE_wrappers stuff
        if ($dir =~ /ACE_wrappers\/build\/[^\/]*\/(.*)/) {
            $dir = $1;
        }
        elsif ($dir =~ /ACE_wrappers\/(.*)/) {
            $dir = $1;
        }

        # Strip of trailing '

        if ($dir =~ /(.*)\'$/) {
            $dir = $1;
        }

        $directory = $dir;
    }

    LOOP: while (<>)
    {
        last LOOP if (/^####################/);

        s/</&lt;/g if !$opt_p;
        s/>/&gt;/g if !$opt_p;

        my $is_warning = is_warning ();
        my $is_error = is_error ();

        if (/Entering directory (.*)/) {
            print_summary () if ($directory ne 'NULL');

            print $pre_config.$1.$post_config."\n".$line_break
                if (!$opt_b && !$opt_t);
            set_directory ($1);
            $first_problem = 1;

        }
        elsif ($is_error == 3) {
            # Do Nothing
        }
        elsif ($is_error == 2 || $is_error == 1) {
            if (!$opt_t) {
                print_build_header ($directory, "")
                    if ($first_problem && $opt_b);
                $first_problem = 0;
                print "$pre_error$_$post_error$line_break";
            }
            if ($is_error == 1) {
                ++$project_errors;
            }
        }
        elsif ($is_warning == 3) {
            # Do Nothing
        }
        elsif ($is_warning == 2 || $is_warning == 1) {
            if (!$opt_t) {
                print_build_header ($directory, "")
                    if ($first_problem && $opt_b);
                $first_problem = 0;
                print "$pre_warning$_$post_warning$line_break";
            }
            if ($is_warning == 1) {
                ++$project_warnings;
            }
        }
        else
        {
            print "$_$line_break"
                if (!$opt_b && !$opt_t);
        }
    }
    print_summary () if ($directory ne 'NULL');
    print $line_break;
    print "\nCompiler Totals: ";
    print " Errors: $total_errors  Warnings: $total_warnings\n\n$line_break";
}

sub tests_output ()
{
    local $first_problem = 1;
    local $run_test = 'NULL';
    local $tests_failed = 0;

    sub check_result ()
    {
        if ($first_problem == 0) {
            if ($opt_t) {
                print $pre_error."Failure in $run_test\n".$post_error.$line_break;
            }
            ++$tests_failed;
        }
    }

    if (!$opt_t) {
        print $separator;
        print $bookmark_tests;
        print $pre_section_title."Tests".$post_section_title;
    }

    LOOP: while (<>) {
        last LOOP if (/^####################/);

        s/</&lt;/g if !$opt_p;
        s/>/&gt;/g if !$opt_p;

        if (/auto_run_tests: (.*)/) {
            check_result ();

            print $pre_config.$1.$post_config."\n".$line_break
                if (!$opt_b && !$opt_t);
            $run_test = $1;
            $first_problem = 1;
        }
        elsif (m/Error/
               || m/ERROR/
               || m/FAILED/
               || m/EXCEPTION/
               || m/pure virtual /i) {
            if (!$opt_t) {
                print_build_header ($run_test, "") if ($first_problem && $opt_b);
                print "$pre_error$_$post_error$line_break";
            }
            $first_problem = 0;
        }
        else
        {
            print "$_$line_break"
                if (!$opt_b && !$opt_t);
        }
    }
    check_result ();

    print $line_break;
    print "\nTest Failures: $tests_failed\n\n$line_break";
}

##############################################################################
if ($opt_p) {
    set_text_output ();
}
else {
    set_html_output ();
}

print $header;
print $bookmark_table;

LOOP: while (<>) {
   last LOOP if (/^####################/);
}

cvs_output ();

makefile_compiler_output () if ($opt_c eq 'makefile');
msvc_compiler_output () if ($opt_c eq 'msvc');

tests_output ();

print "$line_break\n\n$opt_m\n\n$line_break" if $opt_m;
print $trailer;