Make TcGenDeriv warning-free
[ghc-hetmet.git] / darcs-all
index 2fd61a8..046e589 100644 (file)
--- a/darcs-all
+++ b/darcs-all
-#!/bin/sh
+#!/usr/bin/perl -w
 
-set -e
+use strict;
 
-top_dirs="nofib testsuite"
+my @top_dirs = ("nofib", "testsuite");
 
-default_repo_root="http://darcs.haskell.org/"
-default_lib_repo_root=$default_repo_root/packages
+# Figure out where to get the other repositories from,
+# based on where this GHC repo came from.
+my $defaultrepo = `cat _darcs/prefs/defaultrepo`;
+chomp $defaultrepo;
+my $defaultrepo_base;
+my $defaultrepo_lib;
 
-quiet=NO
+if ($defaultrepo =~ /:/) {
+    # HTTP or SSH
+    $defaultrepo_base = $defaultrepo;
+    $defaultrepo_base =~ s#/[^/]+/?$##;
+    $defaultrepo_lib = "$defaultrepo_base/packages";
+}
+elsif ($defaultrepo =~ /^\//) {
+    # Local filesystem, absolute path (assumes a checked-out tree):
+    $defaultrepo_base = $defaultrepo;
+    $defaultrepo_lib = "$defaultrepo/libraries";
+}
+elsif ($defaultrepo =~ /^..\//) {
+    # Local filesystem, relative path (assumes a checked-out tree):
+    $defaultrepo_base = $defaultrepo;
+    $defaultrepo_lib = "$defaultrepo/libraries";
+}
+else {
+    die "Couldn't work out defaultrepo";
+}
+
+my $verbose = 2;
+my $ignore_failure = 0;
+
+# --extra says we grab the extra libs with 'get'.  It has no effect on
+# the other commands.
+my $extra = 0;
+# --nofib/--testsuite tell get to also grab the respective repos.
+# They have no effect on the other commands.
+my $nofib = 0;
+my $testsuite = 0;
+
+sub message {
+    if ($verbose >= 2) {
+        print "@_\n";
+    }
+}
+
+sub warning {
+    if ($verbose >= 1) {
+        print "warning: @_\n";
+    }
+}
+
+sub darcs {
+    message "== running darcs @_";
+    system ("darcs", @_) == 0
+        or $ignore_failure
+        or die "darcs failed: $?";
+}
 
