Add a push-all script
[ghc-hetmet.git] / push-all
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 my @top_dirs = ("nofib", "testsuite");
6
7 my $reporoot;
8
9 my $verbose = 1;
10 my $ignore_failure = 0;
11
12 # --checked-out says we are pushing to a checked out tree
13 my $checked_out = 0;
14
15 sub message {
16     if ($verbose) {
17         print "@_\n";
18     }
19 }
20
21 sub warning {
22     print "warning: @_\n";
23 }
24
25 sub darcs {
26     message "== running darcs @_";
27     system ("darcs", @_) == 0
28         or $ignore_failure
29         or die "darcs failed: $?";
30 }
31
32 sub darcs_push {
33     darcs ("push", "--no-set-default", @_);
34 }
35
36 sub pushall {
37     my $dir;
38     my $ghcrepo = $checked_out ? $reporoot : "$reporoot/ghc";
39     darcs_push ($ghcrepo, @_);
40     for $dir (@top_dirs) {
41         if (-d $dir && -d "$dir/_darcs") {
42             darcs_push ("$reporoot/$dir", @_, "--repodir", $dir);
43         }
44         else {
45             message "== $dir not present or not a repository; skipping";
46         }
47     }
48     for my $pkg (`cat libraries/core-packages libraries/extra-packages`) {
49         chomp $pkg;
50         $dir = "libraries/$pkg";
51         if (-d "$dir") {
52             darcs_push ("$reporoot/$dir", @_, "--repodir", "$dir");
53         }
54         else {
55             warning("$pkg doesn't exist, use 'darcs-all get' to get it");
56         }
57     }
58 }
59
60 sub main {
61     if (! -d "_darcs" || ! -d "compiler") {
62         die "error: darcs-all must be run from the top level of the ghc tree."
63     }
64
65     if ($#_ ne -1) {
66         while ($#_ ne -1) {
67             my $arg = shift;
68             # We handle -q here as well as lower down as we need to skip
69             # over it if it comes before the darcs command
70             if ($arg eq "-q") {
71                 $verbose = 0;
72             }
73             elsif ($arg eq "--checked-out") {
74                 $checked_out = 1;
75             }
76             else {
77                 $reporoot = $arg;
78                 if (grep /^-q$/, @_) {
79                     $verbose = 0;
80                 }
81                 last;
82             }
83         }
84     }
85     else {
86         die "Where do you want to push to?";
87     }
88
89     pushall (@_);
90 }
91
92 main(@ARGV);
93