Debian Codegraph @

mozilla-head-check

raw
1 #! /usr/bin/perl
2
3 use strict;
4 use warnings;
5 use Cwd();
6 use File::Temp();
7 use File::Spec();
8 use FileHandle();
9 use English qw( -no_match_vars );
10 use Carp();
11 use DirHandle();
12 use Sys::Syslog();
13
14 our $VERSION = '1.70';
15
16 MAIN: {
17 my $facility = 'LOG_LOCAL0';
18 my $absolute_program_name;
19 if ( File::Spec->file_name_is_absolute($PROGRAM_NAME) ) {
20 $absolute_program_name = $PROGRAM_NAME;
21 }
22 else {
23 $absolute_program_name =
24 File::Spec->catfile( Cwd::cwd(), $PROGRAM_NAME );
25 }
26 my ( $original_volume, $original_directories, $original_name ) =
27 File::Spec->splitpath($absolute_program_name);
28 my $ident = $original_name;
29 my $base_directory =
30 File::Spec->catdir( $original_volume, $original_directories );
31 my $mozilla_central_directory = File::Spec->canonpath(
32 File::Spec->catdir( $base_directory, q[..], 'mozilla-central' ) );
33 build_firefox($mozilla_central_directory);
34 my $changeset = most_recent_firefox_changeset($mozilla_central_directory);
35 my $firefox_path = File::Spec->catfile( $mozilla_central_directory,
36 'obj-x86_64-pc-linux-gnu', 'dist', 'bin', 'firefox' );
37 local $ENV{SSH_AUTH_SOCK} = get_ssh_auth_sock();
38 local $ENV{SSH_AUTH_SOCK} = get_ssh_auth_sock();
39 local $ENV{FIREFOX_BINARY} = $firefox_path;
40 local $ENV{RELEASE_TESTING} = 1;
41 system {$EXECUTABLE_NAME} $EXECUTABLE_NAME, 'Makefile.PL'
42 and Carp::croak(q[Failed to 'perl Makefile.PL']);
43 system {'cover'} 'cover', '-test'
44 and Carp::croak(q[Failed to 'cover -test']);
45 system {'make'} 'make', 'clean'
46 and Carp::croak(q[Failed to 'make clean']);
47 system {'rm'} 'rm', 'Makefile.old'
48 and Carp::croak(q[Failed to 'rm Makefile.old']);
49 Sys::Syslog::openlog( $ident, 'cons', $facility );
50 Sys::Syslog::syslog( Sys::Syslog::LOG_INFO(),
51 "Passed cover -test at mozilla-central changeset $changeset" );
52 Sys::Syslog::closelog();
53 }
54
55 sub get_ssh_auth_sock {
56 if ( $ENV{SSH_AUTH_SOCK1} ) {
57 return $ENV{SSH_AUTH_SOCK};
58 }
59 else {
60 my $tmp_directory = File::Spec->tmpdir();
61 my $tmp_handle = DirHandle->new($tmp_directory)
62 or Carp::croak(
63 "Failed to open directory $tmp_directory:$EXTENDED_OS_ERROR");
64 while ( my $agent_entry = $tmp_handle->read() ) {
65 if ( $agent_entry =~ /^(ssh\-[[:alnum:]]+)$/smx ) {
66 my $ssh_agent_directory =
67 File::Spec->catfile( $tmp_directory, $1 );
68 if ( my $agent_file =
69 find_ssh_agent_file($ssh_agent_directory) )
70 {
71 return $agent_file;
72 }
73 }
74 }
75 }
76 return;
77 }
78
79 sub find_ssh_agent_file {
80 my ($ssh_agent_directory) = @_;
81
82 my $ssh_agent_handle = DirHandle->new($ssh_agent_directory)
83 or Carp::croak(
84 "Failed to open directory $ssh_agent_directory:$EXTENDED_OS_ERROR");
85 while ( my $pid_entry = $ssh_agent_handle->read() ) {
86 if ( $pid_entry =~ /^agent[.](\d+)$/smx ) {
87 my $ppid = $1;
88 if ( kill 0, $ppid ) {
89 return File::Spec->catfile( $ssh_agent_directory,
90 'agent.' . $ppid );
91 }
92 }
93 }
94 return;
95 }
96
97 sub build_firefox {
98 my ($mozilla_central_directory) = @_;
99 my ( $mozilla_volume, $mozilla_directories, $mozilla_name ) =
100 File::Spec->splitpath($mozilla_central_directory);
101 my $mozilla_parent_directory =
102 File::Spec->catdir( $mozilla_volume, $mozilla_directories );
103 if ( my $pid = fork ) {
104 waitpid $pid, 0;
105 if ( $CHILD_ERROR != 0 ) {
106 Carp::croak("Failed to checkout on $mozilla_central_directory");
107 }
108 }
109 elsif ( defined $pid ) {
110 eval {
111 if ( !-d $mozilla_central_directory ) {
112 chdir $mozilla_parent_directory
113 or Carp::croak(
114 "Failed to chdir $mozilla_parent_directory:$EXTENDED_OS_ERROR"
115 );
116 system {'hg'} 'hg', 'clone',
117 'https://hg.mozilla.org/mozilla-central/', $mozilla_name
118 and Carp::croak(
119 "Failed to 'hg clone https://hg.mozilla.org/mozilla-central/ $mozilla_name:$EXTENDED_OS_ERROR"
120 );
121 }
122 chdir $mozilla_central_directory
123 or Carp::croak(
124 "Failed to chdir $mozilla_central_directory:$EXTENDED_OS_ERROR"
125 );
126 system {'hg'} 'hg', 'pull'
127 and
128 Carp::croak("Failed to 'hg pull' on $mozilla_central_directory");
129 system {'hg'} 'hg', 'update', '--clean'
130 and Carp::croak(
131 "Failed to 'hg update --clean' on $mozilla_central_directory");
132 system {'./mach'} './mach', 'clobber'
133 and Carp::croak(
134 "Failed to './mach clobber' on $mozilla_central_directory");
135 system {'./mach'} './mach', 'build'
136 and Carp::croak(
137 "Failed to './mach build' on $mozilla_central_directory");
138 exit 0;
139 } or do {
140 chomp $EVAL_ERROR;
141 Carp::carp($EVAL_ERROR);
142 };
143 exit 1;
144 }
145 else {
146 Carp::croak("Failed to fork:$OS_ERROR");
147 }
148 return;
149 }
150
151 sub most_recent_firefox_changeset {
152 my ($mozilla_central_directory) = @_;
153 my $handle = FileHandle->new();
154 my $changeset;
155 if ( my $pid = $handle->open(q[-|]) ) {
156 while ( my $line = <$handle> ) {
157 if ( $line =~ /^changeset:[ ]+(\d+:[[:xdigit:]]+)\s*$/smx ) {
158 ($changeset) = ($1);
159 }
160 }
161 close $handle or Carp::croak(q[Failed to successfully run 'hg heads']);
162
163 }
164 elsif ( defined $pid ) {
165 eval {
166 chdir $mozilla_central_directory
167 or Carp::croak(
168 "Failed to chdir $mozilla_central_directory:$EXTENDED_OS_ERROR"
169 );
170 exec {'hg'} 'hg', 'heads'
171 or Carp::croak("Failed to exec 'hg':$EXTENDED_OS_ERROR");
172 } or do {
173 chomp $EVAL_ERROR;
174 Carp::carp($EVAL_ERROR);
175 };
176 exit 1;
177 }
178 else {
179 Carp::croak("Failed to fork:$OS_ERROR");
180 }
181 return $changeset;
182 }