xref: /trunk/main/sal/qa/buildall.pl (revision cdf0e10c)
1eval 'exec perl -wS $0 ${1+"$@"}'
2    if 0;
3#*************************************************************************
4#
5# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6#
7# Copyright 2000, 2010 Oracle and/or its affiliates.
8#
9# OpenOffice.org - a multi-platform office productivity suite
10#
11# This file is part of OpenOffice.org.
12#
13# OpenOffice.org is free software: you can redistribute it and/or modify
14# it under the terms of the GNU Lesser General Public License version 3
15# only, as published by the Free Software Foundation.
16#
17# OpenOffice.org is distributed in the hope that it will be useful,
18# but WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20# GNU Lesser General Public License version 3 for more details
21# (a copy is included in the LICENSE file that accompanied this code).
22#
23# You should have received a copy of the GNU Lesser General Public License
24# version 3 along with OpenOffice.org.  If not, see
25# <http://www.openoffice.org/license.html>
26# for a copy of the LGPLv3 License.
27#
28#************************************************************************
29
30# #!/usr/bin/perl -w
31
32use strict;
33use POSIX;
34use Cwd;
35use File::Path;
36use English;
37use Cwd 'chdir';
38
39my $cwd = getcwd();
40
41# Prototypes
42sub initEnvironment();
43sub main($);
44sub checkForKillobj();
45sub checkARGVFor($);
46
47my $g_sTempDir = "";
48my $FS = "";
49
50my $nGlobalFailures = 0;
51
52my %libraryRunThrough;
53my $bBuildAll = 0;
54
55# LLA: this does not exist, ... use a little bit simpler method.
56# use File::Temp qw/ :POSIX /;
57
58my $params;
59my $param;
60
61if ($#ARGV < 0)
62{
63    $params = "test "; # debug=t TESTOPTADD=\"-boom\"   TESTOPTADD=\"-noerroronexit\"
64
65    # my $nNumber = 55;
66    # my $sLocalParams = $params;
67    # $sLocalParams =~ s/test\s/test$nNumber /;
68    # print "Testparams: $sLocalParams\n";
69    # exit 1;
70    print "Default ";
71}
72else
73{
74    # special hack!
75    if (checkForKillobj() == 1)
76    {
77        $params = "killobj";
78    }
79    elsif (checkARGVFor("buildall") == 1)
80    {
81        $bBuildAll = 1;
82        $params = "test";
83    }
84    else
85    {
86        # always run test, but envelope the other in 'TESTOPT="..."'
87        $params = "test TESTOPT=\"";
88
89        foreach $param (@ARGV)
90        {
91            $params = $params . " " . $param;
92        }
93        $params = $params . "\"";
94    }
95    print "User defined ";
96}
97
98print "parameters for dmake: $params\n";
99
100initEnvironment();
101main($params);
102
103# ------------------------------------------------------------------------------
104sub checkARGVFor($)
105{
106    my $sCheckValue = shift;
107    my $sLocalParam;
108    my $nBackValue = 0;
109    foreach $sLocalParam (@ARGV)
110    {
111        if ($sLocalParam =~ /^${sCheckValue}$/)
112        {
113            $nBackValue = 1;
114            last;
115        }
116    }
117    return $nBackValue;
118}
119# ------------------------------------------------------------------------------
120sub checkForKillobj()
121{
122    my $sLocalParam;
123    my $nBackValue = 0;
124    foreach $sLocalParam (@ARGV)
125    {
126        if ($sLocalParam =~ /^killobj$/)
127        {
128            $nBackValue = 1;
129            last;
130        }
131    }
132    return $nBackValue;
133}
134
135# ------------------------------------------------------------------------------
136sub initEnvironment()
137{
138    my $gui = $ENV{GUI};
139    # no error output in forms of message boxes
140    $ENV{'DISABLE_SAL_DBGBOX'}="t";
141
142  SWITCH: {
143      if ( $gui eq "WNT" ) {
144          $FS             = "\\";
145          $g_sTempDir         = $ENV{TMP}  ? "$ENV{TMP}${FS}" : "c:${FS}tmp${FS}";
146          last SWITCH;
147      }
148      if ( $gui eq "WIN" ) {
149          $FS             = "\\";
150          $g_sTempDir         = $ENV{TMP}  ? "$ENV{TMP}${FS}" : "c:${FS}tmp${FS}";
151          last SWITCH;
152      }
153      if ( $gui eq "OS2" ) {
154          $FS             = "\\";
155          $g_sTempDir         = $ENV{TMP}  ? "$ENV{TMP}${FS}" : "c:${FS}tmp${FS}";
156          last SWITCH;
157      }
158      if ( $gui eq "UNX" ) {
159          $FS             = "/";
160          $g_sTempDir         = $ENV{TMP}  ? "$ENV{TMP}${FS}" : "${FS}tmp${FS}";
161          last SWITCH;
162      }
163      print STDERR "buildall.pl: unkown platform\n";
164      exit(1);
165  }
166}
167# ------------------------------------------------------------------------------
168
169sub trim($)
170{
171    my $oldstr = shift;
172    $oldstr =~ s/^\s*(.*?)\s*$/$1/;
173    return $oldstr;
174}
175
176# ------------------------------------------------------------------------------
177sub getLibName($)
178{
179    my $sFile = shift;
180    if ($OSNAME eq "linux" || $OSNAME eq "solaris")
181    {
182        return "lib" . $sFile . ".so";
183    }
184    if ($OSNAME eq "MSWin32" || $OSNAME eq "OS2")
185    {
186        return $sFile . ".dll";
187    }
188    return $sFile;
189}
190# ------------------------------------------------------------------------------
191sub giveOutAll($)
192{
193    my $sFailureFile = shift;
194    local *IN;
195    if (! open(IN, $sFailureFile))
196    {
197        print "ERROR: Can't open output file $sFailureFile\n";
198        return;
199    }
200    my $line;
201    while ($line = <IN>)
202    {
203        chomp($line);
204        print "$line\n";
205    }
206    close(IN);
207}
208# ------------------------------------------------------------------------------
209sub giveOutFailures($$)
210{
211    my $sTest = shift;
212    my $sFailureFile = shift;
213
214    my $bBegin = 0;
215    my $nFailures = 0;
216
217    my $line;
218    local *IN;
219    if (! open(IN, $sFailureFile))
220    {
221        print "ERROR: Can't open output file $sFailureFile\n";
222        return;
223    }
224
225    my $bStartUnitTest = 0;
226    while ($line = <IN>)
227    {
228        chomp($line);
229        if ( $line =~ /^- start unit test/)
230        {
231            $bStartUnitTest = 1;
232        }
233    }
234    close(IN);
235
236    if ($bStartUnitTest == 0)
237    {
238        print "\nFailure: Unit test not started. Maybe compiler error.\n";
239        giveOutAll($sFailureFile);
240        $nFailures++;
241        # exit(1);
242    }
243    else
244    {
245        open(IN, $sFailureFile);
246        # check if testshl2 was started
247        while ($line = <IN>)
248        {
249            chomp($line);
250
251            # handling of the states
252            if ( $line =~ /^\# -- BEGIN:/)
253            {
254                $bBegin = 1;
255            }
256            elsif ( $line =~ /^\# -- END:/)
257            {
258                $bBegin = 0;
259            }
260            else
261            {
262                if ($bBegin == 1)
263                {
264                    print "$line\n";
265                    $nFailures++;
266                }
267            }
268        }
269        close(IN);
270    }
271
272    if ($nFailures > 0)
273    {
274        # extra return for a better output
275        print "\nFailures occured: $nFailures\n";
276        print "The whole output can be found in $sFailureFile\n";
277        print "\n";
278
279        # Statistics
280        $nGlobalFailures += $nFailures;
281    }
282}
283# ------------------------------------------------------------------------------
284sub printOnLibrary($)
285{
286    my $sTarget = shift;
287    print "       on library: " . getLibName($sTarget);
288}
289# ------------------------------------------------------------------------------
290sub runASingleTest($$)
291{
292    my $sTarget = shift;
293    my $params = shift;
294    my $dmake = "dmake $params";
295
296    my $sLogPath = $g_sTempDir . "dmake_out_$$";
297    mkdir($sLogPath);
298    my $sLogFile = $sLogPath . "/" . $sTarget . ".out";
299
300    # due to the fact, a library name in one project is distinct, we should remember all already run through libraries and
301    # supress same libraries, if they occur one more.
302
303    if (exists $libraryRunThrough{getLibName($sTarget)})
304    {
305        # already done
306        return;
307    }
308    printOnLibrary($sTarget);
309    print "\n";
310
311# redirect tcsh ">&" (stdout, stderr)
312# redirect 4nt   ">" (stdout), "2>" (stderr)
313# print "OSNAME: $OSNAME\n";
314# LLA: redirect check canceled, seems to be not work as I want.
315#     my $redirect = "";
316#     if ($OSNAME eq "linux" || $OSNAME eq "solaris")
317#     {
318#         # print "UNIX, linux or solaris\n";
319#         $redirect = '>>&!' . $sLogFile;
320#     }
321#     else
322#     {
323#         if ($OSNAME eq "MSWin32" || $OSNAME eq "OS2")
324#         {
325#             # test
326#             $redirect = ">>$sLogFile 2>>$sLogFile";
327#         }
328#     }
329#     print "$dmake $redirect\n";
330
331# LLA: so system does also not work as I imagine
332#    system("$dmake $redirect");
333
334# LLA: next check, use open with pipe
335
336    local *LOGFILE;
337    if (! open( LOGFILE, '>' . "$sLogFile"))
338    {
339        print "ERROR: can't open logfile: $sLogFile\n";
340        return;
341    }
342
343    my $line;
344    local *DMAKEOUTPUT;
345    if (! open( DMAKEOUTPUT, "$dmake 2>&1 |"))
346    {
347        print "ERROR: can't open dmake\n";
348        return;
349    }
350    while ($line = <DMAKEOUTPUT>)
351    {
352        chomp($line);
353        print LOGFILE "$line\n";
354    }
355    close(DMAKEOUTPUT);
356    close(LOGFILE);
357
358    giveOutFailures($sTarget, $sLogFile);
359
360    $libraryRunThrough{getLibName($sTarget)} = "done";
361}
362
363# ------------------------------------------------------------------------------
364sub interpretLine($)
365{
366    my $line = shift;
367
368    my $path;
369    my $file;
370
371    if ($line =~ /^\#/ || $line =~ /^$/)
372    {
373        # remark or empty line
374    }
375    else
376    {
377        # special format, $file == $path
378        ($path, $file) = split(/;/, $line);
379        if (! $file)
380        {
381            $file = $path;
382        }
383        $file = trim($file);
384        $path = trim($path);
385    }
386    return $path, $file;
387}
388# ------------------------------------------------------------------------------
389sub runTestsOnPath($$$)
390{
391    my $path = shift;
392    my $file = shift;
393    my $params = shift;
394
395    # empty values
396    if (!$path || $path eq "")
397    {
398        # DBG: print "empty path '$path'\n";
399        return;
400    }
401    if (!$file || $file eq "")
402    {
403        # DBG: print "empty file '$file'\n";
404        return;
405    }
406
407#   print "File: '$file', Path: '$path'\n";
408    print "Work in directory: $path\n";
409    my $newpath = $cwd . $FS . $path;
410#   print "chdir to $newpath\n";
411
412    my $error = chdir($newpath);
413    cwd();
414
415    # run through the hole makefile.mk and check if SHL<D>TARGET = ... exist, for every target call "dmake test<D>"
416
417    local *MAKEFILE_MK;
418    if (! open(MAKEFILE_MK, "makefile.mk"))
419    {
420        print "ERROR: can't open makefile.mk in path: $newpath\n";
421        print "please check your libs2test.txt file in qa directory.\n";
422    }
423    my $line;
424    my $nNumber;
425    my $sTarget;
426    my $sLocalParams;
427
428    while($line = <MAKEFILE_MK>)
429    {
430        chomp($line);
431
432        if ($line =~ /SHL(\d)TARGET=(.*)/)
433        {
434            $nNumber = $1;
435            $sTarget = trim($2);
436
437            # DBG: print "test$number is lib: $target\n";
438            $sLocalParams = $params . " ";                  # append a whitespace, so we can check if 'test' exist without additional digits
439            $sLocalParams =~ s/test\s/test$nNumber/;
440            # DBG: print "$sLocalParams\n";
441            if ($bBuildAll == 1 ||
442                $file eq $sTarget)
443            {
444                # print "runASingleTest on Target: $sTarget 'dmake $sLocalParams'\n";
445                runASingleTest($sTarget, $sLocalParams);
446            }
447            else
448            {
449                # printOnLibrary($sTarget);
450                # print " suppressed, not in libs2test.txt\n";
451            }
452        }
453    }
454    close(MAKEFILE_MK);
455}
456
457# ------------------------------------------------------------------------------
458
459sub main($)
460{
461    my $params = shift;
462#    my $sLogFile = shift;     # "buildall_$$.out";
463    local *LIBS2TEST;
464    my $filename = "libs2test.txt";
465    my $line;
466
467    open(LIBS2TEST, $filename) || die "can't open $filename\n";
468
469    while($line = <LIBS2TEST>)
470    {
471        chomp($line);
472        # DOS Hack grrrr...
473        while ($line =~ /
474$/)
475        {
476            $line = substr($line, 0, -1);
477        }
478
479        # print "$line\n";
480        my $path;
481        my $file;
482        ($path, $file) = interpretLine($line);
483        runTestsOnPath($path, $file, $params);
484    }
485    close(LIBS2TEST);
486
487    print "\nComplete logging information will be found in dir: ".$g_sTempDir."dmake_out_$$/\n";
488
489    if ($nGlobalFailures > 0)
490    {
491        print "\nFailures over all occured: $nGlobalFailures\n";
492        print "\nPASSED FAILED.\n";
493    }
494    else
495    {
496        print "\nPASSED OK.\n";
497    }
498}
499
500# ------------------------------------------------------------------------------
501
502# TODO:
503# -verbose
504# -fan   - \ | /
505
506# END!
507
508