Building/Rebuilding: darcs-all-30032009.diff

File darcs-all-30032009.diff, 3.3 KB (added by claus, 6 years ago)

modification to darcs-all (March 2009), to improve reporting

  • darcs-all

    old new  
    5252
    5353my %tags;
    5454
     55my %warnings;
     56my %conflicts;
     57my %missing;
     58
    5559sub message {
    5660    if ($verbose >= 2) {
    5761        print "@_\n";
     
    6670
    6771sub darcs {
    6872    message "== running darcs @_";
    69     system ("darcs", @_) == 0
     73
     74    # run darcs, track std and err output
     75    open(DARCS,"darcs @_ 2>&1 |")
     76        or $ignore_failure
     77        or die "can't start darcs: $?";
     78
     79    # keep per-package record of warnings, errors and conflicts
     80    my $previous = "";
     81    while (<DARCS>) {
     82      if (/^Warning/ || /^darcs/ || /^realdarcs/ || /^Backing/) {
     83        $warnings{$_[$#_]} .= $_;
     84      } elsif ($previous =~ /^We have conflicts/) {
     85        $conflicts{$_[$#_]} .= $_;
     86      }
     87      $previous = $_;
     88      print $_;
     89    }
     90    close(DARCS)
    7091        or $ignore_failure
    71         or die "darcs failed: $?";
     92        or die "darcs failed ($!): $?";
    7293}
    7394
    7495sub darcsall {
    7596    my $localpath;
    7697    my $path;
    7798    my $tag;
     99    my %modtime;
    78100    my @repos;
    79101
     102    # read and close packages before calling darcs, which might
     103    # try to update that file
    80104    open IN, "< packages" or die "Can't open packages file";
     105
     106    # keep track of who we are
     107    $modtime{"darcs-all"} = (stat("darcs-all"))[9];
     108    $modtime{"packages"}  = (stat("packages"))[9];
    81109    @repos = <IN>;
    82110    close IN;
    83111
     
    89117
    90118            if (-d "$localpath/_darcs") {
    91119                darcs (@_, "--repodir", $localpath);
     120
     121                # if we have updated ourselves, all bets are off
     122                if ($localpath eq ".") {
     123                  my $darcs_all_mod = ((stat("darcs-all"))[9] != $modtime{"darcs-all"});
     124                  my $packages_mod  = ((stat("packages"))[9] != $modtime{"packages"});
     125                  if ($darcs_all_mod || $packages_mod) {
     126                      summary();
     127                      die "'darcs-all' ".($darcs_all_mod?"(changed)":"").
     128                      " or 'packages' ".($packages_mod?"(changed)":"")." updated;\n".
     129                      "please re-run your darcs-all command";
     130                    }
     131                }
    92132            }
    93133            elsif ($tag eq "") {
    94134                message "== Required repo $localpath is missing! Skipping";
     135                $missing{$localpath} = "(required repo!)";
    95136            }
    96137            else {
    97138                message "== $localpath repo not present; skipping";
     139                $missing{$localpath} = "(optional '$tag' repo)";
    98140            }
    99141        }
    100142        elsif (! /^(#.*)?$/) {
    101143            die "Bad line: $_";
    102144        }
    103145    }
     146    summary();
     147}
     148
     149# summarize warnings and conflicts
     150sub summary {
     151    my $package;
     152    if (scalar(%warnings)) {
     153      print "\n-- there are Warnings\n";
     154      foreach $package (keys%warnings) {
     155        print "-- Warnings for $package:\n$warnings{$package}\n";
     156      }
     157    }
     158    if (scalar(%conflicts)) {
     159      print "\n-- there are Conflicts\n";
     160      foreach $package (keys%conflicts) {
     161        print "-- Conflicts in $package:\n$conflicts{$package}\n";
     162      }
     163    }
     164    if (scalar(%missing)) {
     165      print "\n-- there are missing packages:\n";
     166      foreach $package (keys%missing) {
     167        print "$package $missing{$package}\n";
     168      }
     169    }
    104170}
    105171
    106172sub darcsget {