5 Copyright (c) 2003-2010, Andrew Dunstan
7 See accompanying License file for license details
11 use vars qw($VERSION); $VERSION = 'REL_0.1';
15 use Fcntl qw(:flock :seek);
16 use EximBuild::Options;
23 ($run_build = $0) =~ s/run_branches/run_build/;
25 my($run_all, $run_one);
27 'run-all' => \$run_all,
28 'run-one' => \$run_one,
31 # process the command line
32 EximBuild::Options::fetch_options(%extra_options);
34 # no non-option args allowed here
35 die("$0: non-option arguments not permitted")
38 die "only one of --run-all and --run-one permitted"
39 if ($run_all && $run_one);
41 die "need one of --run-all and --run-one"
42 unless ($run_all || $run_one);
45 die "need group searchable homedir"
46 unless (stat($ENV{HOME}) & 0550 == 0550);
48 # set up a "branch" variable for processing the config file
59 ref $EximBuild::conf{branches_to_build} eq 'ARRAY'
60 &&@{$EximBuild::conf{branches_to_build}}
62 ||$EximBuild::conf{branches_to_build} =~
63 /^(ALL|HEAD_PLUS_LATEST|HEAD_PLUS_LATEST2)$/
66 die "no branches_to_build specified in $buildconf";
70 if (ref $EximBuild::conf{branches_to_build})
72 @branches = @{$EximBuild::conf{branches_to_build}};
74 elsif ($EximBuild::conf{branches_to_build} =~
75 /^(ALL|HEAD_PLUS_LATEST|HEAD_PLUS_LATEST2)$/ )
78 # Need to set the path here so we make sure we pick up the right perl.
79 # It has to be the perl that the build script would choose
80 # i.e. specially *not* the MinGW SDK perl that is invoked for the
81 # build script, which means we need to put the path back the way it was
83 my $save_path = $ENV{PATH};
84 $ENV{PATH} = $EximBuild::conf{build_env}->{PATH}
85 if ($EximBuild::conf{build_env}->{PATH});
86 (my $url = $EximBuild::conf{target}) =~s/cgi-bin.*/branches_of_interest.txt/;
87 my $branches_of_interest = `perl -MLWP::Simple -e "getprint(q{$url})"`;
88 die "getting branches of interest" unless $branches_of_interest;
89 $ENV{PATH} = $save_path;
90 push(@branches,$_)foreach (split(/\s+/,$branches_of_interest));
91 #splice(@branches,0,-2)
92 # if $EximBuild::conf{branches_to_build} eq 'HEAD_PLUS_LATEST';
93 #splice(@branches,0,-3)
94 # if $EximBuild::conf{branches_to_build} eq 'HEAD_PLUS_LATEST2';
97 @branches = apply_throttle(@branches);
100 $EximBuild::conf{global_lock_dir}
101 ||$EximBuild::conf{build_root}
104 unless ($global_lock_dir && -d $global_lock_dir)
106 die "no global lock directory: $global_lock_dir";
113 my $lockfilename = "$global_lock_dir/GLOBAL.lck";
115 open($lockfile, ">$lockfilename") || die "opening lockfile: $!";
117 if ( !flock($lockfile,LOCK_EX|LOCK_NB) )
119 print "Another process holds the lock on " ."$lockfilename. Exiting.\n"
126 foreach my $brnch(@branches)
134 # sort the branches by the order in which they last did actual work
135 # then try running them in that order until one does some work
137 %branch_last = map {$_ => find_last_status($_)} @branches;
138 foreach my $brnch(sort branch_last_sort @branches)
141 my $new_status = find_last_status($brnch);
142 last if $new_status != $branch_last{$brnch};
148 ##########################################################
153 my @args = ($run_build,EximBuild::Options::standard_option_list(), $branch);
155 # Explicitly use perl from the path (and not this perl, so don't use $^X)
156 # This script needs to run on Cygwin with non-cygwin perl if it's running
157 # in tandem with AS/MinGW perl, since Cygwin perl doesn't honor locks
158 # the samne way, and the global lock fails. But the build script needs
159 # to run with the native perl, even on Cygwin, which it picks up from
160 # the path. (Head exploding yet?).
161 system("perl",@args);
166 return $branch_last{$a} <=> $branch_last{$b};
173 "$EximBuild::conf{build_root}/$brnch/$EximBuild::conf{animal}.last.status";
174 return 0 unless (-e $status_file);
176 open($handle,$status_file) || dir $!;
186 return @branches unless exists $EximBuild::conf{throttle};
188 my %throttle = %{$EximBuild::conf{throttle}};
190 # implement throttle keywords ALL !HEAD and !RECENT
193 if (exists $throttle{ALL})
195 @candidates = @branches;
196 $replacement = $throttle{ALL};
198 elsif (exists $throttle{'!HEAD'})
200 @candidates = grep { $_ ne 'HEAD' } @branches;
201 $replacement = $throttle{'!HEAD'};
203 elsif (exists $throttle{'!RECENT'})
206 # sort branches, make sure we get numeric major version sorting right
207 my @stable = grep { $_ ne 'HEAD' } @branches;
208 s/^REL(\d)_/0$1/ foreach (@stable);
209 @stable = sort @stable;
210 s/^REL0/REL/ foreach (@stable);
211 pop @stable; # remove latest
212 @candidates = @stable;
213 $replacement = $throttle{'!RECENT'};
215 foreach my $cand (@candidates)
218 # only supply this for the branch if there isn't already
220 $throttle{$cand} ||= $replacement;
223 # apply throttle filters
224 foreach my $branch(@branches)
226 my $this_throttle = $throttle{$branch};
227 unless (defined $this_throttle)
229 push(@result,$branch);
232 my $minh = $this_throttle->{min_hours_since};
233 my $ts = find_last_status($branch);
237 &&($minh && $minh < ((time - $ts) / 3600.0)));
238 if (exists $this_throttle->{allowed_hours})
240 my @allowed_hours = split(/,/,$this_throttle->{allowed_hours});
241 my $hour = (localtime(time))[2];
242 next unless grep {$_ == $hour} @allowed_hours;
244 push(@result,$branch);