darcs-all 10.4 KB
Newer Older
Ian Lynagh's avatar
Ian Lynagh committed
1
#!/usr/bin/perl -w
2

Ian Lynagh's avatar
Ian Lynagh committed
3
use strict;
4

Ian Lynagh's avatar
Ian Lynagh committed
5
6
# Usage:
#
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# ./darcs-all [-q] [-s] [-i] [-r repo]
#             [--nofib] [--testsuite] [--checked-out] cmd [darcs flags]
#
# Applies the darcs command "cmd" to each repository in the tree.
#
# e.g.
#      ./darcs-all -r http://darcs.haskell.org/ghc get
#          To get any repos which do not exist in the local tree
#
#      ./darcs-all -r ~/ghc-validate push
#          To push all your repos to the ~/ghc-validate tree
#
#      ./darcs-all pull -a
#          To pull everything from the default repos
#
#      ./darc-all push --dry-run
#          To see what local patches you have relative to the main repos
#
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -------------- Flags -------------------
#   -q says to be quite, and -s to be silent.
#
#   -i says to ignore darcs errors and move on to the next repository
#
#   -r repo says to use repo as the location of package repositories
#
#   --checked-out says that the remote repo is in checked-out layout, as
#   opposed to the layout used for the main repo.  By default a repo on
#   the local filesystem is assumed to be checked-out, and repos accessed
#   via HTTP or SSH are assumed to be in the main repo layout; use
#   --checked-out to override the latter.
#
#   --nofib, --testsuite also get the nofib and testsuite repos respectively
#
#   The darcs get flag you are most likely to want is --complete. By
#   default we pass darcs the --partial flag.
#
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# ------------ Which repos to use -------------
# darcs-all uses the following algorithm to decide which remote repos to use
#
#  It always computes the remote repos from a single base, $repo_base
#  How is $repo_base set?  
#    If you say "-r repo", then that's $repo_base
#    othewise $repo_base is set thus:
#       look in _darcs/prefs/defaultrepo, 
#       and remove the trailing 'ghc'
#
#  Then darcs-all iterates over the package found in the file
#  ./packages, which has entries like:
#         libraries/array  packages/array  darcs
#    or, in general
#         <local-path>  <remote-path> <vcs>
# 
#    If $repo_base looks like a local filesystem path, or if you give
#    the --checked-out flag, darcs-all works on repos of form
#          $repo_base/<local-path>
#    otherwise darcs-all works on repos of form
#          $repo_base/<remote-path>
#    This logic lets you say
#      both    darcs-all -r http://darcs.haskell.org/ghc-6.12 pull
#      and     darcs-all -r ../HEAD pull
#    The latter is called a "checked-out tree".

# NB: darcs-all *ignores* the defaultrepo of all repos other than the
# root one.  So the remote repos must be laid out in one of the two
# formats given by <local-path> and <remote-path> in the file 'packages'.

Ian Lynagh's avatar
Ian Lynagh committed
73

74
75
$| = 1; # autoflush stdout after each print, to avoid output after die

76
my $defaultrepo;
77

Ian Lynagh's avatar
Ian Lynagh committed
78
my $verbose = 2;
Ian Lynagh's avatar
Ian Lynagh committed
79
my $ignore_failure = 0;
80
my $want_remote_repo = 0;
81
my $checked_out_flag = 0;
82

Ian Lynagh's avatar
Ian Lynagh committed
83
my %tags;
Ian Lynagh's avatar
Ian Lynagh committed
84

85
86
87
88
89
90
91
92
93
94
95
96
97
98
# Figure out where to get the other repositories from.
sub getrepo {
    my $basedir = ".";
    my $repo = $defaultrepo || `cat $basedir/_darcs/prefs/defaultrepo`;
    chomp $repo;

    my $repo_base;
    my $checked_out_tree;

    if ($repo =~ /^...*:/) {
        # HTTP or SSH
        # Above regex says "at least two chars before the :", to avoid
        # catching Win32 drives ("C:\").
        $repo_base = $repo;
99
100
101
102
103
104
105
106

        # --checked-out is needed if you want to use a checked-out repo
        # over SSH or HTTP
        if ($checked_out_flag) {
            $checked_out_tree = 1;
        } else {
            $checked_out_tree = 0;
        }
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133

        # Don't drop the last part of the path if specified with -r, as
        # it expects repos of the form:
        #
        #   http://darcs.haskell.org
        #
        # rather than
        #   
        #   http://darcs.haskell.org/ghc
        #
        if (!$defaultrepo) {
            $repo_base =~ s#/[^/]+/?$##;
        }
    }
    elsif ($repo =~ /^\/|\.\.\/|.:(\/|\\)/) {
        # Local filesystem, either absolute or relative path
        # (assumes a checked-out tree):
        $repo_base = $repo;
        $checked_out_tree = 1;
    }
    else {
        die "Couldn't work out repo";
    }

    return $repo_base, $checked_out_tree;
}

