summaryrefslogtreecommitdiffstats
path: root/pulse-build-script
blob: f7e8c6da332cf7c6658ce394c3a69b0671e372af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/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_qt5  = 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 <dir>       A precloned Qt dir you want to modularize\n";
    print "  -clone-qt5    Instead of modularizing, clone the qt5 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 = ("qtphonon", "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";
      $ENV{"QT_MODULE_TO_TEST"} = "$basepath/qt/qt/$test";
      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-qt5") {
        $clone_qt5 = 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_qt5) {
    system_v("git clone qtgitreadonly:qt/qt.git $qtdir") and die("Could not clone qt");
}

if (!$clone_qt5) {
    chdir($qtdir) or die("Could not chdir to " . dirname($qtdir));
}

system_v("git reset --hard origin/master") and die("Could not reset master");

my $modularize_options = "";
$modularize_options .= "-zero-move-graft" if ($Config{'osname'} =~ /linux/i);

if ($clone_qt5) {
    system_v("git clone git://scm.dev.nokia.troll.no/qt/qt5.git qt") and die("Could not clone qt5");
} else {
    system_v("$basepath/modularize -redo -verbose $modularize_options") 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_qt5) {
    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;