-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmozilla-head-check
executable file
·182 lines (173 loc) · 6.12 KB
/
mozilla-head-check
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
#! /usr/bin/perl
use strict;
use warnings;
use Cwd();
use File::Temp();
use File::Spec();
use FileHandle();
use English qw( -no_match_vars );
use Carp();
use DirHandle();
use Sys::Syslog();
our $VERSION = '1.62';
MAIN: {
my $facility = 'LOG_LOCAL0';
my $absolute_program_name;
if ( File::Spec->file_name_is_absolute($PROGRAM_NAME) ) {
$absolute_program_name = $PROGRAM_NAME;
}
else {
$absolute_program_name =
File::Spec->catfile( Cwd::cwd(), $PROGRAM_NAME );
}
my ( $original_volume, $original_directories, $original_name ) =
File::Spec->splitpath($absolute_program_name);
my $ident = $original_name;
my $base_directory =
File::Spec->catdir( $original_volume, $original_directories );
my $mozilla_central_directory = File::Spec->canonpath(
File::Spec->catdir( $base_directory, q[..], 'mozilla-central' ) );
build_firefox($mozilla_central_directory);
my $changeset = most_recent_firefox_changeset($mozilla_central_directory);
my $firefox_path = File::Spec->catfile( $mozilla_central_directory,
'obj-x86_64-pc-linux-gnu', 'dist', 'bin', 'firefox' );
local $ENV{SSH_AUTH_SOCK} = get_ssh_auth_sock();
local $ENV{SSH_AUTH_SOCK} = get_ssh_auth_sock();
local $ENV{FIREFOX_BINARY} = $firefox_path;
local $ENV{RELEASE_TESTING} = 1;
system {$EXECUTABLE_NAME} $EXECUTABLE_NAME, 'Makefile.PL'
and Carp::croak(q[Failed to 'perl Makefile.PL']);
system {'cover'} 'cover', '-test'
and Carp::croak(q[Failed to 'cover -test']);
system {'make'} 'make', 'clean'
and Carp::croak(q[Failed to 'make clean']);
system {'rm'} 'rm', 'Makefile.old'
and Carp::croak(q[Failed to 'rm Makefile.old']);
Sys::Syslog::openlog( $ident, 'cons', $facility );
Sys::Syslog::syslog( Sys::Syslog::LOG_INFO(),
"Passed cover -test at mozilla-central changeset $changeset" );
Sys::Syslog::closelog();
}
sub get_ssh_auth_sock {
if ( $ENV{SSH_AUTH_SOCK1} ) {
return $ENV{SSH_AUTH_SOCK};
}
else {
my $tmp_directory = File::Spec->tmpdir();
my $tmp_handle = DirHandle->new($tmp_directory)
or Carp::croak(
"Failed to open directory $tmp_directory:$EXTENDED_OS_ERROR");
while ( my $agent_entry = $tmp_handle->read() ) {
if ( $agent_entry =~ /^(ssh\-[[:alnum:]]+)$/smx ) {
my $ssh_agent_directory =
File::Spec->catfile( $tmp_directory, $1 );
if ( my $agent_file =
find_ssh_agent_file($ssh_agent_directory) )
{
return $agent_file;
}
}
}
}
return;
}
sub find_ssh_agent_file {
my ($ssh_agent_directory) = @_;
my $ssh_agent_handle = DirHandle->new($ssh_agent_directory)
or Carp::croak(
"Failed to open directory $ssh_agent_directory:$EXTENDED_OS_ERROR");
while ( my $pid_entry = $ssh_agent_handle->read() ) {
if ( $pid_entry =~ /^agent[.](\d+)$/smx ) {
my $ppid = $1;
if ( kill 0, $ppid ) {
return File::Spec->catfile( $ssh_agent_directory,
'agent.' . $ppid );
}
}
}
return;
}
sub build_firefox {
my ($mozilla_central_directory) = @_;
my ( $mozilla_volume, $mozilla_directories, $mozilla_name ) =
File::Spec->splitpath($mozilla_central_directory);
my $mozilla_parent_directory =
File::Spec->catdir( $mozilla_volume, $mozilla_directories );
if ( my $pid = fork ) {
waitpid $pid, 0;
if ( $CHILD_ERROR != 0 ) {
Carp::croak("Failed to checkout on $mozilla_central_directory");
}
}
elsif ( defined $pid ) {
eval {
if ( !-d $mozilla_central_directory ) {
chdir $mozilla_parent_directory
or Carp::croak(
"Failed to chdir $mozilla_parent_directory:$EXTENDED_OS_ERROR"
);
system {'hg'} 'hg', 'clone',
'https://hg.mozilla.org/mozilla-central/', $mozilla_name
and Carp::croak(
"Failed to 'hg clone https://hg.mozilla.org/mozilla-central/ $mozilla_name:$EXTENDED_OS_ERROR"
);
}
chdir $mozilla_central_directory
or Carp::croak(
"Failed to chdir $mozilla_central_directory:$EXTENDED_OS_ERROR"
);
system {'hg'} 'hg', 'pull'
and
Carp::croak("Failed to 'hg pull' on $mozilla_central_directory");
system {'hg'} 'hg', 'update', '--clean'
and Carp::croak(
"Failed to 'hg update --clean' on $mozilla_central_directory");
system {'./mach'} './mach', 'clobber'
and Carp::croak(
"Failed to './mach clobber' on $mozilla_central_directory");
system {'./mach'} './mach', 'build'
and Carp::croak(
"Failed to './mach build' on $mozilla_central_directory");
exit 0;
} or do {
chomp $EVAL_ERROR;
Carp::carp($EVAL_ERROR);
};
exit 1;
}
else {
Carp::croak("Failed to fork:$OS_ERROR");
}
return;
}
sub most_recent_firefox_changeset {
my ($mozilla_central_directory) = @_;
my $handle = FileHandle->new();
my $changeset;
if ( my $pid = $handle->open(q[-|]) ) {
while ( my $line = <$handle> ) {
if ( $line =~ /^changeset:[ ]+(\d+:[[:xdigit:]]+)\s*$/smx ) {
($changeset) = ($1);
}
}
close $handle or Carp::croak(q[Failed to successfully run 'hg heads']);
}
elsif ( defined $pid ) {
eval {
chdir $mozilla_central_directory
or Carp::croak(
"Failed to chdir $mozilla_central_directory:$EXTENDED_OS_ERROR"
);
exec {'hg'} 'hg', 'heads'
or Carp::croak("Failed to exec 'hg':$EXTENDED_OS_ERROR");
} or do {
chomp $EVAL_ERROR;
Carp::carp($EVAL_ERROR);
};
exit 1;
}
else {
Carp::croak("Failed to fork:$OS_ERROR");
}
return $changeset;
}