auto-generate module pris
[profile/ivi/qtbase.git] / bin / qtmodule-configtests
index 2ea6861..c6ebe2f 100755 (executable)
@@ -1,9 +1,8 @@
 #!/usr/bin/perl
 #############################################################################
 ##
-## Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-## All rights reserved.
-## Contact: Nokia Corporation (qt-info@nokia.com)
+## Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+## Contact: http://www.qt-project.org/
 ##
 ## This file is part of the build configuration tools of the Qt Toolkit.
 ##
@@ -36,6 +35,7 @@
 ##
 ##
 ##
+##
 ## $QT_END_LICENSE$
 ##
 #############################################################################
@@ -54,9 +54,9 @@ use warnings;
 # use packages -------------------------------------------------------
 use File::Basename;
 use File::Path 'mkpath';
-use File::Spec::Functions;
+use File::Spec::Functions qw/ :ALL /;
+use File::Temp qw/ :POSIX /;
 use Cwd;
-use Cwd 'abs_path';
 use Config;
 
 # Which file to look for the %configtests variable in
@@ -76,7 +76,8 @@ my $generator = $ARGV[3];
 
 our %configtests;
 
-my $qmakeCachePath = catfile($out_basedir, ".qmake.cache");
+my $qmakeCachePath = catfile($out_basedir, '.qmake.cache');
+my $configLogPath = catfile($out_basedir, 'config.log');
 
 my $QMAKE = catfile($qtbasedir, "bin", ($^O =~ /win32/i) ? 'qmake.exe' : 'qmake');
 if (!-x $QMAKE) {
@@ -162,36 +163,51 @@ sub hashesAreDifferent {
     }
 }
 
+
 ######################################################################
-# Syntax:  executeSomething
-# Params:  A list of things.
+# Syntax:  executeLoggedCommand()
+# Params:  path to executable, arguments
+#
+# This function is equivalent to system(), except that the command
+# details and output is placed in the configure log (only).
 #
-# Purpose: Executes the first arg, passing the list.
-#          stderr is redirected to stdout, and the output is captured.
-# Returns: The output.
+# Purpose: run a command and log the output
+# Returns: exit code and output.
 ######################################################################
