#!/usr/bin/perl -w
####################################################################################################
#
# Modularization script for Qt
#
# Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
# Contact: Nokia Corporation (qt-info@nokia.com)
#
####################################################################################################
use strict;
use File::Basename;
use Carp 'confess';
use Cwd 'abs_path';
use Config;
=head2 prop - read a Pulse property from the environment
The conventional way to configure test scripts running within
Pulse is to use `properties'. These are simple key/value pairs.
Properties are imported into the script's environment with some
munging of property name into valid environment variable name.
For example, a property named `make.args' is in the environment
as `PULSE_MAKE_ARGS'.
See the Pulse documentation for more detail.
Examples:
=over
=item prop "make.args", "-j2";
Read the `make.args' property and default to `-j2' if not set.
=item prop "qt.branch";
Read the `qt.branch' property and die if it has not been set.
=back
=cut
sub prop
{
my ($prop, $default) = @_;
my $key = uc $prop;
$key =~ s/[^A-Z0-9]/_/g;
$key = 'PULSE_'.$key;
if (exists($ENV{$key})) {
return $ENV{$key};
}
elsif (defined($default)) {
return $default;
}
else {
confess "Property `$prop' was requested, but environment variable ".
"`$key' is not set and no default value was provided";
}
}
sub find_exe {
my ($exe) = @_;
return if (!defined($exe));
my @paths = split(/;/, $ENV{"PATH"});
foreach my $path (@paths) {
$path =~ s/\\$//g;
$path =~ s/\\/\//g;
my $file = $path . '/' . $exe;
return $file if ((-e $file) && (-f $file));
}
}
# Global parameters
our $build_test = 0;
our $run_autotests = 0;
our $clone_qtbundle = 0;
our $qtdir;
my $basepath = dirname(abs_path($0));
$basepath =~ s,\\,/,g;
$qtdir = $basepath . "/qt" if (!$qtdir);
sub showUsage {
print "$0 usage:\n";
print " -test Configure qt with -nokia-developer for autotest build\n";
print " -autotest Run the autotests locally\n";
print " -qtdir
A precloned Qt dir you want to modularize\n";
print " -clone-qtbundle Instead of modularizing, clone the qt-bundle repository and build that\n";
print " -? This help\n";
}
sub runAutotests {
# Pulse : You must either set these Environment Variables or uncomment the following lines
# Depending on the platform you are running this script
#$ENV{"PULSE_PLATFORM"} = "linux-g++";
# Please don't change this value, otherwise you will send the results to Testr
#$ENV{"PULSE_TESTS_TESTR"} = "0";
my @autotests = ("phonon", "qt3support", "qtbase", "qtmultimedia", "qtdeclarative", "qtscript", "qtsvg", "qttools", "qtxmlpatterns", "qtqa");
chdir($basepath) or die("Could not chdir to qt");
system_v("git clone qtgitreadonly:qa-dungeon/mainline.git $basepath/_qadungeon") and die("Could not clone qa-dungeon");
my $test;
foreach $test (@autotests) {
# The path to the tests you want to run.
$ENV{"PULSE_TESTS_DIR"} = "$basepath/qt/qt/$test/tests/auto";
system_v("perl $basepath/_qadungeon/tests/qt/qt_pulse_runtests.pl") and die("Could not run qt_pulse_runtests.pl for $test");
}
}
while ( @ARGV ) {
my $arg = shift @ARGV;
if ($arg eq "-?" || $arg eq "-h" || $arg eq "-help" || $arg eq "?") {
showUsage();
exit 0;
} elsif($arg eq "-test") {
$build_test = 1;
} elsif($arg eq "-autotest") {
$run_autotests = 1;
} elsif($arg eq "-clone-qtbundle") {
$clone_qtbundle = 1;
} elsif ($arg eq "-qtdir") {
$qtdir = shift @ARGV or die("-qtdir requires an argument");
} else {
print "Unknown option: $arg\n\n";
showUsage();
exit 1;
}
}
# `system', but also print the command
sub system_v
{
print "+ ";
print @_;
print "\n";
return system(@_);
}
if ($Config{'osname'} =~ /mswin/i) {
$ENV{"PATH"} .= ";C:\\Python26" if (-d "C:\\Python26");
$ENV{"PATH"} .= ";C:\\Jom\\bin" if (-d "C:\\Jom\\bin");
my $winQtdir = $qtdir;
$winQtdir =~ s,/,\\,g;
$ENV{"PATH"} = "$winQtdir\\qt\\qtbase\\bin;$ENV{PATH}";
} else {
$ENV{"PATH"} = "$qtdir/qt/qtbase/bin:$ENV{PATH}";
}
if (! -d "$qtdir/.git" && !$clone_qtbundle) {
system_v("git clone qtgitreadonly:qt/qt.git $qtdir") and die("Could not clone qt");
}
if (!$clone_qtbundle) {
chdir($qtdir) or die("Could not chdir to " . dirname($qtdir));
}
system_v("git reset --hard origin/master") and die("Could not reset master");
if ($clone_qtbundle) {
system_v("git clone git://scm.dev.nokia.troll.no/qt/qt-bundle.git qt") and die("Could not clone qt-bundle");
} else {
system_v("$basepath/modularize -redo -verbose") and die("Modularize script failed");
}
chdir("qt") or die("Could not chdir to qt");
system_v("git submodule update --init") and die("git submodule update failed");
if ($clone_qtbundle) {
my @ls = <*>;
foreach my $file (@ls) {
if (-d $file && $file !~ /^qtwebkit$/) {
system_v("cd $file && git reset --hard origin/master");
}
}
}
my $configure = "configure";
$configure = "./configure" if ($Config{'osname'} !~ /mswin/i);
my $configure_args = "-confirm-license -opensource -mp" if ($Config{'osname'} =~ /mswin/i);
$configure_args = "-confirm-license -opensource" if ($Config{'osname'} !~ /mswin/i);
$configure_args = "$configure_args -nokia-developer" if ($build_test);
# Allow configure options to be completely overriden from Pulse...
$configure_args = prop("configure.args", $configure_args);
# ... or just to append a few extra
$configure_args .= ' '.prop("configure.extra_args", "");
system_v("$configure $configure_args") and die("configure failed");
# only support nmake for Windows as fallback
my $make = "nmake";
# we support make for Linux and Mac
$make = "make " . prop("make.args", "-j4") if ($Config{'osname'} !~ /mswin/i);
# we support JOM / IncrediBuild for Windows
if ($Config{'osname'} =~ /mswin/i) {
# if (find_exe('xgconsole.exe') && find_exe('jom.exe')) {
# $make = "xgconsole /NOLOGO /COMMAND=\"jom.exe /NOLOGO " . prop("make.args", "-j20") . " /F Makefile\" /PROFILE=\"C:/Jom/bin/profile.xml\" /MAXCPUS=20";
# } elsif (find_exe('jom.exe')) {
if (find_exe('jom.exe')) {
$make = "jom " . prop("make.args", "-j20");
}
}
system_v("$make") and die("$make failed");
# Pulse : attempt to run autotests
runAutotests() if ($run_autotests);
exit 0;