Type families: new algorithm to solve equalities
[ghc-hetmet.git] / darcs-all
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 # Usage:
6 #
7 # ./darcs-all [-q] [-s] [--dph] [--extra] [--nofib] [--testsuite] get [darcs get flags]
8 #   This gets the GHC core repos, if they do not already exist.
9 #   -q says to be quite, and -s to be silent.
10 #   --dph, --extra, --nofib, --testsuite also get the dph library,
11 #                                        extralibs, nofib and testsuite
12 #                                        repos respectively
13 #   The darcs get flag you are most likely to want is --complete. By
14 #   default we pass darcs the --partial flag.
15 #
16 # ./darcs-all [-q] [-s] cmd [darcs cmd flags]
17 #   This runs the darcs "cmd" command, with any flags you give, in all
18 #   of the repos you have checked out. e.g.
19 #       ./darcs-all pull
20 #       ./darcs-all -q send --dry-run
21 #   -q says to be quite, and -s to be silent.
22
23 # Figure out where to get the other repositories from,
24 # based on where this GHC repo came from.
25 my $defaultrepo = `cat _darcs/prefs/defaultrepo`;
26 chomp $defaultrepo;
27 my $defaultrepo_base;
28 my $checked_out_tree;
29
30 if ($defaultrepo =~ /^...*:/) {
31     # HTTP or SSH
32     # Above regex says "at least two chars before the :", to avoid
33     # catching Win32 drives ("C:\").
34     $defaultrepo_base = $defaultrepo;
35     $defaultrepo_base =~ s#/[^/]+/?$##;
36     $checked_out_tree = 0;
37 }
38 elsif ($defaultrepo =~ /^\/|\.\.\/|.:(\/|\\)/) {
39     # Local filesystem, either absolute or relative path
40     # (assumes a checked-out tree):
41     $defaultrepo_base = $defaultrepo;
42     $checked_out_tree = 1;
43 }
44 else {
45     die "Couldn't work out defaultrepo";
46 }
47
48 my $verbose = 2;
49 my $ignore_failure = 0;
50
51 my %tags;
52
53 sub message {
54     if ($verbose >= 2) {
55         print "@_\n";
56     }
57 }
58
59 sub warning {
60     if ($verbose >= 1) {
61         print "warning: @_\n";
62     }
63 }
64
65 sub darcs {
66     message "== running darcs @_";
67     system ("darcs", @_) == 0
68         or $ignore_failure
69         or die "darcs failed: $?";
70 }
71
72 sub darcsall {
73     my $localpath;
74     my $path;
75     my $tag;
76     my @repos;
77
78     open IN, "< packages" or die "Can't open packages file";
79     @repos = <IN>;
80     close IN;
81
82     foreach (@repos) {
83         chomp;
84         if (/^([^# ]+) +(?:([^ ]+) +)?([^ ]+) +([^ ]+)$/) {
85             $localpath = $1;
86             $tag = defined($2) ? $2 : "";
87
88             if (-d "$localpath/_darcs") {
89                 darcs (@_, "--repodir", $localpath);
90             }
91             elsif ($tag eq "") {
92                 message "== Required repo $localpath is missing! Skipping";
93             }
94             else {
95                 message "== $localpath repo not present; skipping";
96             }
97         }
98         elsif (! /^(#.*)?$/) {
99             die "Bad line: $_";
100         }
101     }
102 }
103
104 sub darcsget {
105     my $r_flags;
106     my $localpath;
107     my $remotepath;
108     my $path;
109     my $tag;
110     my @repos;
111
112     if (! grep /(?:--complete|--partial)/, @_) {
113         warning("adding --partial, to override use --complete");
114         $r_flags = [@_, "--partial"];
115     }
116     else {
117         $r_flags = \@_;
118     }
119
120     open IN, "< packages" or die "Can't open packages file";
121     @repos = <IN>;
122     close IN;
123
124     foreach (@repos) {
125         chomp;
126         if (/^([^ ]+) +(?:([^ ]+) +)?([^ ]+) +([^ ]+)$/) {
127             $localpath = $1;
128             $tag = defined($2) ? $2 : "";
129             $remotepath = $3;
130
131             if ($checked_out_tree) {
132                 $path = "$defaultrepo_base/$localpath";
133             }
134             else {
135                 if ($remotepath =~ /^http:/) {
136                     $path = $remotepath;
137                 }
138                 else {
139                     $path = "$defaultrepo_base/$remotepath";
140                 }
141             }
142
143             if (($tag eq "") || defined($tags{$tag})) {
144                 if (-d $localpath) {
145                     warning("$localpath already present; omitting");
146                 }
147                 else {
148                     darcs (@$r_flags, $path, $localpath);
149                 }
150             }
151         }
152         elsif (! /^(#.*)?$/) {
153             die "Bad line: $_";
154         }
155     }
156 }
157
158 sub main {
159     if (! -d "_darcs" || ! -d "compiler") {
160         die "error: darcs-all must be run from the top level of the ghc tree."
161     }
162
163     while ($#_ ne -1) {
164         my $arg = shift;
165         # We handle -q here as well as lower down as we need to skip over it
166         # if it comes before the darcs command
167         if ($arg eq "-q") {
168             $verbose = 1;
169         }
170         elsif ($arg eq "-s") {
171             $verbose = 0;
172         }
173         # --dph says we grab the dph libs with 'get'.
174         # It has no effect on the other commands.
175         elsif ($arg eq "--dph") {
176             $tags{"dph"} = 1;
177         }
178         # --extra says we grab the extra libs with 'get'.
179         # It has no effect on the other commands.
180         elsif ($arg eq "--extra") {
181             $tags{"extralibs"} = 1;
182         }
183         # --nofib tells get to also grab the nofib repo.
184         # It has no effect on the other commands.
185         elsif ($arg eq "--nofib") {
186             $tags{"nofib"} = 1;
187         }
188         # --testsuite tells get to also grab the testsuite repo.
189         # It has no effect on the other commands.
190         elsif ($arg eq "--testsuite") {
191             $tags{"testsuite"} = 1;
192         }
193         else {
194             unshift @_, $arg;
195             if (grep /^-q$/, @_) {
196                 $verbose = 1;
197             }
198             last;
199         }
200     }
201
202     if ($#_ eq -1) {
203         die "What do you want to do?";
204     }
205     my $command = $_[0];
206     if ($command eq "get") {
207         darcsget @_;
208     }
209     else {
210         if ($command =~ /^(?:w|wh|wha|what|whats|whatsn|whatsne|whatsnew)$/) {
211             # Hack around whatsnew failing if there are no changes
212             $ignore_failure = 1;
213         }
214         darcsall @_;
215     }
216 }
217
218 main(@ARGV);
219