Fix Trac #2141: invalid record update
[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 # --boot-only says we only want to push bootlibs, not extralibs
15 my $boot_only = 0;
16 # --push or --pull?
17 my $push_pull = "push";
18
19 sub message {
20     if ($verbose) {
21         print "@_\n";
22     }
23 }
24
25 sub warning {
26     print "warning: @_\n";
27 }
28
29 sub darcs {
30     message "== running darcs @_";
31     system ("darcs", @_) == 0
32         or $ignore_failure
33         or die "darcs failed: $?";
34 }
35
36 sub darcs_push {
37     darcs ($push_pull, "--no-set-default", @_);
38 }
39
40 sub pushall {
41     my $dir;
42     my $ghcrepo = $checked_out ? $reporoot : "$reporoot/ghc";
43     darcs_push ($ghcrepo, @_);
44     for $dir (@top_dirs) {
45         if (-d $dir && -d "$dir/_darcs") {
46             darcs_push ("$reporoot/$dir", @_, "--repodir", $dir);
47         }
48         else {
49             message "== $dir not present or not a repository; skipping";
50         }
51     }
52     my $library_lists = $boot_only
53                       ? "libraries/boot-packages"
54                       : "libraries/boot-packages libraries/extra-packages";
55     for my $pkg (`cat $library_lists`) {
56         chomp $pkg;
57         $dir = "libraries/$pkg";
58         if (-d "$dir") {
59             darcs_push ("$reporoot/$dir", @_, "--repodir", "$dir");
60         }
61         else {
62             warning("$pkg doesn't exist, use 'darcs-all get' to get it");
63         }
64     }
65 }
66
67 sub main {
68     if (! -d "_darcs" || ! -d "compiler") {
69         die "error: darcs-all must be run from the top level of the ghc tree."
70     }
71
72     if ($#_ ne -1) {
73         while ($#_ ne -1) {
74             my $arg = shift;
75             # We handle -q here as well as lower down as we need to skip
76             # over it if it comes before the darcs command
77             if ($arg eq "-q") {
78                 $verbose = 0;
79             }
80             elsif ($arg eq "--ignore-failure") {
81                 $ignore_failure = 1;
82             }
83             elsif ($arg eq "--checked-out") {
84                 $checked_out = 1;
85             }
86             elsif ($arg eq "--boot-only") {
87                 $boot_only = 1;
88             }
89             elsif ($arg eq "--push") {
90                 $push_pull = "push";
91             }
92             elsif ($arg eq "--pull") {
93                 $push_pull = "pull";
94             }
95             else {
96                 $reporoot = $arg;
97                 if (grep /^-q$/, @_) {
98                     $verbose = 0;
99                 }
100                 last;
101             }
102         }
103     }
104     else {
105         die "Where do you want to push to?";
106     }
107
108     pushall (@_);
109 }
110
111 main(@ARGV);
112