#!/usr/bin/perl
-######################################################################
+#############################################################################
+##
+## 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.
+##
+## $QT_BEGIN_LICENSE:LGPL$
+## GNU Lesser General Public License Usage
+## This file may be used under the terms of the GNU Lesser General Public
+## License version 2.1 as published by the Free Software Foundation and
+## appearing in the file LICENSE.LGPL included in the packaging of this
+## file. Please review the following information to ensure the GNU Lesser
+## General Public License version 2.1 requirements will be met:
+## http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+##
+## In addition, as a special exception, Nokia gives you certain additional
+## rights. These rights are described in the Nokia Qt LGPL Exception
+## version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+##
+## GNU General Public License Usage
+## Alternatively, this file may be used under the terms of the GNU General
+## Public License version 3.0 as published by the Free Software Foundation
+## and appearing in the file LICENSE.GPL included in the packaging of this
+## file. Please review the following information to ensure the GNU General
+## Public License version 3.0 requirements will be met:
+## http://www.gnu.org/copyleft/gpl.html.
+##
+## Other Usage
+## Alternatively, this file may be used in accordance with the terms and
+## conditions contained in a signed written agreement between you and Nokia.
+##
+##
+##
+##
+##
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
#
# Runs any module configuration tests
#
#
# configtests $basedir $out_basedir $qtbasedir $quietmode
#
-# Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-# Contact: Nokia Corporation (qt-info@nokia.com)
-#
-######################################################################
use strict;
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
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) {
}
}
+
######################################################################
-# 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);
}
######################################################################
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);
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) {
# 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:
# 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;
# 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);
my $newContents = $existingContents;
# Strip out any existing config test results
- $newContents =~ s/^config_test_.*$//gms;
- $newContents =~ s/^# Compile time test results.*$//gms;
+ $newContents =~ s/^config_test_[^\$]*$//gm;
+ $newContents =~ s/^# Compile time test results[^\$]*$//gm;
# Add any remaining content and make sure we start on a new line
if ($newContents and chop $newContents ne '\n') {
}
}
+ # Remove blank lines
+ $newContents =~ s/^[\s]*$//gms;
+
# and open the file
open my $cacheFileHandle, ">$qmakeCachePath" or die "Unable to open $qmakeCachePath for writing: $!\n";