-function message()
-{
-  if [ "$quiet" = "NO" ]; then
-     echo $*
-  fi
+sub darcsall {
+    my @packages;
+    darcs @_;
+    for my $dir (@top_dirs) {
+        if (-d $dir && -d "$dir/_darcs") {
+            darcs (@_, "--repodir", $dir);
+        }
+        else {
+            message "== $dir not present or not a repository; skipping";
+        }
+    }
+    for my $path (<libraries/*/_darcs>) {
+        chomp $path;
+        if ($path =~ m#/(.*)/#) {
+            my $pkg = $1;
+            # bootstrapping.* are just copies of other repos; we don't
+            # update them directly.
+            if ($pkg !~ /bootstrapping/) {
+                darcs (@_, "--repodir", "libraries/$pkg");
+            }
+        }
+        else {
+            die "that pattern can't fail!";
+        }
+    }
+    @packages = `cat libraries/boot-packages`;
+    # @packages = `cat libraries/boot-packages libraries/extra-packages`;
+    for my $pkg (@packages) {
+        chomp $pkg;
+        if (! -d "libraries/$pkg") {
+            warning("$pkg doesn't exist, use 'darcs-all get' to get it");
+        }
+    }
 }
 
-function darcsall()
-{
-  message "== running darcs $* at the top level"
-  darcs $*
-  for dir in $top_dirs; do
-    if test -d $dir -a -d $dir/_darcs; then
-       message "== running darcs $* in $dir"
-       darcs $* --repodir $dir
-    else
-       message "== $dir not present or not a repository; skipping"
-    fi
-  done
-  for pkg in `cat libraries/default-packages`; do
-    if test -d libraries/$pkg; then
-       message "== running darcs $* in libraries/$pkg"
-       darcs $* --repodir libraries/$pkg
-    else
-       echo "warning: $dir doesn't seem to exist, use 'darcs-all get' to get it"
-    fi
-  done
+sub darcsgetpackage {
+    my ($get_it, $r_flags, $repo_root, $package) = @_;
+
+    if ($get_it) {
+        if (-d $package) {
+            warning("$package already present; omitting");
+        }
+        else {
+            darcs (@$r_flags, "$repo_root/$package");
+        }
+    }
 }
 
-function darcsget()
-{
-  case $* in
-    *--partial*) ;;
-    *) echo "warning: adding --partial, to override use --complete"
-  esac
-
-  repo_root=`cat _darcs/prefs/defaultrepo`
-  case $repo_root in
-    /*) lib_repos=$repo_root/libraries;;
-    *)  lib_repos=$default_lib_repo_root;;
-  esac
-
-  cd libraries
-  for pkg in `cat default-packages`; do
-    if test -d $pkg; then
-       echo "warning: $pkg already present; omitting"
-    else
-       repo=$lib_repos/$pkg
-       message "== running darcs get --partial $* $repo"
-       darcs get --partial $* $repo
-    fi
-  done
+sub darcsget {
+    my $r_flags;
+    if (! grep /(?:--complete|--partial)/, @_) {
+        warning("adding --partial, to override use --complete");
+        $r_flags = [@_, "--partial"];
+    }
+    else {
+        $r_flags = \@_;
+    }
+
+    darcsgetpackage($nofib,     $r_flags, $defaultrepo_base, "nofib");
+    darcsgetpackage($testsuite, $r_flags, $defaultrepo_base, "testsuite");
+
+    chdir "libraries";
+
+    my @packages;
+    if ($extra) {
+        @packages = `cat boot-packages extra-packages`;
+    }
+    else {
+        @packages = `cat boot-packages`;
+    }
+
+    for my $pkg (@packages) {
+        chomp $pkg;
+        darcsgetpackage(1, $r_flags, $defaultrepo_lib, $pkg);
+    }
 }
 
-if test ! -d _darcs -o ! -d ghc; then
-  echo "error: darcs-all must be run from the top level of the ghc tree."
-  exit 1;
-fi
-
-case $* in
-  *-q*) quiet=YES;;
-esac
-
-case $1 in
-  get)  shift; darcsget $*;;
-  # Hack around whatsnew failing if there are no changes
-  w|wh|wha|what|whats|whatsn|whatsne|whatsnew) set +e; darcsall $*;;
-  *) darcsall $*;;
-esac
+sub main {
+    if (! -d "_darcs" || ! -d "compiler") {
+        die "error: darcs-all must be run from the top level of the ghc tree."
+    }
+
+    while ($#_ ne -1) {
+        my $arg = shift;
+        # We handle -q here as well as lower down as we need to skip over it
+        # if it comes before the darcs command
+        if ($arg eq "-q") {
+            $verbose = 1;
+        }
+        elsif ($arg eq "-s") {
+            $verbose = 0;
+        }
+        elsif ($arg eq "--extra") {
+            $extra = 1;
+        }
+        elsif ($arg eq "--nofib") {
+            $nofib = 1;
+        }
+        elsif ($arg eq "--testsuite") {
+            $testsuite = 1;
+        }
+        else {
+            unshift @_, $arg;
+            if (grep /^-q$/, @_) {
+                $verbose = 1;
+            }
+            last;
+        }
+    }
+
+    if ($#_ eq -1) {
+        die "What do you want to do?";
+    }
+    my $command = $_[0];
+    if ($command eq "get") {
+        darcsget @_;
+    }
+    else {
+        if ($command =~ /^(?:w|wh|wha|what|whats|whatsn|whatsne|whatsnew)$/) {
+            # Hack around whatsnew failing if there are no changes
+            $ignore_failure = 1;
+        }
+        darcsall @_;
+    }
+}
+
+main(@ARGV);
+