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);
44 # set up a "branch" variable for processing the config file
55 ref $EximBuild::conf{branches_to_build} eq 'ARRAY'
56 &&@{$EximBuild::conf{branches_to_build}}
58 ||$EximBuild::conf{branches_to_build} =~
59 /^(ALL|HEAD_PLUS_LATEST|HEAD_PLUS_LATEST2)$/
62 die "no branches_to_build specified in $buildconf";
66 if (ref $EximBuild::conf{branches_to_build})
68 @branches = @{$EximBuild::conf{branches_to_build}};
70 elsif ($EximBuild::conf{branches_to_build} =~
71 /^(ALL|HEAD_PLUS_LATEST|HEAD_PLUS_LATEST2)$/ )
74 # Need to set the path here so we make sure we pick up the right perl.
75 # It has to be the perl that the build script would choose
76 # i.e. specially *not* the MinGW SDK perl that is invoked for the
77 # build script, which means we need to put the path back the way it was
79 my $save_path = $ENV{PATH};
80 $ENV{PATH} = $EximBuild::conf{build_env}->{PATH}
81 if ($EximBuild::conf{build_env}->{PATH});
82 (my $url = $EximBuild::conf{target}) =~s/cgi-bin.*/branches_of_interest.txt/;
83 my $branches_of_interest = `perl -MLWP::Simple -e "getprint(q{$url})"`;
84 die "getting branches of interest" unless $branches_of_interest;
85 $ENV{PATH} = $save_path;
86 push(@branches,$_)foreach (split(/\s+/,$branches_of_interest));
87 #splice(@branches,0,-2)
88 # if $EximBuild::conf{branches_to_build} eq 'HEAD_PLUS_LATEST';
89 #splice(@branches,0,-3)
90 # if $EximBuild::conf{branches_to_build} eq 'HEAD_PLUS_LATEST2';
93 @branches = apply_throttle(@branches);
96 $EximBuild::conf{global_lock_dir}
97 ||$EximBuild::conf{build_root}
100 unless ($global_lock_dir && -d $global_lock_dir)
102 die "no global lock directory: $global_lock_dir";
109 my $lockfilename = "$global_lock_dir/GLOBAL.lck";
111 open($lockfile, ">$lockfilename") || die "opening lockfile: $!";
113 if ( !flock($lockfile,LOCK_EX|LOCK_NB) )
115 print "Another process holds the lock on " ."$lockfilename. Exiting.\n"
122 foreach my $brnch(@branches)
130 # sort the branches by the order in which they last did actual work
131 # then try running them in that order until one does some work
133 %branch_last = map {$_ => find_last_status($_)} @branches;
134 foreach my $brnch(sort branch_last_sort @branches)
137 my $new_status = find_last_status($brnch);
138 last if $new_status != $branch_last{$brnch};
144 ##########################################################
149 my @args = ($run_build,EximBuild::Options::standard_option_list(), $branch);
151 # Explicitly use perl from the path (and not this perl, so don't use $^X)
152 # This script needs to run on Cygwin with non-cygwin perl if it's running
153 # in tandem with AS/MinGW perl, since Cygwin perl doesn't honor locks
154 # the samne way, and the global lock fails. But the build script needs
155 # to run with the native perl, even on Cygwin, which it picks up from
156 # the path. (Head exploding yet?).
157 system("perl",@args);
162 return $branch_last{$a} <=> $branch_last{$b};
169 "$EximBuild::conf{build_root}/$brnch/$EximBuild::conf{animal}.last.status";
170 return 0 unless (-e $status_file);
172 open($handle,$status_file) || dir $!;
182 return @branches unless exists $EximBuild::conf{throttle};
184 my %throttle = %{$EximBuild::conf{throttle}};
186 # implement throttle keywords ALL !HEAD and !RECENT
189 if (exists $throttle{ALL})
191 @candidates = @branches;
192 $replacement = $throttle{ALL};
194 elsif (exists $throttle{'!HEAD'})
196 @candidates = grep { $_ ne 'HEAD' } @branches;
197 $replacement = $throttle{'!HEAD'};
199 elsif (exists $throttle{'!RECENT'})
202 # sort branches, make sure we get numeric major version sorting right
203 my @stable = grep { $_ ne 'HEAD' } @branches;
204 s/^REL(\d)_/0$1/ foreach (@stable);
205 @stable = sort @stable;
206 s/^REL0/REL/ foreach (@stable);
207 pop @stable; # remove latest
208 @candidates = @stable;
209 $replacement = $throttle{'!RECENT'};
211 foreach my $cand (@candidates)
214 # only supply this for the branch if there isn't already
216 $throttle{$cand} ||= $replacement;
219 # apply throttle filters
220 foreach my $branch(@branches)
222 my $this_throttle = $throttle{$branch};
223 unless (defined $this_throttle)
225 push(@result,$branch);
228 my $minh = $this_throttle->{min_hours_since};
229 my $ts = find_last_status($branch);
233 &&($minh && $minh < ((time - $ts) / 3600.0)));
234 if (exists $this_throttle->{allowed_hours})
236 my @allowed_hours = split(/,/,$this_throttle->{allowed_hours});
237 my $hour = (localtime(time))[2];
238 next unless grep {$_ == $hour} @allowed_hours;
240 push(@result,$branch);