2 #***************************************************************************
4 # Project ___| | | | _ \| |
6 # | (__| |_| | _ <| |___
7 # \___|\___/|_| \_\_____|
9 # Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
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.
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.
19 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 # KIND, either express or implied.
22 ###########################################################################
24 ###########################
25 # What is This Script?
26 ###########################
28 # testcurl.pl is the master script to use for automatic testing of CVS-curl.
29 # This is written for the purpose of being run from a crontab job or similar
30 # at a regular interval. The output is suitable to be mailed to
31 # curl-autocompile@haxx.se to be dealt with automatically (make sure the
32 # subject includes the word "autobuild" as the mail gets silently discarded
33 # otherwise). The most current build status (with a resonable backlog) will
34 # be published on the curl site, at http://curl.haxx.se/auto/
37 # testcurl.pl [options] [curl-daily-name] > output
41 # --configure=[options] Configure options
42 # --crosscompile This is a crosscompile
43 # --desc=[desc] Description of your test system
44 # --email=[email] Set email address to report as
45 # --extvercmd=[command] Command to use for displaying version with cross compiles.
46 # --mktarball=[command] Command to run after completed test
47 # --name=[name] Set name to report as
48 # --nocvsup Don't update from CVS even though it is a CVS tree
49 # --nobuildconf Don't run buildconf
50 # --runtestopts=[options] Options to pass to runtests.pl
51 # --setup=[file name] File name to read setup from (deprecated)
52 # --target=[your os] Specify your target environment.
54 # if [curl-daily-name] is omitted, a 'curl' CVS directory is assumed.
61 # Turn on warnings (equivalent to -w, which can't be used with /usr/bin/env)
64 use vars qw($version $fixed $infixed $CURLDIR $CVS $pwd $build $buildlog
65 $buildlogname $configurebuild $targetos $confsuffix $binext
67 use vars qw($name $email $desc $confopts $runtestopts $setupfile $mktarball
68 $extvercmd $nocvsup $nobuildconf $crosscompile $timestamp);
70 # version of this script
71 $version='$Revision$';
74 # Determine if we're running from CVS or a canned copy of curl,
75 # or if we got a specific target option or setup file option.
80 if ($ARGV[0] =~ /--target=/) {
81 $targetos = (split(/=/, shift @ARGV))[1];
83 elsif ($ARGV[0] =~ /--setup=/) {
84 $setupfile = (split(/=/, shift @ARGV))[1];
86 elsif ($ARGV[0] =~ /--extvercmd=/) {
87 $extvercmd = (split(/=/, shift @ARGV))[1];
89 elsif ($ARGV[0] =~ /--mktarball=/) {
90 $mktarball = (split(/=/, shift @ARGV))[1];
92 elsif ($ARGV[0] =~ /--name=/) {
93 $name = (split(/=/, shift @ARGV))[1];
95 elsif ($ARGV[0] =~ /--email=/) {
96 $email = (split(/=/, shift @ARGV))[1];
98 elsif ($ARGV[0] =~ /--desc=/) {
99 $desc = (split(/=/, shift @ARGV))[1];
101 elsif ($ARGV[0] =~ /--configure=/) {
102 $confopts = (split(/=/, shift @ARGV))[1];
104 elsif ($ARGV[0] =~ /--nocvsup/) {
108 elsif ($ARGV[0] =~ /--nobuildconf/) {
112 elsif ($ARGV[0] =~ /--crosscompile/) {
116 elsif ($ARGV[0] =~ /--runtestopts=/) {
117 $runtestopts = (split(/=/, shift @ARGV, 2))[1];
120 $CURLDIR=shift @ARGV;
125 # Do the platform-specific stuff here
129 $libext = '.la'; # .la since both libcurl and libcares are made with libtool
130 if ($^O eq 'MSWin32' || $targetos) {
132 # If no target defined on Win32 lets assume vc
135 if ($targetos =~ /vc/ || $targetos =~ /borland/) {
139 elsif ($targetos =~ /mingw/) {
141 if ($^O eq 'MSWin32') {
145 elsif ($targetos =~ /netware/) {
148 if ($^O eq 'MSWin32') {
157 if (($^O eq 'MSWin32') &&
158 ($targetos =~ /vc/ || $targetos =~ /mingw32/ || $targetos =~ /borland/)) {
160 # Set these things only when building ON Windows and for Win32 platform.
161 # FOR Windows since we might be cross-compiling on another system. Non-
162 # Windows builds still default to configure-style builds with no confsuffix.
165 $confsuffix = '-win32';
168 $ENV{LC_ALL}="C" if (($ENV{LC_ALL}) && ($ENV{LC_ALL} !~ /^C$/));
169 $ENV{LC_CTYPE}="C" if (($ENV{LC_CTYPE}) && ($ENV{LC_CTYPE} !~ /^C$/));
174 if ($^O eq 'MSWin32') {
175 foreach (glob($target)) {
177 system("rd /s /q $_");
180 system("rm -rf $target");
185 my ($target, $fn) = @_;
200 print "testcurl: $text\n";
204 sub logit_spaced($) {
207 print "\ntestcurl: $text\n\n";
214 chdir $pwd; # cd back to the original root dir
216 if ($pwd && $build) {
217 # we have a build directory name, remove the dir
218 logit "removing the $build dir";
219 rmtree "$pwd/$build";
222 # we have a build log output file left, remove it
223 logit "removing the $buildlogname file";
226 logit "ENDING HERE"; # last line logged!
230 sub get_host_triplet {
232 my $configfile = "$pwd/$build/lib/curl_config.h";
234 if(-f $configfile && -s $configfile && open(LIBCONFIGH, "<$configfile")) {
235 while(<LIBCONFIGH>) {
236 if($_ =~ /^\#define\s+OS\s+"*([^"][^"]*)"*\s*/) {
246 if (open(F, "$setupfile")) {
255 $infixed=0; # so that "additional args to configure" works properly first time...
259 print "please enter your name\n";
266 print "please enter your contact email address\n";
273 print "please enter a one line system description\n";
281 print "please enter your additional arguments to configure\n";
282 print "examples: --with-ssl --enable-debug --enable-ipv6 --with-krb4\n";
291 open(F, ">$setupfile") or die;
292 print F "name='$name'\n";
293 print F "email='$email'\n";
294 print F "desc='$desc'\n";
295 print F "confopts='$confopts'\n";
296 print F "fixed='$fixed'\n";
300 # Enable picky compiler warnings unless explicitly disabled
301 if (($confopts !~ /--enable-debug/) &&
302 ($confopts !~ /--enable-warnings/) &&
303 ($confopts !~ /--disable-warnings/)) {
304 $confopts .= " --enable-warnings";
307 my $str1066os = 'o' x 1066;
309 # Set timestamp to the UTC this script is running. Its value might
310 # be changed later in the script to the value present in curlver.h
311 $timestamp = scalar(gmtime)." UTC";
313 logit "STARTING HERE"; # first line logged, for scripts to trigger on
314 logit 'TRANSFER CONTROL ==== 1120 CHAR LINE' . $str1066os . 'LINE_END';
315 logit "NAME = $name";
316 logit "EMAIL = $email";
317 logit "DESC = $desc";
318 logit "CONFOPTS = $confopts";
319 logit "CPPFLAGS = ".$ENV{CPPFLAGS};
320 logit "CFLAGS = ".$ENV{CFLAGS};
321 logit "LDFLAGS = ".$ENV{LDFLAGS};
322 logit "CC = ".$ENV{CC};
323 logit "MAKEFLAGS = ".$ENV{MAKEFLAGS};
324 logit "PKG_CONFIG_PATH = ".$ENV{PKG_CONFIG_PATH};
325 logit "target = ".$targetos;
326 logit "version = $version"; # script version
327 logit "date = $timestamp"; # When the test build starts
331 # Make $pwd to become the path without newline. We'll use that in order to cut
332 # off that path from all possible logs and error messages etc.
336 if ($CVS && -d "$CURLDIR/CVS") {
337 logit "$CURLDIR is verified to be a fine source dir";
338 # remove the generated sources to force them to be re-generated each
339 # time we run this test
340 unlink "$CURLDIR/src/hugehelp.c";
341 } elsif (!$CVS && -f "$CURLDIR/tests/testcurl.pl") {
342 logit "$CURLDIR is verified to be a fine daily source dir"
344 mydie "$CURLDIR is not a daily source dir or checked out from CVS!"
348 $buildlogname="buildlog-$$";
349 $buildlog="$pwd/$buildlogname";
351 # remove any previous left-overs
355 # this is to remove old build logs that ended up in the wrong dir
356 foreach (glob("$CURLDIR/buildlog-*")) { unlink $_; }
358 # create a dir to build in
362 logit "build dir $build was created fine";
364 mydie "failed to create dir $build";
367 # get in the curl source tree root
370 # Do the CVS thing, or not...
373 # this is a temporary fix to make things work again, remove later
374 logit "remove ares/aclocal.m4";
375 unlink "ares/aclocal.m4";
377 logit "update from CVS";
381 # update quietly to the latest CVS
383 logit "Skipping CVS update (--nocvsup)";
388 system("cvs -Q up -dP 2>&1");
393 # return !RETURNVALUE so that errors return 0 while goodness
401 logit "failed CVS update attempt number $att.";
404 last; # get out of the loop
410 mydie "failed to update from CVS ($cvsstat), exiting";
413 # Set timestamp to the UTC the CVS update took place.
414 $timestamp = scalar(gmtime)." UTC";
418 logit "told to not run buildconf";
420 elsif ($configurebuild) {
421 # remove possible left-overs from the past
423 unlink "autom4te.cache";
425 # generate the build files
426 logit "invoke buildconf, but filter off aclocal underquoted definition warnings";
427 open(F, "./buildconf 2>&1 |") or die;
428 open(LOG, ">$buildlog") or die;
430 next if /warning: underquoted definition of/;
437 if (grepfile("^buildconf: OK", $buildlog)) {
438 logit "buildconf was successful";
441 mydie "buildconf was NOT successful";
445 logit "buildconf was successful (dummy message)";
449 # Set timestamp to the one in curlver.h if this isn't a CVS test build.
450 if ((-f "include/curl/curlver.h") &&
451 (open(F, "<include/curl/curlver.h"))) {
454 if ($_ =~ /^\#define\s+LIBCURL_TIMESTAMP\s+\"(.+)\".*$/) {
455 my $stampstring = $1;
456 if ($stampstring !~ /CVS/) {
457 $stampstring =~ s/\s+UTC//;
458 $timestamp = $stampstring." UTC";
466 # Show timestamp we are using for this test build.
467 logit "timestamp = $timestamp";
469 if ($configurebuild) {
470 if (-f "configure") {
471 logit "configure created (at least it exists)";
473 mydie "no configure created/found";
476 logit "configure created (dummy message)"; # dummy message to feign success
482 my $x = ($^O eq 'MSWin32') ? '.exe' : '';
483 my $s = ($^O eq 'MSWin32') ? ';' : ':';
485 my @pa = split($s, $p);
495 my $make = findinpath("gmake", "make", "nmake");
497 mydie "Couldn't find make in the PATH";
499 # force to 'nmake' for VC builds
500 $make = "nmake" if ($targetos =~ /vc/);
501 logit "going with $make as make";
503 # change to build dir
506 if ($configurebuild) {
507 # run configure script
508 print `../$CURLDIR/configure $confopts 2>&1`;
510 if (-f "lib/Makefile") {
511 logit "configure seems to have finished fine";
513 mydie "configure didn't work";
516 logit "copying files to build dir ...";
517 if (($^O eq 'MSWin32') && ($targetos !~ /netware/)) {
518 system("xcopy /s /q ..\\$CURLDIR .");
519 system("buildconf.bat");
521 elsif ($targetos =~ /netware/) {
522 system("cp -afr ../$CURLDIR/* .");
523 system("cp -af ../$CURLDIR/Makefile.dist Makefile");
524 system("$make -i -C lib -f Makefile.netware prebuild");
525 system("$make -i -C src -f Makefile.netware prebuild");
526 if (-d "../$CURLDIR/ares") {
527 system("$make -i -C ares -f Makefile.netware prebuild");
530 elsif ($^O eq 'linux') {
531 system("cp -afr ../$CURLDIR/* .");
532 system("cp -af ../$CURLDIR/Makefile.dist Makefile");
533 system("cp -af ../$CURLDIR/include/curl/curlbuild.h.dist ./include/curl/curlbuild.h");
534 system("$make -i -C lib -f Makefile.$targetos prebuild");
535 system("$make -i -C src -f Makefile.$targetos prebuild");
536 if (-d "../$CURLDIR/ares") {
537 system("cp -af ../$CURLDIR/ares/ares_build.h.dist ./ares/ares_build.h");
538 system("$make -i -C ares -f Makefile.$targetos prebuild");
543 if(-f "./libcurl.pc") {
544 logit_spaced "display libcurl.pc";
545 if(open(F, "<./libcurl.pc")) {
548 print $ll if(($ll !~ /^ *#/) && ($ll !~ /^ *$/));
554 if(-f "./include/curl/curlbuild.h") {
555 logit_spaced "display include/curl/curlbuild.h";
556 if(open(F, "<./include/curl/curlbuild.h")) {
559 print $ll if(($ll =~ /^ *# *define *CURL_/) && ($ll !~ /__CURL_CURLBUILD_H/));
565 mydie "no curlbuild.h created/found";
568 logit_spaced "display lib/curl_config$confsuffix.h";
569 open(F, "lib/curl_config$confsuffix.h") or die "lib/curl_config$confsuffix.h: $!";
575 if (grepfile("define USE_ARES", "lib/curl_config$confsuffix.h")) {
577 logit "setup to build ares";
579 if(-f "./ares/libcares.pc") {
580 logit_spaced "display ares/libcares.pc";
581 if(open(F, "<./ares/libcares.pc")) {
584 print $ll if(($ll !~ /^ *#/) && ($ll !~ /^ *$/));
590 if(-f "./ares/ares_build.h") {
591 logit_spaced "display ares/ares_build.h";
592 if(open(F, "<./ares/ares_build.h")) {
595 print $ll if(($ll =~ /^ *# *define *CARES_/) && ($ll !~ /__CARES_BUILD_H/));
601 mydie "no ares_build.h created/found";
604 logit_spaced "display ares/ares_config$confsuffix.h";
605 if(open(F, "ares/ares_config$confsuffix.h")) {
616 if ($targetos && !$configurebuild) {
617 logit "$make -f Makefile.$targetos";
618 open(F, "$make -f Makefile.$targetos 2>&1 |") or die;
622 open(F, "$make 2>&1 |") or die;
630 if (-f "libcares$libext") {
631 logit "ares is now built successfully (libcares$libext)";
633 mydie "ares build failed (libcares$libext)";
636 # cd back to the curl build dir
640 my $mkcmd = "$make -i" . ($targetos && !$configurebuild ? " $targetos" : "");
642 open(F, "$mkcmd 2>&1 |") or die;
649 if (-f "lib/libcurl$libext") {
650 logit "libcurl was created fine (libcurl$libext)";
653 mydie "libcurl was not created (libcurl$libext)";
656 if (-f "src/curl$binext") {
657 logit "curl was created fine (curl$binext)";
660 mydie "curl was not created (curl$binext)";
663 if (!$crosscompile || (($extvercmd ne '') && (-x $extvercmd))) {
664 logit "display curl${binext} --version output";
665 my $cmd = ($extvercmd ne '' ? $extvercmd.' ' : '')."./src/curl${binext} --version|";
668 # strip CR from output on non-win32 platforms (wine on Linux)
669 s/\r// if ($^O ne 'MSWin32');
675 if ($configurebuild && !$crosscompile) {
678 $o = "TEST_F=\"$runtestopts\" ";
680 logit "$make -k ${o}test-full";
681 open(F, "$make -k ${o}test-full 2>&1 |") or die;
682 open(LOG, ">$buildlog") or die;
691 if (grepfile("^TEST", $buildlog)) {
692 logit "tests were run";
694 mydie "test suite failure";
697 if (grepfile("^TESTFAIL:", $buildlog)) {
698 logit "the tests were not successful";
700 logit "the tests were successful!";
705 # build test harness programs for selected cross-compiles
706 my $host_triplet = get_host_triplet();
707 if($host_triplet =~ /([^-]+)-([^-]+)-mingw(.*)/) {
708 chdir "$pwd/$build/tests";
709 logit_spaced "build test harness";
710 open(F, "$make -i 2>&1 |") or die;
711 open(LOG, ">$buildlog") or die;
721 logit_spaced "cross-compiling, can't run tests";
723 # dummy message to feign success
724 print "TESTDONE: 1 tests out of 0 (dummy message)\n";
727 # create a tarball if we got that option.
728 if (($mktarball ne '') && (-x $mktarball)) {
733 mydie "ending nicely";