X-Git-Url: https://git.exim.org/buildfarm-client.git/blobdiff_plain/3769c7ccb6a7f0089bb44c0e061a321aa2f4815e..b04f6889700e04f6a9d6ce14c7b29d86ec33d8e9:/run_branches diff --git a/run_branches b/run_branches index 20f3790..18ee919 100755 --- a/run_branches +++ b/run_branches @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl =comment @@ -34,8 +34,13 @@ if ($0 =~ /(.*)\.pl$/) { # Most of the client code assumes that our working directory # is the client code directory. +my %CALLED = ( + cwd => cwd(), + argv0 => $0, + argv => [@ARGV], # get a copy! +); chdir $RealBin or die "$0: Can't chdir to '$RealBin': $!\n"; -say "Changed working directory to '$RealBin'" if -t; +#say "Changed working directory to '$RealBin'" if -t; my %branch_last; my $run_build = './run_build'; @@ -73,22 +78,45 @@ $branch = 'global'; require $buildconf; # Check if auto-update is wanted and possible -if (not exists $EximBuild::Conf{auto_update} or $EximBuild::Conf{auto_update}) -{ - die "$0: auto-update not possible: need write permissions in @{[cwd]}\n" - if not -w '.'; - # http://stackoverflow.com/questions/3258243/check-if-pull-needed-in-git - system('git remote update') == 0 or die $? >> 8; - my ($upstream, $local, $base) = qx'git rev-parse ...@{upstream}'; die $? >> 8 if $?; - $base =~ s/^\^//; - - if ($upstream ne $local) { - die "$0: the merge base is not local anymore. Refusing to `git pull`\n" - if $base ne $local; - - # if we're the merge base, the ff-only should workkkkkk - system 'git pull --ff-only' +eval { + if (not exists $EximBuild::conf{auto_update} or $EximBuild::conf{auto_update}) + { + my $remote = $EximBuild::conf{auto_update} // 'origin'; + + die "auto-update not possible: need write permissions in @{[cwd]}\n" + if not -w '.'; + + # Get information about our remote and calculate the chance for a + # successfull auto-update. Based on: + # http://stackoverflow.com/questions/3258243/check-if-pull-needed-in-git + system("git fetch $remote") == 0 or die "'git fetch $remote' failed\n"; + my ($upstream, $local, $base) = qx'git rev-parse ...@{upstream}' or die "'git rev-parse' failed\n"; + + $base =~ s/^\^//; + + if ($upstream ne $local) { + + if ($base ne $local) { + die "the merge base is not local anymore. Refusing to `git pull`\n" + } + + # if we're the merge base, the ff-only should work + # except if there are local changes. We won't stop, if we + # fail to update, but we'll issue a warning + system("git pull --ff-only $remote") == 0 or die "git pull --ff-only\n"; + + say "re-execute after update"; + chdir $CALLED{cwd} or die "Can't chdir to $CALLED{cwd}: $!\n"; + exec $CALLED{argv0}, @{$CALLED{argv}}; + die "Can't re-exec\n"; + } } +}; + +if ($@) { + chomp $@; + warn "Automatic updated failed with `$@'\n" + ."Continue anyway\n"; } unless ( @@ -112,8 +140,8 @@ elsif ($EximBuild::conf{branches_to_build} =~ /^(ALL|HEAD_PLUS_LATEST|HEAD_PLUS_LATEST2)$/ ) { - # Need to set the path here so we make sure we pick up the right perl. - # It has to be the perl that the build script would choose + # Need to set the path here so we make sure we pick up the right Perl. + # It has to be the Perl that the build script would choose # i.e. specially *not* the MinGW SDK perl that is invoked for the # build script, which means we need to put the path back the way it was # when we're done @@ -131,15 +159,12 @@ elsif ($EximBuild::conf{branches_to_build} =~ @branches = apply_throttle(@branches); -my $global_lock_dir = - $EximBuild::conf{global_lock_dir} - ||$EximBuild::conf{build_root} - ||''; +my $global_lock_dir = $EximBuild::conf{global_lock_dir} + // $EximBuild::conf{build_root} + // die "$0: need global_lock_dir\n"; -unless ($global_lock_dir && -d $global_lock_dir) -{ - die "no global lock directory: $global_lock_dir"; -} +die "$0: need r/w permissions for directory '$global_lock_dir'\n" + if not -d -w $global_lock_dir; # acquire the lock @@ -190,10 +215,10 @@ sub run_branch # Explicitly use perl from the path (and not this perl, so don't use $^X) # This script needs to run on Cygwin with non-cygwin perl if it's running # in tandem with AS/MinGW perl, since Cygwin perl doesn't honor locks - # the samne way, and the global lock fails. But the build script needs + # the same way, and the global lock fails. But the build script needs # to run with the native perl, even on Cygwin, which it picks up from # the path. (Head exploding yet?). - system("perl",@args); + system(perl => @args); } sub branch_last_sort