Bump for 3.6-28
[LibreOffice.git] / sal / qa / buildall.pl
blob02fc352bba89a7eb5030bb02902a98214a8dd15c
1 eval 'exec perl -wS $0 ${1+"$@"}'
2 if 0;
3 #*************************************************************************
5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 # Copyright 2000, 2010 Oracle and/or its affiliates.
9 # OpenOffice.org - a multi-platform office productivity suite
11 # This file is part of OpenOffice.org.
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.
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).
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.
28 #************************************************************************
30 # #!/usr/bin/perl -w
32 use strict;
33 use POSIX;
34 use Cwd;
35 use File::Path;
36 use English;
37 use Cwd 'chdir';
39 my $cwd = getcwd();
41 # Prototypes
42 sub initEnvironment();
43 sub main($);
44 sub checkForKillobj();
45 sub checkARGVFor($);
47 my $g_sTempDir = "";
48 my $FS = "";
50 my $nGlobalFailures = 0;
52 my %libraryRunThrough;
53 my $bBuildAll = 0;
55 # LLA: this does not exist, ... use a little bit simpler method.
56 # use File::Temp qw/ :POSIX /;
58 my $params;
59 my $param;
61 if ($#ARGV < 0)
63 $params = "test "; # debug=t TESTOPTADD=\"-boom\" TESTOPTADD=\"-noerroronexit\"
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 ";
72 else
74 # special hack!
75 if (checkForKillobj() == 1)
77 $params = "killobj";
79 elsif (checkARGVFor("buildall") == 1)
81 $bBuildAll = 1;
82 $params = "test";
84 else
86 # always run test, but envelope the other in 'TESTOPT="..."'
87 $params = "test TESTOPT=\"";
89 foreach $param (@ARGV)
91 $params = $params . " " . $param;
93 $params = $params . "\"";
95 print "User defined ";
98 print "parameters for dmake: $params\n";
100 initEnvironment();
101 main($params);
103 # ------------------------------------------------------------------------------
104 sub checkARGVFor($)
106 my $sCheckValue = shift;
107 my $sLocalParam;
108 my $nBackValue = 0;
109 foreach $sLocalParam (@ARGV)
111 if ($sLocalParam =~ /^${sCheckValue}$/)
113 $nBackValue = 1;
114 last;
117 return $nBackValue;
119 # ------------------------------------------------------------------------------
120 sub checkForKillobj()
122 my $sLocalParam;
123 my $nBackValue = 0;
124 foreach $sLocalParam (@ARGV)
126 if ($sLocalParam =~ /^killobj$/)
128 $nBackValue = 1;
129 last;
132 return $nBackValue;
135 # ------------------------------------------------------------------------------
136 sub initEnvironment()
138 my $gui = $ENV{GUI};
139 # no error output in forms of message boxes
140 $ENV{'DISABLE_SAL_DBGBOX'}="t";
142 SWITCH: {
143 if ( $gui eq "WNT" ) {
144 $FS = "\\";
145 $g_sTempDir = $ENV{TMP} ? "$ENV{TMP}${FS}" : "c:${FS}tmp${FS}";
146 last SWITCH;
148 if ( $gui eq "WIN" ) {
149 $FS = "\\";
150 $g_sTempDir = $ENV{TMP} ? "$ENV{TMP}${FS}" : "c:${FS}tmp${FS}";
151 last SWITCH;
153 if ( $gui eq "UNX" ) {
154 $FS = "/";
155 $g_sTempDir = $ENV{TMP} ? "$ENV{TMP}${FS}" : "${FS}tmp${FS}";
156 last SWITCH;
158 print STDERR "buildall.pl: unkown platform\n";
159 exit(1);
162 # ------------------------------------------------------------------------------
164 sub trim($)
166 my $oldstr = shift;
167 $oldstr =~ s/^\s*(.*?)\s*$/$1/;
168 return $oldstr;
171 # ------------------------------------------------------------------------------
172 sub getLibName($)
174 my $sFile = shift;
175 if ($OSNAME eq "linux" || $OSNAME eq "solaris")
177 return "lib" . $sFile . ".so";
179 if ($OSNAME eq "MSWin32")
181 return $sFile . ".dll";
183 return $sFile;
185 # ------------------------------------------------------------------------------
186 sub giveOutAll($)
188 my $sFailureFile = shift;
189 local *IN;
190 if (! open(IN, $sFailureFile))
192 print "ERROR: Can't open output file $sFailureFile\n";
193 return;
195 my $line;
196 while ($line = <IN>)
198 chomp($line);
199 print "$line\n";
201 close(IN);
203 # ------------------------------------------------------------------------------
204 sub giveOutFailures($$)
206 my $sTest = shift;
207 my $sFailureFile = shift;
209 my $bBegin = 0;
210 my $nFailures = 0;
212 my $line;
213 local *IN;
214 if (! open(IN, $sFailureFile))
216 print "ERROR: Can't open output file $sFailureFile\n";
217 return;
220 my $bStartUnitTest = 0;
221 while ($line = <IN>)
223 chomp($line);
224 if ( $line =~ /^- start unit test/)
226 $bStartUnitTest = 1;
229 close(IN);
231 if ($bStartUnitTest == 0)
233 print "\nFailure: Unit test not started. Maybe compiler error.\n";
234 giveOutAll($sFailureFile);
235 $nFailures++;
236 # exit(1);
238 else
240 open(IN, $sFailureFile);
241 # check if testshl2 was started
242 while ($line = <IN>)
244 chomp($line);
246 # handling of the states
247 if ( $line =~ /^\# -- BEGIN:/)
249 $bBegin = 1;
251 elsif ( $line =~ /^\# -- END:/)
253 $bBegin = 0;
255 else
257 if ($bBegin == 1)
259 print "$line\n";
260 $nFailures++;
264 close(IN);
267 if ($nFailures > 0)
269 # extra return for a better output
270 print "\nFailures occurred: $nFailures\n";
271 print "The whole output can be found in $sFailureFile\n";
272 print "\n";
274 # Statistics
275 $nGlobalFailures += $nFailures;
278 # ------------------------------------------------------------------------------
279 sub printOnLibrary($)
281 my $sTarget = shift;
282 print " on library: " . getLibName($sTarget);
284 # ------------------------------------------------------------------------------
285 sub runASingleTest($$)
287 my $sTarget = shift;
288 my $params = shift;
289 my $dmake = "dmake $params";
291 my $sLogPath = $g_sTempDir . "dmake_out_$$";
292 mkdir($sLogPath);
293 my $sLogFile = $sLogPath . "/" . $sTarget . ".out";
295 # due to the fact, a library name in one project is distinct, we should remember all already run through libraries and
296 # supress same libraries, if they occur one more.
298 if (exists $libraryRunThrough{getLibName($sTarget)})
300 # already done
301 return;
303 printOnLibrary($sTarget);
304 print "\n";
306 # redirect tcsh ">&" (stdout, stderr)
307 # redirect 4nt ">" (stdout), "2>" (stderr)
308 # print "OSNAME: $OSNAME\n";
309 # LLA: redirect check canceled, seems to be not work as I want.
310 # my $redirect = "";
311 # if ($OSNAME eq "linux" || $OSNAME eq "solaris")
313 # # print "UNIX, linux or solaris\n";
314 # $redirect = '>>&!' . $sLogFile;
316 # else
318 # if ($OSNAME eq "MSWin32")
320 # # test
321 # $redirect = ">>$sLogFile 2>>$sLogFile";
324 # print "$dmake $redirect\n";
326 # LLA: so system does also not work as I imagine
327 # system("$dmake $redirect");
329 # LLA: next check, use open with pipe
331 local *LOGFILE;
332 if (! open( LOGFILE, '>' . "$sLogFile"))
334 print "ERROR: can't open logfile: $sLogFile\n";
335 return;
338 my $line;
339 local *DMAKEOUTPUT;
340 if (! open( DMAKEOUTPUT, "$dmake 2>&1 |"))
342 print "ERROR: can't open dmake\n";
343 return;
345 while ($line = <DMAKEOUTPUT>)
347 chomp($line);
348 print LOGFILE "$line\n";
350 close(DMAKEOUTPUT);
351 close(LOGFILE);
353 giveOutFailures($sTarget, $sLogFile);
355 $libraryRunThrough{getLibName($sTarget)} = "done";
358 # ------------------------------------------------------------------------------
359 sub interpretLine($)
361 my $line = shift;
363 my $path;
364 my $file;
366 if ($line =~ /^\#/ || $line =~ /^$/)
368 # remark or empty line
370 else
372 # special format, $file == $path
373 ($path, $file) = split(/;/, $line);
374 if (! $file)
376 $file = $path;
378 $file = trim($file);
379 $path = trim($path);
381 return $path, $file;
383 # ------------------------------------------------------------------------------
384 sub runTestsOnPath($$$)
386 my $path = shift;
387 my $file = shift;
388 my $params = shift;
390 # empty values
391 if (!$path || $path eq "")
393 # DBG: print "empty path '$path'\n";
394 return;
396 if (!$file || $file eq "")
398 # DBG: print "empty file '$file'\n";
399 return;
402 # print "File: '$file', Path: '$path'\n";
403 print "Work in directory: $path\n";
404 my $newpath = $cwd . $FS . $path;
405 # print "chdir to $newpath\n";
407 my $error = chdir($newpath);
408 cwd();
410 # run through the hole makefile.mk and check if SHL<D>TARGET = ... exist, for every target call "dmake test<D>"
412 local *MAKEFILE_MK;
413 if (! open(MAKEFILE_MK, "makefile.mk"))
415 print "ERROR: can't open makefile.mk in path: $newpath\n";
416 print "please check your libs2test.txt file in qa directory.\n";
418 my $line;
419 my $nNumber;
420 my $sTarget;
421 my $sLocalParams;
423 while($line = <MAKEFILE_MK>)
425 chomp($line);
427 if ($line =~ /SHL(\d)TARGET=(.*)/)
429 $nNumber = $1;
430 $sTarget = trim($2);
432 # DBG: print "test$number is lib: $target\n";
433 $sLocalParams = $params . " "; # append a whitespace, so we can check if 'test' exist without additional digits
434 $sLocalParams =~ s/test\s/test$nNumber/;
435 # DBG: print "$sLocalParams\n";
436 if ($bBuildAll == 1 ||
437 $file eq $sTarget)
439 # print "runASingleTest on Target: $sTarget 'dmake $sLocalParams'\n";
440 runASingleTest($sTarget, $sLocalParams);
442 else
444 # printOnLibrary($sTarget);
445 # print " suppressed, not in libs2test.txt\n";
449 close(MAKEFILE_MK);
452 # ------------------------------------------------------------------------------
454 sub main($)
456 my $params = shift;
457 # my $sLogFile = shift; # "buildall_$$.out";
458 local *LIBS2TEST;
459 my $filename = "libs2test.txt";
460 my $line;
462 open(LIBS2TEST, $filename) || die "can't open $filename\n";
464 while($line = <LIBS2TEST>)
466 chomp($line);
467 # DOS Hack grrrr...
468 while ($line =~ /
471 $line = substr($line, 0, -1);
474 # print "$line\n";
475 my $path;
476 my $file;
477 ($path, $file) = interpretLine($line);
478 runTestsOnPath($path, $file, $params);
480 close(LIBS2TEST);
482 print "\nComplete logging information will be found in dir: ".$g_sTempDir."dmake_out_$$/\n";
484 if ($nGlobalFailures > 0)
486 print "\nFailures over all occurred: $nGlobalFailures\n";
487 print "\nPASSED FAILED.\n";
489 else
491 print "\nPASSED OK.\n";
495 # ------------------------------------------------------------------------------
497 # TODO:
498 # -verbose
499 # -fan - \ | /
501 # END!