2 #***************************************************************************
4 # Project ___| | | | _ \| |
6 # | (__| |_| | _ <| |___
7 # \___|\___/|_| \_\_____|
9 # Copyright (C) 1998 - 2010, 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 curl
29 # directly off its source repository.
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/
38 # testcurl.pl [options] [curl-daily-name] > output
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 pull from git even though it is a git tree
50 # --nogitpull Don't pull from git even though it is a git tree
51 # --nobuildconf Don't run buildconf
52 # --runtestopts=[options] Options to pass to runtests.pl
53 # --setup=[file name] File name to read setup from (deprecated)
54 # --target=[your os] Specify your target environment.
56 # if [curl-daily-name] is omitted, a 'curl' git directory is assumed.
63 # Turn on warnings (equivalent to -w, which can't be used with /usr/bin/env)
66 use vars qw($version $fixed $infixed $CURLDIR $git $pwd $build $buildlog
67 $buildlogname $configurebuild $targetos $confsuffix $binext
70 use vars qw($name $email $desc $confopts $runtestopts $setupfile $mktarball
71 $extvercmd $nogitpull $nobuildconf $crosscompile
74 # version of this script
75 $version='2010-03-24';
78 # Determine if we're running from git or a canned copy of curl,
79 # or if we got a specific target option or setup file option.
84 if ($ARGV[0] =~ /--target=/) {
85 $targetos = (split(/=/, shift @ARGV))[1];
87 elsif ($ARGV[0] =~ /--setup=/) {
88 $setupfile = (split(/=/, shift @ARGV))[1];
90 elsif ($ARGV[0] =~ /--extvercmd=/) {
91 $extvercmd = (split(/=/, shift @ARGV))[1];
93 elsif ($ARGV[0] =~ /--mktarball=/) {
94 $mktarball = (split(/=/, shift @ARGV))[1];
96 elsif ($ARGV[0] =~ /--name=/) {
97 $name = (split(/=/, shift @ARGV))[1];
99 elsif ($ARGV[0] =~ /--email=/) {
100 $email = (split(/=/, shift @ARGV))[1];
102 elsif ($ARGV[0] =~ /--desc=/) {
103 $desc = (split(/=/, shift @ARGV))[1];
105 elsif ($ARGV[0] =~ /--configure=/) {
106 $confopts = (split(/=/, shift @ARGV))[1];
108 elsif (($ARGV[0] eq "--nocvsup") || ($ARGV[0] eq "--nogitpull")) {
112 elsif ($ARGV[0] =~ /--nobuildconf/) {
116 elsif ($ARGV[0] =~ /--crosscompile/) {
120 elsif ($ARGV[0] =~ /--runtestopts=/) {
121 $runtestopts = (split(/=/, shift @ARGV, 2))[1];
124 $CURLDIR=shift @ARGV;
125 $git=0; # a given dir, assume not using git
129 # Do the platform-specific stuff here
133 $libext = '.la'; # .la since both libcurl and libcares are made with libtool
134 if ($^O eq 'MSWin32' || $targetos) {
136 # If no target defined on Win32 lets assume vc
139 if ($targetos =~ /vc/ || $targetos =~ /borland/) {
143 elsif ($targetos =~ /mingw/) {
145 if ($^O eq 'MSWin32') {
149 elsif ($targetos =~ /netware/) {
152 if ($^O eq 'MSWin32') {
161 if (($^O eq 'MSWin32') &&
162 ($targetos =~ /vc/ || $targetos =~ /mingw32/ || $targetos =~ /borland/)) {
164 # Set these things only when building ON Windows and for Win32 platform.
165 # FOR Windows since we might be cross-compiling on another system. Non-
166 # Windows builds still default to configure-style builds with no confsuffix.
169 $confsuffix = '-win32';
172 $ENV{LC_ALL}="C" if (($ENV{LC_ALL}) && ($ENV{LC_ALL} !~ /^C$/));
173 $ENV{LC_CTYPE}="C" if (($ENV{LC_CTYPE}) && ($ENV{LC_CTYPE} !~ /^C$/));
178 if ($^O eq 'MSWin32') {
179 foreach (glob($target)) {
181 system("rd /s /q $_");
184 system("rm -rf $target");
189 my ($target, $fn) = @_;
204 print "testcurl: $text\n";
208 sub logit_spaced($) {
211 print "\ntestcurl: $text\n\n";
218 chdir $pwd; # cd back to the original root dir
220 if ($pwd && $build) {
221 # we have a build directory name, remove the dir
222 logit "removing the $build dir";
223 rmtree "$pwd/$build";
226 # we have a build log output file left, remove it
227 logit "removing the $buildlogname file";
230 logit "ENDING HERE"; # last line logged!
234 sub get_host_triplet {
236 my $configfile = "$pwd/$build/lib/curl_config.h";
238 if(-f $configfile && -s $configfile && open(LIBCONFIGH, "<$configfile")) {
239 while(<LIBCONFIGH>) {
240 if($_ =~ /^\#define\s+OS\s+"*([^"][^"]*)"*\s*/) {
250 if (open(F, "$setupfile")) {
259 $infixed=0; # so that "additional args to configure" works properly first time...
263 print "please enter your name\n";
270 print "please enter your contact email address\n";
277 print "please enter a one line system description\n";
285 print "please enter your additional arguments to configure\n";
286 print "examples: --with-ssl --enable-debug --enable-ipv6 --with-krb4\n";
295 open(F, ">$setupfile") or die;
296 print F "name='$name'\n";
297 print F "email='$email'\n";
298 print F "desc='$desc'\n";
299 print F "confopts='$confopts'\n";
300 print F "fixed='$fixed'\n";
304 # Enable picky compiler warnings unless explicitly disabled
305 if (($confopts !~ /--enable-debug/) &&
306 ($confopts !~ /--enable-warnings/) &&
307 ($confopts !~ /--disable-warnings/)) {
308 $confopts .= " --enable-warnings";
311 my $str1066os = 'o' x 1066;
313 # Set timestamp to the UTC this script is running. Its value might
314 # be changed later in the script to the value present in curlver.h
315 $timestamp = scalar(gmtime)." UTC";
317 logit "STARTING HERE"; # first line logged, for scripts to trigger on
318 logit 'TRANSFER CONTROL ==== 1120 CHAR LINE' . $str1066os . 'LINE_END';
319 logit "NAME = $name";
320 logit "EMAIL = $email";
321 logit "DESC = $desc";
322 logit "CONFOPTS = $confopts";
323 logit "CPPFLAGS = ".$ENV{CPPFLAGS};
324 logit "CFLAGS = ".$ENV{CFLAGS};
325 logit "LDFLAGS = ".$ENV{LDFLAGS};
326 logit "CC = ".$ENV{CC};
327 logit "MAKEFLAGS = ".$ENV{MAKEFLAGS};
328 logit "PKG_CONFIG_PATH = ".$ENV{PKG_CONFIG_PATH};
329 logit "target = ".$targetos;
330 logit "version = $version"; # script version
331 logit "date = $timestamp"; # When the test build starts
335 # Make $pwd to become the path without newline. We'll use that in order to cut
336 # off that path from all possible logs and error messages etc.
340 if ($git && -d "$CURLDIR/.git") {
341 logit "$CURLDIR is verified to be a fine git source dir";
342 # remove the generated sources to force them to be re-generated each
343 # time we run this test
344 unlink "$CURLDIR/src/hugehelp.c";
345 } elsif (!$git && -f "$CURLDIR/tests/testcurl.pl") {
346 logit "$CURLDIR is verified to be a fine daily source dir"
348 mydie "$CURLDIR is not a daily source dir or checked out from git!"
352 $buildlogname="buildlog-$$";
353 $buildlog="$pwd/$buildlogname";
355 # remove any previous left-overs
359 # this is to remove old build logs that ended up in the wrong dir
360 foreach (glob("$CURLDIR/buildlog-*")) { unlink $_; }
362 # create a dir to build in
366 logit "build dir $build was created fine";
368 mydie "failed to create dir $build";
371 # get in the curl source tree root
375 # update quietly to the latest git
377 logit "Skipping git pull (--nogitpull)";
381 logit "run git pull";
382 system("git pull 2>&1");
390 # Do the git thing, or not...
393 my $cvsstat = gitpull();
396 # update failure is not lethal
397 logit "failed to update from git ($cvsstat), continue anyway";
399 elsif (!$nogitpull) {
400 # Set timestamp to the UTC the git update took place.
401 $timestamp = scalar(gmtime)." UTC";
404 # get the last 5 commits for show (even if no pull was made)
405 my @commits=`git log --pretty=oneline --abbrev-commit -5`;
406 logit "The most recent git commits:";
407 for my $l (@commits) {
413 logit "told to not run buildconf";
415 elsif ($configurebuild) {
416 # remove possible left-overs from the past
418 unlink "autom4te.cache";
420 # generate the build files
421 logit "invoke buildconf, but filter off aclocal underquoted definition warnings";
422 open(F, "./buildconf 2>&1 |") or die;
423 open(LOG, ">$buildlog") or die;
425 next if /warning: underquoted definition of/;
432 if (grepfile("^buildconf: OK", $buildlog)) {
433 logit "buildconf was successful";
436 mydie "buildconf was NOT successful";
440 logit "buildconf was successful (dummy message)";
444 # Set timestamp to the one in curlver.h if this isn't a git test build.
445 if ((-f "include/curl/curlver.h") &&
446 (open(F, "<include/curl/curlver.h"))) {
449 if ($_ =~ /^\#define\s+LIBCURL_TIMESTAMP\s+\"(.+)\".*$/) {
450 my $stampstring = $1;
451 if ($stampstring !~ /DEV/) {
452 $stampstring =~ s/\s+UTC//;
453 $timestamp = $stampstring." UTC";
461 # Show timestamp we are using for this test build.
462 logit "timestamp = $timestamp";
464 if ($configurebuild) {
465 if (-f "configure") {
466 logit "configure created (at least it exists)";
468 mydie "no configure created/found";
471 logit "configure created (dummy message)"; # dummy message to feign success
477 my $x = ($^O eq 'MSWin32') ? '.exe' : '';
478 my $s = ($^O eq 'MSWin32') ? ';' : ':';
480 my @pa = split($s, $p);
490 my $make = findinpath("gmake", "make", "nmake");
492 mydie "Couldn't find make in the PATH";
494 # force to 'nmake' for VC builds
495 $make = "nmake" if ($targetos =~ /vc/);
496 logit "going with $make as make";
498 # change to build dir
501 if ($configurebuild) {
502 # run configure script
503 print `../$CURLDIR/configure $confopts 2>&1`;
505 if (-f "lib/Makefile") {
506 logit "configure seems to have finished fine";
508 mydie "configure didn't work";
511 logit "copying files to build dir ...";
512 if (($^O eq 'MSWin32') && ($targetos !~ /netware/)) {
513 system("xcopy /s /q ..\\$CURLDIR .");
514 system("buildconf.bat");
516 elsif ($targetos =~ /netware/) {
517 system("cp -afr ../$CURLDIR/* .");
518 system("cp -af ../$CURLDIR/Makefile.dist Makefile");
519 system("$make -i -C lib -f Makefile.netware prebuild");
520 system("$make -i -C src -f Makefile.netware prebuild");
521 if (-d "../$CURLDIR/ares") {
522 system("$make -i -C ares -f Makefile.netware prebuild");
525 elsif ($^O eq 'linux') {
526 system("cp -afr ../$CURLDIR/* .");
527 system("cp -af ../$CURLDIR/Makefile.dist Makefile");
528 system("cp -af ../$CURLDIR/include/curl/curlbuild.h.dist ./include/curl/curlbuild.h");
529 system("$make -i -C lib -f Makefile.$targetos prebuild");
530 system("$make -i -C src -f Makefile.$targetos prebuild");
531 if (-d "../$CURLDIR/ares") {
532 system("cp -af ../$CURLDIR/ares/ares_build.h.dist ./ares/ares_build.h");
533 system("$make -i -C ares -f Makefile.$targetos prebuild");
538 if(-f "./libcurl.pc") {
539 logit_spaced "display libcurl.pc";
540 if(open(F, "<./libcurl.pc")) {
543 print $ll if(($ll !~ /^ *#/) && ($ll !~ /^ *$/));
549 if(-f "./include/curl/curlbuild.h") {
550 logit_spaced "display include/curl/curlbuild.h";
551 if(open(F, "<./include/curl/curlbuild.h")) {
554 print $ll if(($ll =~ /^ *# *define *CURL_/) && ($ll !~ /__CURL_CURLBUILD_H/));
560 mydie "no curlbuild.h created/found";
563 logit_spaced "display lib/curl_config$confsuffix.h";
564 open(F, "lib/curl_config$confsuffix.h") or die "lib/curl_config$confsuffix.h: $!";
570 if (grepfile("define USE_ARES", "lib/curl_config$confsuffix.h")) {
572 logit "setup to build ares";
574 if(-f "./ares/libcares.pc") {
575 logit_spaced "display ares/libcares.pc";
576 if(open(F, "<./ares/libcares.pc")) {
579 print $ll if(($ll !~ /^ *#/) && ($ll !~ /^ *$/));
585 if(-f "./ares/ares_build.h") {
586 logit_spaced "display ares/ares_build.h";
587 if(open(F, "<./ares/ares_build.h")) {
590 print $ll if(($ll =~ /^ *# *define *CARES_/) && ($ll !~ /__CARES_BUILD_H/));
596 mydie "no ares_build.h created/found";
599 logit_spaced "display ares/ares_config$confsuffix.h";
600 if(open(F, "ares/ares_config$confsuffix.h")) {
611 if ($targetos && !$configurebuild) {
612 logit "$make -f Makefile.$targetos";
613 open(F, "$make -f Makefile.$targetos 2>&1 |") or die;
617 open(F, "$make 2>&1 |") or die;
625 if (-f "libcares$libext") {
626 logit "ares is now built successfully (libcares$libext)";
628 mydie "ares build failed (libcares$libext)";
631 # cd back to the curl build dir
635 my $mkcmd = "$make -i" . ($targetos && !$configurebuild ? " $targetos" : "");
637 open(F, "$mkcmd 2>&1 |") or die;
644 if (-f "lib/libcurl$libext") {
645 logit "libcurl was created fine (libcurl$libext)";
648 mydie "libcurl was not created (libcurl$libext)";
651 if (-f "src/curl$binext") {
652 logit "curl was created fine (curl$binext)";
655 mydie "curl was not created (curl$binext)";
658 if (!$crosscompile || (($extvercmd ne '') && (-x $extvercmd))) {
659 logit "display curl${binext} --version output";
660 my $cmd = ($extvercmd ne '' ? $extvercmd.' ' : '')."./src/curl${binext} --version|";
663 # strip CR from output on non-win32 platforms (wine on Linux)
664 s/\r// if ($^O ne 'MSWin32');
670 if ($configurebuild && !$crosscompile) {
673 $o = "TEST_F=\"$runtestopts\" ";
675 logit "$make -k ${o}test-full";
676 open(F, "$make -k ${o}test-full 2>&1 |") or die;
677 open(LOG, ">$buildlog") or die;
686 if (grepfile("^TEST", $buildlog)) {
687 logit "tests were run";
689 mydie "test suite failure";
692 if (grepfile("^TESTFAIL:", $buildlog)) {
693 logit "the tests were not successful";
695 logit "the tests were successful!";
700 # build test harness programs for selected cross-compiles
701 my $host_triplet = get_host_triplet();
702 if($host_triplet =~ /([^-]+)-([^-]+)-mingw(.*)/) {
703 chdir "$pwd/$build/tests";
704 logit_spaced "build test harness";
705 open(F, "$make -i 2>&1 |") or die;
706 open(LOG, ">$buildlog") or die;
716 logit_spaced "cross-compiling, can't run tests";
718 # dummy message to feign success
719 print "TESTDONE: 1 tests out of 0 (dummy message)\n";
722 # create a tarball if we got that option.
723 if (($mktarball ne '') && (-x $mktarball)) {
728 mydie "ending nicely";