Ian Lynagh's avatar
Ian Lynagh committed
134
sub message {
Ian Lynagh's avatar
Ian Lynagh committed
135
    if ($verbose >= 2) {
Ian Lynagh's avatar
Ian Lynagh committed
136
137
138
139
140
        print "@_\n";
    }
}

sub warning {
Ian Lynagh's avatar
Ian Lynagh committed
141
142
143
    if ($verbose >= 1) {
        print "warning: @_\n";
    }
Ian Lynagh's avatar
Ian Lynagh committed
144
145
146
147
148
}

sub darcs {
    message "== running darcs @_";
    system ("darcs", @_) == 0
149
150
       or $ignore_failure
       or die "darcs failed: $?";
Ian Lynagh's avatar
Ian Lynagh committed
151
152
153
}

sub darcsall {
Ian Lynagh's avatar
Ian Lynagh committed
154
    my $localpath;
155
    my $remotepath;
Ian Lynagh's avatar
Ian Lynagh committed
156
157
    my $path;
    my $tag;
158
    my @repos;
159
    my $command = $_[0];
160
    my $line;
Ian Lynagh's avatar
Ian Lynagh committed
161

162
163
    my ($repo_base, $checked_out_tree) = getrepo();

Ian Lynagh's avatar
Ian Lynagh committed
164
    open IN, "< packages" or die "Can't open packages file";
165
166
167
    @repos = <IN>;
    close IN;

168
    $line = 0;
Ian Lynagh's avatar
Ian Lynagh committed
169
    foreach (@repos) {
Ian Lynagh's avatar
Ian Lynagh committed
170
        chomp;
171
        $line++;
172
        if (/^([^# ]+) +([^ ]+) +([^ ]+) +([^ ]+) +([^ ]+)$/) {
Ian Lynagh's avatar
Ian Lynagh committed
173
            $localpath = $1;
174
            $tag = $2;
175
176
177
178
179
180
            $remotepath = $3;

            if ($checked_out_tree) {
                $path = "$repo_base/$localpath";
            }
            else {
181
                $path = "$repo_base/$remotepath";
182
            }
Ian Lynagh's avatar
Ian Lynagh committed
183

Ian Lynagh's avatar
Ian Lynagh committed
184
            if (-d "$localpath/_darcs") {
185
                if ($want_remote_repo) {
186
187
188
189
190
191
                    if ($command =~ /^opt/) {
                        # Allows ./darcs-all optimize --relink
                        darcs (@_, "--repodir", $localpath, "--sibling=$path");
                    } else {
                        darcs (@_, "--repodir", $localpath, $path);
                    }
192
193
194
                } else {
                    darcs (@_, "--repodir", $localpath);
                }
Ian Lynagh's avatar
Ian Lynagh committed
195
            }
196
            elsif ($tag eq "-") {
Ian Lynagh's avatar
Ian Lynagh committed
197
198
199
200
201
                message "== Required repo $localpath is missing! Skipping";
            }
            else {
                message "== $localpath repo not present; skipping";
            }
Ian Lynagh's avatar
Ian Lynagh committed
202
        }
203
        elsif (! /^(#.*)?$/) {
204
            die "Bad content on line $line of packages file: $_";
Ian Lynagh's avatar
Ian Lynagh committed
205
206
207
208
209
210
        }
    }
}

sub darcsget {
    my $r_flags;
Ian Lynagh's avatar
Ian Lynagh committed
211
212
213
214
    my $localpath;
    my $remotepath;
    my $path;
    my $tag;
215
    my @repos;
216
    my $line;
Ian Lynagh's avatar
Ian Lynagh committed
217

218
219
    my ($repo_base, $checked_out_tree) = getrepo();

Simon Marlow's avatar
Simon Marlow committed
220
    if (! grep /(?:--complete|--partial|--lazy)/, @_) {
Ian Lynagh's avatar
Ian Lynagh committed
221
222
223
224
225
226
227
        warning("adding --partial, to override use --complete");
        $r_flags = [@_, "--partial"];
    }
    else {
        $r_flags = \@_;
    }

Ian Lynagh's avatar
Ian Lynagh committed
228
    open IN, "< packages" or die "Can't open packages file";
229
230
231
    @repos = <IN>;
    close IN;

232
    $line = 0;
233
    foreach (@repos) {
Ian Lynagh's avatar
Ian Lynagh committed
234
        chomp;
235
        $line++;
236
        if (/^([^ ]+) +([^ ]+) +([^ ]+) +([^ ]+) +([^ ]+)$/) {
Ian Lynagh's avatar
Ian Lynagh committed
237
            $localpath = $1;
238
            $tag = $2;
Ian Lynagh's avatar
Ian Lynagh committed
239
            $remotepath = $3;
Ian Lynagh's avatar
Ian Lynagh committed
240

Ian Lynagh's avatar
Ian Lynagh committed
241
            if ($checked_out_tree) {
242
                $path = "$repo_base/$localpath";
Ian Lynagh's avatar
Ian Lynagh committed
243
244
            }
            else {
245
                $path = "$repo_base/$remotepath";
Ian Lynagh's avatar
Ian Lynagh committed
246
            }
Ian Lynagh's avatar
Ian Lynagh committed
247

248
            if (($tag eq "-") || defined($tags{$tag})) {
Ian Lynagh's avatar
Ian Lynagh committed
249
250
251
252
253
254
255
256
                if (-d $localpath) {
                    warning("$localpath already present; omitting");
                }
                else {
                    darcs (@$r_flags, $path, $localpath);
                }
            }
        }
Ian Lynagh's avatar
Ian Lynagh committed
257
        elsif (! /^(#.*)?$/) {
258
            die "Bad content on line $line of packages file: $_";
Ian Lynagh's avatar
Ian Lynagh committed
259
        }
Ian Lynagh's avatar
Ian Lynagh committed
260
261
262
263
    }
}

sub main {
264
    if (! -d "compiler") {
Ian Lynagh's avatar
Ian Lynagh committed
265
266
267
        die "error: darcs-all must be run from the top level of the ghc tree."
    }

268
269
    while ($#_ ne -1) {
        my $arg = shift;
270
271
        # We handle -q here as well as lower down as we need to skip over it
        # if it comes before the darcs command
272
        if ($arg eq "-q") {
Ian Lynagh's avatar
Ian Lynagh committed
273
274
275
            $verbose = 1;
        }
        elsif ($arg eq "-s") {
276
277
            $verbose = 0;
        }
278
279
280
281
282
283
        elsif ($arg eq "-r") {
            $defaultrepo = shift;
        }
        elsif ($arg eq "-i") {
            $ignore_failure = 1;
        }
Ian Lynagh's avatar
Ian Lynagh committed
284
285
        # --nofib tells get to also grab the nofib repo.
        # It has no effect on the other commands.
286
        elsif ($arg eq "--nofib") {
Ian Lynagh's avatar
Ian Lynagh committed
287
            $tags{"nofib"} = 1;
288
        }
Ian Lynagh's avatar
Ian Lynagh committed
289
290
        # --testsuite tells get to also grab the testsuite repo.
        # It has no effect on the other commands.
291
        elsif ($arg eq "--testsuite") {
Ian Lynagh's avatar
Ian Lynagh committed
292
            $tags{"testsuite"} = 1;
293
        }
294
295
296
297
298
        # --extralibs tells get to also grab the extra repos.
        # It has no effect on the other commands.
        elsif ($arg eq "--extra") {
            $tags{"extra"} = 1;
        }
299
300
301
        elsif ($arg eq "--checked-out") {
            $checked_out_flag = 1;
        }
302
303
        else {
            unshift @_, $arg;
304
            if (grep /^-q$/, @_) {
Ian Lynagh's avatar
Ian Lynagh committed
305
                $verbose = 1;
306
            }
307
308
309
310
            last;
        }
    }

Ian Lynagh's avatar
Ian Lynagh committed
311
312
313
314
315
316
317
318
319
320
321
322
    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;
        }
323
        if ($command =~ /^(pul|pus|sen|put|opt)/) {
324
325
            $want_remote_repo = 1;
        }
Ian Lynagh's avatar
Ian Lynagh committed
326
327
328
329
        darcsall @_;
    }
}

330
END {
331
332
    my $ec = $?;

333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
    message "== Checking for old bytestring repo";
    if (-d "libraries/bytestring/_darcs") {
        if ((system "darcs annotate --repodir libraries/bytestring --match 'hash 20080118173113-3fd76-d5b74c04372a297b585ebea4e16d524551ce5035' > /dev/null 2> /dev/null") == 0) {
            print <<EOF;
============================
ATTENTION!

You have an old bytestring repository in your GHC tree!

Please remove it (e.g. "rm -r libraries/bytestring"), and the new
version of bytestring will be used from a tarball instead.
============================
EOF
        }
    }
348

349
350
351
352
353
354
355
356
357
358
359
360
361
362
    message "== Checking for bytestring tarball";
    if (-d "libraries/bytestring" && not -d "libraries/bytestring/_darcs") {
        print <<EOF;
============================
ATTENTION!

You have an old bytestring in your GHC tree!

Please remove it (e.g. "rm -r libraries/bytestring"), and then run
"./darcs-all get" to get the darcs repository.
============================
EOF
    }

363
364
365
366
367
368
369
370
371
372
373
374
375
376
    message "== Checking for unpulled tarball patches";
    if ((system "darcs annotate --match 'hash 20090930200358-3fd76-cab3bf4a0a9e3902eb6dd41f71712ad3a6a9bcd1' > /dev/null 2> /dev/null") == 0) {
        print <<EOF;
============================
ATTENTION!

You have the unpulled tarball patches in your GHC tree!

Please remove them:
    darcs unpull -p "Use mingw tarballs to get mingw on Windows"
and say yes to each patch.
============================
EOF
    }
377
378

    $? = $ec;
379
380
}

Ian Lynagh's avatar
Ian Lynagh committed
381
382
main(@ARGV);