Adjust testcurl.pl to copy checked out curlbuild.h.dist as curlbuild.h
[platform/upstream/curl.git] / tests / testcurl.pl
1 #!/usr/bin/env perl
2 #***************************************************************************
3 #                                  _   _ ____  _
4 #  Project                     ___| | | |  _ \| |
5 #                             / __| | | | |_) | |
6 #                            | (__| |_| |  _ <| |___
7 #                             \___|\___/|_| \_\_____|
8 #
9 # Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
10 #
11 # This software is licensed as described in the file COPYING, which
12 # you should have received as part of this distribution. The terms
13 # are also available at http://curl.haxx.se/docs/copyright.html.
14 #
15 # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16 # copies of the Software, and permit persons to whom the Software is
17 # furnished to do so, under the terms of the COPYING file.
18 #
19 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 # KIND, either express or implied.
21 #
22 # $Id$
23 ###########################################################################
24
25 ###########################
26 #  What is This Script?
27 ###########################
28
29 # testcurl.pl is the master script to use for automatic testing of CVS-curl.
30 # This is written for the purpose of being run from a crontab job or similar
31 # at a regular interval. The output is suitable to be mailed to
32 # curl-autocompile@haxx.se to be dealt with automatically (make sure the
33 # subject includes the word "autobuild" as the mail gets silently discarded
34 # otherwise).  The most current build status (with a resonable backlog) will
35 # be published on the curl site, at http://curl.haxx.se/auto/
36
37 # USAGE:
38 # testcurl.pl [options] [curl-daily-name] > output
39
40 # Options:
41 #
42 # --configure=[options]    Configure options
43 # --crosscompile           This is a crosscompile
44 # --desc=[desc]            Description of your test system
45 # --email=[email]          Set email address to report as
46 # --extvercmd=[command]    Command to use for displaying version with cross compiles.
47 # --mktarball=[command]    Command to run after completed test
48 # --name=[name]            Set name to report as
49 # --nocvsup                Don't update from CVS even though it is a CVS tree
50 # --nobuildconf            Don't run buildconf
51 # --runtestopts=[options]  Options to pass to runtests.pl
52 # --setup=[file name]      File name to read setup from (deprecated)
53 # --target=[your os]       Specify your target environment.
54 #
55 # if [curl-daily-name] is omitted, a 'curl' CVS directory is assumed.
56 #
57
58 use strict;
59
60 use Cwd;
61
62 # Turn on warnings (equivalent to -w, which can't be used with /usr/bin/env)
63 #BEGIN { $^W = 1; }
64
65 use vars qw($version $fixed $infixed $CURLDIR $CVS $pwd $build $buildlog
66             $buildlogname $configurebuild $targetos $confsuffix $binext
67             $libext);
68 use vars qw($name $email $desc $confopts $runtestopts $setupfile $mktarball
69             $extvercmd $nocvsup $nobuildconf $crosscompile $timestamp);
70
71 # version of this script
72 $version='$Revision$';
73 $fixed=0;
74
75 # Determine if we're running from CVS or a canned copy of curl,
76 # or if we got a specific target option or setup file option.
77 $CURLDIR="curl";
78 $CVS=1;
79 $setupfile = 'setup';
80 while ($ARGV[0]) {
81   if ($ARGV[0] =~ /--target=/) {
82     $targetos = (split(/=/, shift @ARGV))[1];
83   }
84   elsif ($ARGV[0] =~ /--setup=/) {
85     $setupfile = (split(/=/, shift @ARGV))[1];
86   }
87   elsif ($ARGV[0] =~ /--extvercmd=/) {
88     $extvercmd = (split(/=/, shift @ARGV))[1];
89   }
90   elsif ($ARGV[0] =~ /--mktarball=/) {
91     $mktarball = (split(/=/, shift @ARGV))[1];
92   }
93   elsif ($ARGV[0] =~ /--name=/) {
94     $name = (split(/=/, shift @ARGV))[1];
95   }
96   elsif ($ARGV[0] =~ /--email=/) {
97     $email = (split(/=/, shift @ARGV))[1];
98   }
99   elsif ($ARGV[0] =~ /--desc=/) {
100     $desc = (split(/=/, shift @ARGV))[1];
101   }
102   elsif ($ARGV[0] =~ /--configure=/) {
103     $confopts = (split(/=/, shift @ARGV))[1];
104   }
105   elsif ($ARGV[0] =~ /--nocvsup/) {
106     $nocvsup=1;
107     shift @ARGV;
108   }
109   elsif ($ARGV[0] =~ /--nobuildconf/) {
110     $nobuildconf=1;
111     shift @ARGV;
112   }
113   elsif ($ARGV[0] =~ /--crosscompile/) {
114     $crosscompile=1;
115     shift @ARGV;
116   }
117   elsif ($ARGV[0] =~ /--runtestopts=/) {
118     $runtestopts = (split(/=/, shift @ARGV, 2))[1];
119   }
120   else {
121     $CURLDIR=shift @ARGV;
122     $CVS=0;
123   }
124 }
125
126 # Do the platform-specific stuff here
127 $configurebuild = 1;
128 $confsuffix = '';
129 $binext = '';
130 $libext = '.la'; # .la since both libcurl and libcares are made with libtool
131 if ($^O eq 'MSWin32' || $targetos) {
132   if (!$targetos) {
133     # If no target defined on Win32 lets assume vc
134     $targetos = 'vc';
135   }
136   if ($targetos =~ /vc/ || $targetos =~ /borland/) {
137     $binext = '.exe';
138     $libext = '.lib';
139   }
140   elsif ($targetos =~ /mingw32/) {
141     $binext = '.exe';
142     if ($^O eq 'MSWin32') {
143       $libext = '.a';
144     }
145   }
146   elsif ($targetos =~ /netware/) {
147     $configurebuild = 0;
148     $binext = '.nlm';
149     if ($^O eq 'MSWin32') {
150       $libext = '.lib';
151     }
152     else {
153       $libext = '.a';
154     }
155   }
156 }
157
158 if (($^O eq 'MSWin32') &&
159     ($targetos =~ /vc/ || $targetos =~ /mingw32/ || $targetos =~ /borland/)) {
160
161   # Set these things only when building ON Windows and for Win32 platform.
162   # FOR Windows since we might be cross-compiling on another system. Non-
163   # Windows builds still default to configure-style builds with no confsuffix.
164
165   $configurebuild = 0;
166   $confsuffix = '-win32';
167 }
168
169
170 $ENV{LANG}="C";
171
172 sub rmtree($) {
173     my $target = $_[0];
174     if ($^O eq 'MSWin32') {
175       foreach (glob($target)) {
176         s:/:\\:g;
177         system("rd /s /q $_");
178       }
179     } else {
180       system("rm -rf $target");
181     }
182 }
183
184 sub grepfile($$) {
185     my ($target, $fn) = @_;
186     open(F, $fn) or die;
187     while (<F>) {
188       if (/$target/) {
189         close(F);
190         return 1;
191       }
192     }
193     close(F);
194     return 0;
195 }
196
197 sub logit($) {
198     my $text=$_[0];
199     if ($text) {
200       print "testcurl: $text\n";
201     }
202 }
203
204 sub mydie($){
205     my $text=$_[0];
206     logit "$text";
207     chdir $pwd; # cd back to the original root dir
208
209     if ($pwd && $build) {
210       # we have a build directory name, remove the dir
211       logit "removing the $build dir";
212       rmtree "$pwd/$build";
213     }
214     if (-r $buildlog) {
215       # we have a build log output file left, remove it
216       logit "removing the $buildlogname file";
217       unlink "$buildlog";
218     }
219     logit "ENDING HERE"; # last line logged!
220     exit 1;
221 }
222
223 if (open(F, "$setupfile")) {
224   while (<F>) {
225     if (/(\w+)=(.*)/) {
226       eval "\$$1=$2;";
227     }
228   }
229   close(F);
230   $infixed=$fixed;
231 } else {
232   $infixed=0;    # so that "additional args to configure" works properly first time...
233 }
234
235 if (!$name) {
236   print "please enter your name\n";
237   $name = <>;
238   chomp $name;
239   $fixed=1;
240 }
241
242 if (!$email) {
243   print "please enter your contact email address\n";
244   $email = <>;
245   chomp $email;
246   $fixed=2;
247 }
248
249 if (!$desc) {
250   print "please enter a one line system description\n";
251   $desc = <>;
252   chomp $desc;
253   $fixed=3;
254 }
255
256 if (!$confopts) {
257   if ($infixed < 4) {
258     print "please enter your additional arguments to configure\n";
259     print "examples: --with-ssl --enable-debug --enable-ipv6 --with-krb4\n";
260     $confopts = <>;
261     chomp $confopts;
262   }
263 }
264
265
266 if ($fixed < 4) {
267     $fixed=4;
268     open(F, ">$setupfile") or die;
269     print F "name='$name'\n";
270     print F "email='$email'\n";
271     print F "desc='$desc'\n";
272     print F "confopts='$confopts'\n";
273     print F "fixed='$fixed'\n";
274     close(F);
275 }
276
277 my $str1066os = 'o' x 1066;
278
279 # Set timestamp to the UTC this script is running. Its value might
280 # be changed later in the script to the value present in curlver.h
281 $timestamp = scalar(gmtime)." UTC";
282
283 logit "STARTING HERE"; # first line logged, for scripts to trigger on
284 logit 'TRANSFER CONTROL ==== 1120 CHAR LINE' . $str1066os . 'LINE_END';
285 logit "NAME = $name";
286 logit "EMAIL = $email";
287 logit "DESC = $desc";
288 logit "CONFOPTS = $confopts";
289 logit "CPPFLAGS = ".$ENV{CPPFLAGS};
290 logit "CFLAGS = ".$ENV{CFLAGS};
291 logit "LDFLAGS = ".$ENV{LDFLAGS};
292 logit "CC = ".$ENV{CC};
293 logit "target = ".$targetos;
294 logit "version = $version"; # script version
295 logit "date = $timestamp";  # When the test build starts
296
297 $str1066os = undef;
298
299 # Make $pwd to become the path without newline. We'll use that in order to cut
300 # off that path from all possible logs and error messages etc.
301 $pwd = getcwd();
302
303 if (-d $CURLDIR) {
304   if ($CVS && -d "$CURLDIR/CVS") {
305     logit "$CURLDIR is verified to be a fine source dir";
306     # remove the generated sources to force them to be re-generated each
307     # time we run this test
308     unlink "$CURLDIR/src/hugehelp.c";
309   } elsif (!$CVS && -f "$CURLDIR/tests/testcurl.pl") {
310     logit "$CURLDIR is verified to be a fine daily source dir"
311   } else {
312     mydie "$CURLDIR is not a daily source dir or checked out from CVS!"
313   }
314 }
315 $build="build-$$";
316 $buildlogname="buildlog-$$";
317 $buildlog="$pwd/$buildlogname";
318
319 # remove any previous left-overs
320 rmtree "build-*";
321 rmtree "buildlog-*";
322
323 # this is to remove old build logs that ended up in the wrong dir
324 foreach (glob("$CURLDIR/buildlog-*")) { unlink $_; }
325
326 # create a dir to build in
327 mkdir $build, 0777;
328
329 if (-d $build) {
330   logit "build dir $build was created fine";
331 } else {
332   mydie "failed to create dir $build";
333 }
334
335 # get in the curl source tree root
336 chdir $CURLDIR;
337
338 # Do the CVS thing, or not...
339 if ($CVS) {
340
341   # this is a temporary fix to make things work again, remove later
342   logit "remove ares/aclocal.m4";
343   unlink "ares/aclocal.m4";
344
345   logit "update from CVS";
346   my $cvsstat;
347
348   sub cvsup() {
349     # update quietly to the latest CVS
350     if($nocvsup) {
351         logit "Skipping CVS update (--nocvsup)";
352         return 1;
353     }
354     else {
355         logit "run cvs up";
356         system("cvs -Q up -dP 2>&1");
357     }
358
359     $cvsstat=$?;
360
361     # return !RETURNVALUE so that errors return 0 while goodness
362     # returns 1
363     return !$cvsstat;
364   }
365
366   my $att=0;
367   while (!cvsup()) {
368     $att++;
369     logit "failed CVS update attempt number $att.";
370     if ($att > 10) {
371       $cvsstat=111;
372       last; # get out of the loop
373     }
374     sleep 5;
375   }
376
377   if ($cvsstat != 0) {
378     mydie "failed to update from CVS ($cvsstat), exiting";
379   }
380   elsif (!$nocvsup) {
381     # Set timestamp to the UTC the CVS update took place.
382     $timestamp = scalar(gmtime)." UTC";
383   }
384
385   if($nobuildconf) {
386       logit "told to not run buildconf";
387   }
388   elsif ($configurebuild) {
389     # remove possible left-overs from the past
390     unlink "configure";
391     unlink "autom4te.cache";
392
393     # generate the build files
394     logit "invoke buildconf, but filter off aclocal underquoted definition warnings";
395     open(F, "./buildconf 2>&1 |") or die;
396     open(LOG, ">$buildlog") or die;
397     while (<F>) {
398       next if /warning: underquoted definition of/;
399       print;
400       print LOG;
401     }
402     close(F);
403     close(LOG);
404
405     if (grepfile("^buildconf: OK", $buildlog)) {
406       logit "buildconf was successful";
407     }
408     else {
409       mydie "buildconf was NOT successful";
410     }
411   }
412   else {
413     logit "buildconf was successful (dummy message)";
414   }
415 }
416
417 # Set timestamp to the one in curlver.h if this isn't a CVS test build.
418 if ((-f "include/curl/curlver.h") &&
419     (open(F, "<include/curl/curlver.h"))) {
420   while (<F>) {
421     chomp;
422     if ($_ =~ /^\#define\s+LIBCURL_TIMESTAMP\s+\"(.+)\".*$/) {
423       my $stampstring = $1;
424       if ($stampstring !~ /CVS/) {
425           $stampstring =~ s/\s+UTC//;
426           $timestamp = $stampstring." UTC";
427       }
428       last;
429     }
430   }
431   close(F);
432 }
433
434 # Show timestamp we are using for this test build.
435 logit "timestamp = $timestamp";
436
437 if ($configurebuild) {
438   if (-f "configure") {
439     logit "configure created (at least it exists)";
440   } else {
441     mydie "no configure created/found";
442   }
443 } else {
444   logit "configure created (dummy message)"; # dummy message to feign success
445 }
446
447 sub findinpath {
448   my $c;
449   my $e;
450   my $x='';
451   $x='.exe' if ($^O eq 'MSWin32');
452   my $s=':';
453   $s=';' if ($^O eq 'MSWin32');
454   my $p=$ENV{'PATH'};
455   my @pa = split($s, $p);
456   for $c (@_) {
457     for $e (@pa) {
458       if( -x "$e/$c$x") {
459         return $c;
460       }
461     }
462   }
463 }
464
465 my $make = findinpath("gmake", "make", "nmake");
466 if(!$make) {
467     mydie "Couldn't find make in the PATH";
468 }
469 logit "going with $make as make";
470
471 # change to build dir
472 chdir "$pwd/$build";
473
474 if ($configurebuild) {
475   # run configure script
476   print `../$CURLDIR/configure $confopts 2>&1`;
477
478   if (-f "lib/Makefile") {
479     logit "configure seems to have finished fine";
480   } else {
481     mydie "configure didn't work";
482   }
483 } else {
484   logit "copying files to build dir ...";
485   if (($^O eq 'MSWin32') && ($targetos !~ /netware/)) {
486     system("xcopy /s /q ..\\$CURLDIR .");
487     system("buildconf.bat");
488   }
489   elsif (($^O eq 'linux') || ($targetos =~ /netware/)) {
490     system("cp -afr ../$CURLDIR/* ."); 
491     system("cp -af ../$CURLDIR/Makefile.dist Makefile"); 
492     system("cp -af ../$CURLDIR/include/curl/curlbuild.h.dist include/curl/curlbuild.h");
493     system("$make -i -C lib -f Makefile.$targetos prebuild");
494     system("$make -i -C src -f Makefile.$targetos prebuild");
495   }
496 }
497
498 logit "display lib/config$confsuffix.h";
499 open(F, "lib/config$confsuffix.h") or die "lib/config$confsuffix.h: $!";
500 while (<F>) {
501   print if /^ *#/;
502 }
503 close(F);
504
505 if (grepfile("define USE_ARES", "lib/config$confsuffix.h")) {
506   logit "setup to build ares";
507
508   logit "display ares/config$confsuffix.h";
509   if(open(F, "ares/config$confsuffix.h")) {
510       while (<F>) {
511           print if /^ *#/;
512       }
513       close(F);
514   }
515
516   logit "build ares";
517   chdir "ares";
518
519   if ($targetos && !$configurebuild) {
520       logit "$make -f Makefile.$targetos";
521       open(F, "$make -f Makefile.$targetos 2>&1 |") or die;
522   }
523   else {
524       logit "$make";
525       open(F, "$make 2>&1 |") or die;
526   }
527   while (<F>) {
528     s/$pwd//g;
529     print;
530   }
531   close(F);
532
533   if (-f "libcares$libext") {
534     logit "ares is now built successfully (libcares$libext)";
535   } else {
536     logit "ares build failed (libares$libext)";
537   }
538
539   # cd back to the curl build dir
540   chdir "$pwd/$build";
541 }
542
543 if ($configurebuild) {
544   logit "$make -i";
545   open(F, "$make -i 2>&1 |") or die;
546   while (<F>) {
547     s/$pwd//g;
548     print;
549   }
550   close(F);
551 }
552 else {
553   logit "$make -i $targetos";
554   if ($^O eq 'MSWin32') {
555     if ($targetos =~ /vc/) {
556       open(F, "nmake -i $targetos|") or die;
557     }
558     else {
559       open(F, "$make -i $targetos |") or die;
560     }
561   }
562   else {
563     open(F, "$make -i $targetos 2>&1 |") or die;
564   }
565   while (<F>) {
566     s/$pwd//g;
567     print;
568   }
569   close(F);
570 }
571
572 if (-f "lib/libcurl$libext") {
573   logit "libcurl was created fine (libcurl$libext)";
574 }
575 else {
576   mydie "libcurl was not created (libcurl$libext)";
577 }
578
579 if (-f "src/curl$binext") {
580   logit "curl was created fine (curl$binext)";
581 }
582 else {
583   mydie "curl was not created (curl$binext)";
584 }
585
586 if (!$crosscompile || (($extvercmd ne '') && (-x $extvercmd))) {
587   logit "display curl${binext} --version output";
588   my $cmd = ($extvercmd ne '' ? $extvercmd.' ' : '')."./src/curl${binext} --version|";
589   open(F, $cmd);
590   while(<F>) {
591       print;
592       print LOG;
593   }
594   close(F);
595 }
596
597 if ($configurebuild && !$crosscompile) {
598   my $o;
599   if($runtestopts) {
600       $o = "TEST_F=\"$runtestopts\" ";
601   }
602   logit "$make -k ${o}test-full";
603   open(F, "$make -k ${o}test-full 2>&1 |") or die;
604   open(LOG, ">$buildlog") or die;
605   while (<F>) {
606     s/$pwd//g;
607     print;
608     print LOG;
609   }
610   close(F);
611   close(LOG);
612
613   if (grepfile("^TEST", $buildlog)) {
614     logit "tests were run";
615   } else {
616     mydie "test suite failure";
617   }
618
619   if (grepfile("^TESTFAIL:", $buildlog)) {
620     logit "the tests were not successful";
621   } else {
622     logit "the tests were successful!";
623   }
624 } else {
625   # dummy message to feign success
626   if($crosscompile) {
627     logit "cross-compiling, can't run tests";
628   }
629   print "TESTDONE: 1 tests out of 0 (dummy message)\n";
630 }
631
632 # create a tarball if we got that option.
633 if (($mktarball ne '') && (-x $mktarball)) {
634   system($mktarball);
635 }
636
637 # mydie to cleanup
638 mydie "ending nicely";