~ubuntu-branches/ubuntu/oneiric/enigmail/oneiric-updates

« back to all changes in this revision

Viewing changes to build/profile_pageloader.pl

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack
  • Date: 2010-04-10 01:42:24 UTC
  • Revision ID: james.westby@ubuntu.com-20100410014224-fbq9ui5x3b0h2t36
Tags: 2:1.0.1-0ubuntu1
* First releaase of enigmail 1.0.1 for tbird/icedove 3
  (LP: #527138)
* redo packaging from scratch 
  + add debian/make-orig target that uses xulrunner provided
    buildsystem + enigmail tarball to produce a proper orig.tar.gz
  + use debhelper 7 with mozilla-devscripts
  + use debian source format 3.0 (quilt)
  + patch enigmail to use frozen API only
    - add debian/patches/frozen_api.diff
  + patch build system to not link against -lxul - which isnt
    available for sdks produced by all-static apps like tbird
    - add debian/patches/build_system_dont_link_libxul.diff
  + add minimal build-depends to control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
# ***** BEGIN LICENSE BLOCK *****
 
3
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
4
#
 
5
# The contents of this file are subject to the Mozilla Public License Version
 
6
# 1.1 (the "License"); you may not use this file except in compliance with
 
7
# the License. You may obtain a copy of the License at
 
8
# http://www.mozilla.org/MPL/
 
9
#
 
10
# Software distributed under the License is distributed on an "AS IS" basis,
 
11
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
12
# for the specific language governing rights and limitations under the
 
13
# License.
 
14
#
 
15
# The Original Code is the Mozilla Browser code.
 
16
#
 
17
# The Initial Developer of the Original Code is
 
18
# Netscape Communications Corporation.
 
19
# Portions created by the Initial Developer are Copyright (C) 2002
 
20
# the Initial Developer. All Rights Reserved.
 
21
#
 
22
# Contributor(s):
 
23
#  Chris Mcafee <mcafee@netscape.com>
 
24
#  Brian Ryner <bryner@brianryner.com>
 
25
#
 
26
# Alternatively, the contents of this file may be used under the terms of
 
27
# either the GNU General Public License Version 2 or later (the "GPL"), or
 
28
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
29
# in which case the provisions of the GPL or the LGPL are applicable instead
 
30
# of those above. If you wish to allow use of your version of this file only
 
31
# under the terms of either the GPL or the LGPL, and not to allow others to
 
32
# use your version of this file under the terms of the MPL, indicate your
 
33
# decision by deleting the provisions above and replace them with the notice
 
34
# and other provisions required by the GPL or the LGPL. If you do not delete
 
35
# the provisions above, a recipient may use your version of this file under
 
36
# the terms of any one of the MPL, the GPL or the LGPL.
 
37
#
 
38
# ***** END LICENSE BLOCK *****
 
39
 
 
40
use Cwd;
 
41
use File::Find ();
 
42
 
 
43
use POSIX qw(sys_wait_h);
 
44
 
 
45
sub kill_process {
 
46
    my ($target_pid) = @_;
 
47
    my $start_time = time;
 
48
 
 
49
    # Try to kill and wait 10 seconds, then try a kill -9
 
50
    my $sig;
 
51
    for $sig ('TERM', 'KILL') {
 
52
        print "kill $sig $target_pid\n";
 
53
        kill $sig => $target_pid;
 
54
        my $interval_start = time;
 
55
        while (time - $interval_start < 10) {
 
56
            # the following will work with 'cygwin' perl on win32, but not
 
57
            # with 'MSWin32' (ActiveState) perl
 
58
            my $pid = waitpid($target_pid, POSIX::WNOHANG());
 
59
            if (($pid == $target_pid and POSIX::WIFEXITED($?)) or $pid == -1) {
 
60
                my $secs = time - $start_time;
 
61
                $secs = $secs == 1 ? '1 second' : "$secs seconds";
 
62
                print "Process killed. Took $secs to die.\n";
 
63
                return;
 
64
            }
 
65
            sleep 1;
 
66
        }
 
67
    }
 
68
    die "Unable to kill process: $target_pid";
 
69
}
 
70
 
 
71
# Stripped down version of fork_and_log().
 
72
sub system_fork_and_log {
 
73
    # Fork a sub process and log the output.
 
74
    my ($cmd) = @_;
 
75
 
 
76
    my $pid = fork; # Fork off a child process.
 
77
 
 
78
    unless ($pid) { # child
 
79
        exec { $cmd->[0] } @$cmd;
 
80
        die "Could not exec()";
 
81
    }
 
82
    return $pid;
 
83
}
 
84
 
 
85
 
 
86
sub wait_for_pid {
 
87
    # Wait for a process to exit or kill it if it takes too long.
 
88
    my ($pid, $timeout_secs) = @_;
 
89
    my ($exit_value, $signal_num, $dumped_core, $timed_out) = (0,0,0,0);
 
90
    my $sig_name;
 
91
    my $loop_count;
 
92
 
 
93
    die ("Invalid timeout value passed to wait_for_pid()\n")
 
94
        if ($timeout_secs <= 0);
 
95
 
 
96
    eval {
 
97
        $loop_count = 0;
 
98
        while (++$loop_count < $timeout_secs) {
 
99
            my $wait_pid = waitpid($pid, POSIX::WNOHANG());
 
100
            # the following will work with 'cygwin' perl on win32, but not 
 
101
            # with 'MSWin32' (ActiveState) perl
 
102
            last if ($wait_pid == $pid and POSIX::WIFEXITED($?)) or $wait_pid == -1;
 
103
            sleep 1;
 
104
        }
 
105
 
 
106
        $exit_value = $? >> 8;
 
107
        $signal_num = $? >> 127;
 
108
        $dumped_core = $? & 128;
 
109
        if ($loop_count >= $timeout_secs) {
 
110
            die "timeout";
 
111
        }
 
112
        return "done";
 
113
    };
 
114
 
 
115
    if ($@) {
 
116
        if ($@ =~ /timeout/) {
 
117
            kill_process($pid);
 
118
            $timed_out = 1;
 
119
        } else { # Died for some other reason.
 
120
            die; # Propagate the error up.
 
121
        }
 
122
    }
 
123
#    $sig_name = $signal_num ? signal_name($signal_num) : '';
 
124
#
 
125
#    return { timed_out=>$timed_out,
 
126
#             exit_value=>$exit_value,
 
127
#             sig_name=>$sig_name,
 
128
#             dumped_core=>$dumped_core };
 
129
}
 
130
 
 
131
# System version of run_cmd().
 
132
sub run_system_cmd {
 
133
    my ($cmd, $timeout_secs) = @_;
 
134
 
 
135
#    print_log "cmd = $cmd\n";
 
136
    my $pid = system_fork_and_log($cmd);
 
137
    my $result = wait_for_pid($pid, $timeout_secs);
 
138
 
 
139
    return $result;
 
140
}
 
141
 
 
142
#
 
143
# Given profile directory, find pref file hidden in salt directory.
 
144
# profile $Settings::MozProfileName must exist before calling this sub.
 
145
#
 
146
sub find_pref_file {
 
147
    my $profile_dir = shift;
 
148
 
 
149
    # default to *nix
 
150
    my $pref_file = "prefs.js";
 
151
 
 
152
    unless (-e $profile_dir) {
 
153
        return; # empty list
 
154
    }
 
155
 
 
156
    my $found = undef;
 
157
    my $sub = sub {$pref_file = $File::Find::name, $found++ if $pref_file eq $_};
 
158
    File::Find::find($sub, $profile_dir);
 
159
    unless ($found) {
 
160
        return; # empty list
 
161
    }
 
162
 
 
163
    return $pref_file;
 
164
}
 
165
 
 
166
my $topdir = cwd();
 
167
 
 
168
chdir $ENV{OBJDIR};
 
169
my $app_name = `grep "MOZ_APP_NAME      " config/autoconf.mk | sed "s/.*= //"`;
 
170
chomp($app_name);
 
171
 
 
172
# On mac, the app directory is the product name with the first
 
173
# letter capitalized
 
174
 
 
175
my $toolkit = `grep "MOZ_WIDGET_TOOLKIT        " config/autoconf.mk  |sed "s/.*= //"`;
 
176
chomp($toolkit);
 
177
 
 
178
if ($toolkit =~ /(mac|cocoa)/) {
 
179
    my $app_dir = uc(substr($app_name, 0, 1)).substr($app_name, 1);
 
180
    chdir "dist/$app_dir.app/Contents/MacOS";
 
181
} else {
 
182
    chdir "dist/bin";
 
183
}
 
184
 
 
185
my $bin_suffix = "";
 
186
if ($toolkit =~ /(windows|os2)/) {
 
187
    $bin_suffix = ".exe";
 
188
}
 
189
 
 
190
my $old_home = $ENV{HOME};
 
191
$ENV{HOME} = cwd();
 
192
 
 
193
# Create a profile to test with.
 
194
run_system_cmd(["./".$app_name.$bin_suffix, "-createProfile", "testprofile"], 45);
 
195
 
 
196
my $pref_file = find_pref_file(".mozilla/".$app_name);
 
197
open PREFS, ">>$pref_file";
 
198
# Add allow_scripts_to_close_windows; this lets us cleanly exit.
 
199
print PREFS "user_pref(\"dom.allow_scripts_to_close_windows\", true);\n";
 
200
# Suppress the default browser dialog since it keeps the test from starting.
 
201
print PREFS "user_pref(\"browser.shell.checkDefaultBrowser\", false);\n";
 
202
close PREFS;
 
203
 
 
204
# Run the pageload test.
 
205
run_system_cmd(["./".$app_name.$bin_suffix, $ENV{PAGELOAD_URL}."/loader.pl?maxcyc=2&delay=500&nocache=0&timeout=30000&auto=1"], 240);
 
206
 
 
207
# Start up again; this will gather data for reading global history and
 
208
# reading the fastload file.
 
209
run_system_cmd(["./".$app_name.$bin_suffix, "file://$topdir/build/profile_pageloader.html"], 45);
 
210
 
 
211
chdir $topdir;