Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / sal / qa / buildall.pl
blob20f4dfa4aa047a2a9def8574ec660150926f0007
1 eval 'exec perl -wS $0 ${1+"$@"}'
2 if 0;
4 # This file is part of the LibreOffice project.
6 # This Source Code Form is subject to the terms of the Mozilla Public
7 # License, v. 2.0. If a copy of the MPL was not distributed with this
8 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 # This file incorporates work covered by the following license notice:
12 # Licensed to the Apache Software Foundation (ASF) under one or more
13 # contributor license agreements. See the NOTICE file distributed
14 # with this work for additional information regarding copyright
15 # ownership. The ASF licenses this file to you under the Apache
16 # License, Version 2.0 (the "License"); you may not use this file
17 # except in compliance with the License. You may obtain a copy of
18 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 # #!/usr/bin/perl -w
23 use strict;
24 use POSIX;
25 use Cwd;
26 use File::Path;
27 use English;
28 use Cwd 'chdir';
30 my $cwd = getcwd();
32 # Prototypes
33 sub initEnvironment();
34 sub main($);
35 sub checkForKillobj();
36 sub checkARGVFor($);
38 my $g_sTempDir = "";
39 my $FS = "";
41 my $nGlobalFailures = 0;
43 my %libraryRunThrough;
44 my $bBuildAll = 0;
46 # LLA: this does not exist, ... use a little bit simpler method.
47 # use File::Temp qw/ :POSIX /;
49 my $params;
50 my $param;
52 if ($#ARGV < 0)
54 $params = "test "; # debug=t TESTOPTADD=\"-boom\" TESTOPTADD=\"-noerroronexit\"
56 # my $nNumber = 55;
57 # my $sLocalParams = $params;
58 # $sLocalParams =~ s/test\s/test$nNumber /;
59 # print "Testparams: $sLocalParams\n";
60 # exit 1;
61 print "Default ";
63 else
65 # special hack!
66 if (checkForKillobj() == 1)
68 $params = "killobj";
70 elsif (checkARGVFor("buildall") == 1)
72 $bBuildAll = 1;
73 $params = "test";
75 else
77 # always run test, but envelope the other in 'TESTOPT="..."'
78 $params = "test TESTOPT=\"";
80 foreach $param (@ARGV)
82 $params = $params . " " . $param;
84 $params = $params . "\"";
86 print "User defined ";
89 print "parameters for dmake: $params\n";
91 initEnvironment();
92 main($params);
94 # ------------------------------------------------------------------------------
95 sub checkARGVFor($)
97 my $sCheckValue = shift;
98 my $sLocalParam;
99 my $nBackValue = 0;
100 foreach $sLocalParam (@ARGV)
102 if ($sLocalParam =~ /^${sCheckValue}$/)
104 $nBackValue = 1;
105 last;
108 return $nBackValue;
110 # ------------------------------------------------------------------------------
111 sub checkForKillobj()
113 my $sLocalParam;
114 my $nBackValue = 0;
115 foreach $sLocalParam (@ARGV)
117 if ($sLocalParam =~ /^killobj$/)
119 $nBackValue = 1;
120 last;
123 return $nBackValue;
126 # ------------------------------------------------------------------------------
127 sub initEnvironment()
129 my $os = $ENV{OS};
130 # no error output in forms of message boxes
131 $ENV{'DISABLE_SAL_DBGBOX'}="t";
133 SWITCH: {
134 if ( $os eq "WNT" ) {
135 $FS = "\\";
136 $g_sTempDir = $ENV{TMP} ? "$ENV{TMP}${FS}" : "c:${FS}tmp${FS}";
137 last SWITCH;
139 else {
140 $FS = "/";
141 $g_sTempDir = $ENV{TMP} ? "$ENV{TMP}${FS}" : "${FS}tmp${FS}";
142 last SWITCH;
144 print STDERR "buildall.pl: unknown platform\n";
145 exit(1);
148 # ------------------------------------------------------------------------------
150 sub trim($)
152 my $oldstr = shift;
153 $oldstr =~ s/^\s*(.*?)\s*$/$1/;
154 return $oldstr;
157 # ------------------------------------------------------------------------------
158 sub getLibName($)
160 my $sFile = shift;
161 if ($OSNAME eq "linux" || $OSNAME eq "solaris")
163 return "lib" . $sFile . ".so";
165 if ($OSNAME eq "MSWin32")
167 return $sFile . ".dll";
169 return $sFile;
171 # ------------------------------------------------------------------------------
172 sub giveOutAll($)
174 my $sFailureFile = shift;
175 local *IN;
176 if (! open(IN, $sFailureFile))
178 print "ERROR: Can't open output file $sFailureFile\n";
179 return;
181 my $line;
182 while ($line = <IN>)
184 chomp($line);
185 print "$line\n";
187 close(IN);
189 # ------------------------------------------------------------------------------
190 sub giveOutFailures($$)
192 my $sTest = shift;
193 my $sFailureFile = shift;
195 my $bBegin = 0;
196 my $nFailures = 0;
198 my $line;
199 local *IN;
200 if (! open(IN, $sFailureFile))
202 print "ERROR: Can't open output file $sFailureFile\n";
203 return;
206 my $bStartUnitTest = 0;
207 while ($line = <IN>)
209 chomp($line);
210 if ( $line =~ /^- start unit test/)
212 $bStartUnitTest = 1;
215 close(IN);
217 if ($bStartUnitTest == 0)
219 print "\nFailure: Unit test not started. Maybe compiler error.\n";
220 giveOutAll($sFailureFile);
221 $nFailures++;
222 # exit(1);
224 else
226 open(IN, $sFailureFile);
227 # check if testshl2 was started
228 while ($line = <IN>)
230 chomp($line);
232 # handling of the states
233 if ( $line =~ /^\# -- BEGIN:/)
235 $bBegin = 1;
237 elsif ( $line =~ /^\# -- END:/)
239 $bBegin = 0;
241 else
243 if ($bBegin == 1)
245 print "$line\n";
246 $nFailures++;
250 close(IN);
253 if ($nFailures > 0)
255 # extra return for a better output
256 print "\nFailures occurred: $nFailures\n";
257 print "The whole output can be found in $sFailureFile\n";
258 print "\n";
260 # Statistics
261 $nGlobalFailures += $nFailures;
264 # ------------------------------------------------------------------------------
265 sub printOnLibrary($)
267 my $sTarget = shift;
268 print " on library: " . getLibName($sTarget);
270 # ------------------------------------------------------------------------------
271 sub runASingleTest($$)
273 my $sTarget = shift;
274 my $params = shift;
275 my $dmake = "dmake $params";
277 my $sLogPath = $g_sTempDir . "dmake_out_$$";
278 mkdir($sLogPath);
279 my $sLogFile = $sLogPath . "/" . $sTarget . ".out";
281 # due to the fact, a library name in one project is distinct, we should remember all already run through libraries and
282 # supress same libraries, if they occur one more.
284 if (exists $libraryRunThrough{getLibName($sTarget)})
286 # already done
287 return;
289 printOnLibrary($sTarget);
290 print "\n";
292 # redirect tcsh ">&" (stdout, stderr)
293 # redirect 4nt ">" (stdout), "2>" (stderr)
294 # print "OSNAME: $OSNAME\n";
295 # LLA: redirect check canceled, seems to be not work as I want.
296 # my $redirect = "";
297 # if ($OSNAME eq "linux" || $OSNAME eq "solaris")
299 # # print "UNIX, linux or solaris\n";
300 # $redirect = '>>&!' . $sLogFile;
302 # else
304 # if ($OSNAME eq "MSWin32")
306 # # test
307 # $redirect = ">>$sLogFile 2>>$sLogFile";
310 # print "$dmake $redirect\n";
312 # LLA: so system does also not work as I imagine
313 # system("$dmake $redirect");
315 # LLA: next check, use open with pipe
317 local *LOGFILE;
318 if (! open( LOGFILE, '>' . "$sLogFile"))
320 print "ERROR: can't open logfile: $sLogFile\n";
321 return;
324 my $line;
325 local *DMAKEOUTPUT;
326 if (! open( DMAKEOUTPUT, "$dmake 2>&1 |"))
328 print "ERROR: can't open dmake\n";
329 return;
331 while ($line = <DMAKEOUTPUT>)
333 chomp($line);
334 print LOGFILE "$line\n";
336 close(DMAKEOUTPUT);
337 close(LOGFILE);
339 giveOutFailures($sTarget, $sLogFile);
341 $libraryRunThrough{getLibName($sTarget)} = "done";
344 # ------------------------------------------------------------------------------
345 sub interpretLine($)
347 my $line = shift;
349 my $path;
350 my $file;
352 if ($line =~ /^\#/ || $line =~ /^$/)
354 # remark or empty line
356 else
358 # special format, $file == $path
359 ($path, $file) = split(/;/, $line);
360 if (! $file)
362 $file = $path;
364 $file = trim($file);
365 $path = trim($path);
367 return $path, $file;
369 # ------------------------------------------------------------------------------
370 sub runTestsOnPath($$$)
372 my $path = shift;
373 my $file = shift;
374 my $params = shift;
376 # empty values
377 if (!$path || $path eq "")
379 # DBG: print "empty path '$path'\n";
380 return;
382 if (!$file || $file eq "")
384 # DBG: print "empty file '$file'\n";
385 return;
388 # print "File: '$file', Path: '$path'\n";
389 print "Work in directory: $path\n";
390 my $newpath = $cwd . $FS . $path;
391 # print "chdir to $newpath\n";
393 my $error = chdir($newpath);
394 cwd();
396 # run through the hole makefile.mk and check if SHL<D>TARGET = ... exist, for every target call "dmake test<D>"
398 local *MAKEFILE_MK;
399 if (! open(MAKEFILE_MK, "makefile.mk"))
401 print "ERROR: can't open makefile.mk in path: $newpath\n";
402 print "please check your libs2test.txt file in qa directory.\n";
404 my $line;
405 my $nNumber;
406 my $sTarget;
407 my $sLocalParams;
409 while($line = <MAKEFILE_MK>)
411 chomp($line);
413 if ($line =~ /SHL(\d)TARGET=(.*)/)
415 $nNumber = $1;
416 $sTarget = trim($2);
418 # DBG: print "test$number is lib: $target\n";
419 $sLocalParams = $params . " "; # append a whitespace, so we can check if 'test' exist without additional digits
420 $sLocalParams =~ s/test\s/test$nNumber/;
421 # DBG: print "$sLocalParams\n";
422 if ($bBuildAll == 1 ||
423 $file eq $sTarget)
425 # print "runASingleTest on Target: $sTarget 'dmake $sLocalParams'\n";
426 runASingleTest($sTarget, $sLocalParams);
428 else
430 # printOnLibrary($sTarget);
431 # print " suppressed, not in libs2test.txt\n";
435 close(MAKEFILE_MK);
438 # ------------------------------------------------------------------------------
440 sub main($)
442 my $params = shift;
443 # my $sLogFile = shift; # "buildall_$$.out";
444 local *LIBS2TEST;
445 my $filename = "libs2test.txt";
446 my $line;
448 open(LIBS2TEST, $filename) || die "can't open $filename\n";
450 while($line = <LIBS2TEST>)
452 chomp($line);
453 # DOS Hack grrrr...
454 while ($line =~ /
457 $line = substr($line, 0, -1);
460 # print "$line\n";
461 my $path;
462 my $file;
463 ($path, $file) = interpretLine($line);
464 runTestsOnPath($path, $file, $params);
466 close(LIBS2TEST);
468 print "\nComplete logging information will be found in dir: ".$g_sTempDir."dmake_out_$$/\n";
470 if ($nGlobalFailures > 0)
472 print "\nFailures over all occurred: $nGlobalFailures\n";
473 print "\nPASSED FAILED.\n";
475 else
477 print "\nPASSED OK.\n";
481 # ------------------------------------------------------------------------------
483 # TODO:
484 # -verbose
485 # -fan - \ | /
487 # END!