-sub executeSomething {
-    my ($program, @args) = @_;
-
-    my $pid = open(KID_TO_READ, "-|");
-
-    my $output;
-
-    if ($pid) {   # parent
-        while (<KID_TO_READ>) {
-            $output = $output . $_;
-        }
-        close(KID_TO_READ) || $! == 0 || warn "\nFailed to execute $program: exited $?";
-    } else {
-        # redirect STDERR to STDOUT
-        open STDERR, ">&STDOUT";
-
-        # Exec something
-        exec ($program, @args) || die "\nCan't exec $program: $!\n";
-        # NOTREACHED
+sub executeLoggedCommand {
+    my (@command_with_args) = @_;
+
+    # Redirect all stdout, stderr into the config.log
+    my ($save_stdout, $save_stderr);
+    open($save_stdout, '>&', STDOUT) || die "save STDOUT: $!";
+    open($save_stderr, '>&', STDERR) || die "save STDERR: $!";
+
+    my $tmpName = File::Temp::tempnam(File::Spec->tmpdir(), 'log');
+    open(STDOUT, '>', $tmpName) || die "open $tmpName: $!";
+    open(STDERR, '>&', STDOUT) || die "redirect STDERR to STDOUT: $!";
+
+    print "+ @command_with_args\n";
+    my $exitCode = system(@command_with_args) >> 8;
+
+    # Put them back.
+    close(STDOUT);
+    close(STDERR);
+    open(STDOUT, '>&', $save_stdout) || die "restoring STDOUT: $!";
+    open(STDERR, '>&', $save_stderr) || die "restoring STDERR: $!";
+
+    # Append output to config log and return it.
+    my ($tmpFile, $configLog);
+    my $out = '';
+    open($tmpFile, '<', $tmpName) || die "open $tmpName: $!";
+    open($configLog, '>>', $configLogPath) || die "open $configLogPath: $!";
+    while (my $line = <$tmpFile>) {
+        print $configLog $line;
+        $out .= $line;
     }
-
-    return $output;
+    close($tmpFile);
+    close($configLog);
+    unlink($tmpName);
+    return ($exitCode, $out);
 }
 
 ######################################################################
@@ -211,10 +227,17 @@ sub executeSomething {
 sub executeTest {
     my ($testName) = @_;
 
+    {
+        my $fh;
+        open($fh, '>>', $configLogPath) || die "open $configLogPath: $!";
+        print $fh 'executing config test "',$testName, "\":\n";
+        close($fh);
+    }
+
     my $oldWorkingDir = getcwd();
     my $ret = 0;
 
-    my @QMAKEARGS = ('CONFIG-=debug_and_release');
+    my @QMAKEARGS = ('CONFIG-=debug_and_release', 'CONFIG-=app_bundle');
 
     my $testOutDir = catdir($out_basedir, 'config.tests', $testName);
 
@@ -222,7 +245,7 @@ sub executeTest {
     my $testOutFile1 = catfile($testOutDir, "$testName.exe");
     my $testOutFile2 = catfile($testOutDir, $testName);
 
-    if (abs_path($basedir) eq abs_path($out_basedir)) {
+    if ($basedir eq $out_basedir) {
         chdir $testOutDir or die "\nUnable to change to config test directory ($testOutDir): $!\n";
     } else { # shadow build
         if (! -e $testOutDir) {
@@ -236,30 +259,42 @@ sub executeTest {
     # First remove existing stuff (XXX this probably needs generator specific code, but hopefully
     # the target removal below will suffice)
     if (-e "Makefile") {
-        executeSomething($MAKE, 'distclean');
+        executeLoggedCommand($MAKE, 'distclean');
     }
 
     # and any targets that we might find that weren't distcleaned
     unlink $testOutFile1, $testOutFile2;
 
     # Run qmake && make
-    executeSomething($QMAKE, @QMAKEARGS);
-    my $makeOutput = executeSomething(($MAKE));
-
-    # If make prints "blah blah blah\nSkipped." we consider this a skipped test
-    if ($makeOutput !~ qr(^Skipped\.$)ms) {
-        # Check the test exists (can't reliably execute, especially for cross compilation)
-        if (-e $testOutFile1 or -e $testOutFile2) {
-            $ret = 1;
+    my ($qmakeExitCode, $qmakeOutput) = executeLoggedCommand($QMAKE, @QMAKEARGS);
+    if ($qmakeExitCode == 0) {
+        my ($makeExitCode, $makeOutput) = executeLoggedCommand($MAKE);
+
+        # If make prints "blah blah blah\nSkipped." we consider this a skipped test
+        if ($makeOutput !~ qr(^Skipped\.$)ms) {
+            # Check the test exists (can't reliably execute, especially for cross compilation)
+            if ($makeExitCode == 0 and (-e $testOutFile1 or -e $testOutFile2)) {
+                $ret = 1;
+            }
+        } else {
+            $ret = 2;
         }
-    } else {
-        $ret = 2;
     }
 
+    my $fh;
+    open($fh, '>>', $configLogPath) || die "open $configLogPath: $!";
+    print $fh 'config test "',$testName, '" completed with result ',$ret, "\n";
+    close($fh);
+
     chdir $oldWorkingDir or die "\nUnable to restore working directory: $!\n";
     return $ret;
 }
 
+# Remove existing config.log
+if (-e $configLogPath) {
+    unlink($configLogPath) || die "unlink $configLogPath: $!";
+}
+
 # Now run configuration tests
 # %configtests is a map from config test name to a map of parameters
 # e.g:
@@ -278,7 +313,7 @@ loadConfigTests();
 # Only do this step for modules that have config tests
 # (qtbase doesn't). We try to preserve existing contents (and furthermore
 # only write to .qmake.cache if the tests change)
-if (abs_path($out_basedir) ne abs_path($qtbasedir)) {
+if ($out_basedir ne $qtbasedir) {
     # Read any existing content
     my $existingContents = fileContents($qmakeCachePath);
     my %oldTestResults;
@@ -297,6 +332,11 @@ if (abs_path($out_basedir) ne abs_path($qtbasedir)) {
     # Turn off buffering
     $| = 1;
 
+    # Remove existing config.log
+    if (-e $configLogPath) {
+        unlink($configLogPath) || die "unlink $configLogPath: $!";
+    }
+
     # Now run the configuration tests
     print "Configuration tests:\n" if (%configtests);