5 Copyright (c) 2003-2010, Andrew Dunstan
7 See accompanying License file for license details
11 use vars qw($VERSION); $VERSION = 'REL_0.1';
17 use Fcntl qw(:flock :seek);
19 use FindBin qw($RealBin);
23 use EximBuild::Options;
27 # Complain on old-style use (.pl extension), but only if a
28 # terminal is available.
29 if ($0 =~ /(.*)\.pl$/) {
30 die "$0: Please use `@{[join ' ' => $1, @ARGV]}' instead.\n"
35 # Most of the client code assumes that our working directory
36 # is the client code directory.
37 chdir $RealBin or die "$0: Can't chdir to '$RealBin': $!\n";
38 say "Changed working directory to '$RealBin'" if -t;
41 my $run_build = './run_build';
43 my($run_all, $run_one);
45 'run-all' => \$run_all,
46 'run-one' => \$run_one,
49 # process the command line
50 EximBuild::Options::fetch_options(%extra_options);
52 # no non-option args allowed here
53 die("$0: non-option arguments not permitted")
56 die "$0: only one of --run-all and --run-one permitted"
57 if ($run_all && $run_one);
59 die "$0: need one of --run-all and --run-one"
60 unless ($run_all || $run_one);
63 die "$0: need group searchable homedir"
64 unless (stat($ENV{HOME}) & 0550 == 0550);
66 # set up a "branch" variable for processing the config file
77 ref $EximBuild::conf{branches_to_build} eq 'ARRAY'
78 &&@{$EximBuild::conf{branches_to_build}}
80 ||$EximBuild::conf{branches_to_build} =~
81 /^(ALL|HEAD_PLUS_LATEST|HEAD_PLUS_LATEST2)$/
84 die "no branches_to_build specified in $buildconf";
88 if (ref $EximBuild::conf{branches_to_build})
90 @branches = @{$EximBuild::conf{branches_to_build}};
92 elsif ($EximBuild::conf{branches_to_build} =~
93 /^(ALL|HEAD_PLUS_LATEST|HEAD_PLUS_LATEST2)$/ )
96 # Need to set the path here so we make sure we pick up the right perl.
97 # It has to be the perl that the build script would choose
98 # i.e. specially *not* the MinGW SDK perl that is invoked for the
99 # build script, which means we need to put the path back the way it was
101 local $ENV{PATH} = $EximBuild::conf{build_env}->{PATH}
102 if ($EximBuild::conf{build_env}->{PATH});
103 (my $url = $EximBuild::conf{target}) =~s/cgi-bin.*/branches_of_interest.txt/;
104 my $branches_of_interest = `perl -MLWP::Simple -e "getprint(q{$url})"`;
105 die "getting branches of interest" unless $branches_of_interest;
106 push(@branches,$_)foreach (split(/\s+/,$branches_of_interest));
107 #splice(@branches,0,-2)
108 # if $EximBuild::conf{branches_to_build} eq 'HEAD_PLUS_LATEST';
109 #splice(@branches,0,-3)
110 # if $EximBuild::conf{branches_to_build} eq 'HEAD_PLUS_LATEST2';
113 @branches = apply_throttle(@branches);
115 my $global_lock_dir =
116 $EximBuild::conf{global_lock_dir}
117 ||$EximBuild::conf{build_root}
120 unless ($global_lock_dir && -d $global_lock_dir)
122 die "no global lock directory: $global_lock_dir";
129 my $lockfilename = "$global_lock_dir/GLOBAL.lck";
131 open($lockfile, ">$lockfilename") || die "opening lockfile: $!";
133 if ( !flock($lockfile,LOCK_EX|LOCK_NB) )
135 print "Another process holds the lock on " ."$lockfilename. Exiting.\n"
142 foreach my $brnch(@branches)
150 # sort the branches by the order in which they last did actual work
151 # then try running them in that order until one does some work
153 %branch_last = map {$_ => find_last_status($_)} @branches;
154 foreach my $brnch(sort branch_last_sort @branches)
157 my $new_status = find_last_status($brnch);
158 last if $new_status != $branch_last{$brnch};
164 ##########################################################
169 my @args = ($run_build,EximBuild::Options::standard_option_list(), $branch);
171 # Explicitly use perl from the path (and not this perl, so don't use $^X)
172 # This script needs to run on Cygwin with non-cygwin perl if it's running
173 # in tandem with AS/MinGW perl, since Cygwin perl doesn't honor locks
174 # the samne way, and the global lock fails. But the build script needs
175 # to run with the native perl, even on Cygwin, which it picks up from
176 # the path. (Head exploding yet?).
177 system("perl",@args);
182 return $branch_last{$a} <=> $branch_last{$b};
189 "$EximBuild::conf{build_root}/$brnch/$EximBuild::conf{animal}.last.status";
190 return 0 unless (-e $status_file);
192 open($handle,$status_file) || dir $!;
202 return @branches unless exists $EximBuild::conf{throttle};
204 my %throttle = %{$EximBuild::conf{throttle}};
206 # implement throttle keywords ALL !HEAD and !RECENT
209 if (exists $throttle{ALL})
211 @candidates = @branches;
212 $replacement = $throttle{ALL};
214 elsif (exists $throttle{'!HEAD'})
216 @candidates = grep { $_ ne 'HEAD' } @branches;
217 $replacement = $throttle{'!HEAD'};
219 elsif (exists $throttle{'!RECENT'})
222 # sort branches, make sure we get numeric major version sorting right
223 my @stable = grep { $_ ne 'HEAD' } @branches;
224 s/^REL(\d)_/0$1/ foreach (@stable);
225 @stable = sort @stable;
226 s/^REL0/REL/ foreach (@stable);
227 pop @stable; # remove latest
228 @candidates = @stable;
229 $replacement = $throttle{'!RECENT'};
231 foreach my $cand (@candidates)
234 # only supply this for the branch if there isn't already
236 $throttle{$cand} ||= $replacement;
239 # apply throttle filters
240 foreach my $branch(@branches)
242 my $this_throttle = $throttle{$branch};
243 unless (defined $this_throttle)
245 push(@result,$branch);
248 my $minh = $this_throttle->{min_hours_since};
249 my $ts = find_last_status($branch);
253 &&($minh && $minh < ((time - $ts) / 3600.0)));
254 if (exists $this_throttle->{allowed_hours})
256 my @allowed_hours = split(/,/,$this_throttle->{allowed_hours});
257 my $hour = (localtime(time))[2];
258 next unless grep {$_ == $hour} @allowed_hours;
260 push(@result,$branch);