This repository has been archived by the owner on Jan 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdarcs-all
387 lines (322 loc) · 12.2 KB
/
darcs-all
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
#! /bin/sh
################################################################################
# Script for checking out and updating Haskell packages via darcs
################################################################################
set -e
scriptname=$0
package_list="package-list"
hackage_archive="http://hackage.haskell.org/packages/archive"
################################################################################
# Output an informative message if we are in verbose mode.
################################################################################
message ()
{
if test ${verbose} = "yes"; then
echo "== $*" >&2
fi
}
################################################################################
# Print an error message on stderr and terminate script with an error code.
################################################################################
die ()
{
echo "${scriptname}: $1" >&2
exit 1
}
################################################################################
# Run an external command if we are not in dry-run mode.
################################################################################
run_command()
{
message "Running \"$*\""
if test ${dry_run} = "no"; then
"$@"
fi
}
################################################################################
# Higher order shell programming: Map a function over all packages.
################################################################################
map_packages()
{
func="$*"
while read url kind version; do
# Ignore empty lines and comment lines.
if test -z "${url}"; then
continue
fi
case ${url} in
\#*)
continue ;;
*/*)
package_url_prefix=`echo ${url} | sed 's,/[^/]*$,,'`
package=`echo ${url} | sed 's,.*/,,'` ;;
*)
package_url_prefix=""
package=${url} ;;
esac
# Sanity check
if test -z "${kind}" -o -z "${version}"; then
die "Missing kind/version in package list."
fi
${func} "${package_url_prefix}" "${package}" "${kind}" "${version}"
done < "${package_list}"
}
################################################################################
# Handle command line arguments.
################################################################################
extra="no"
nofib="no"
testsuite="no"
release="no"
dry_run="no"
list_packages="no"
verbose="no"
while test $# -gt 0; do
case $1 in
-e | --extra) extra="yes" ;;
-n | --nofib) nofib="yes" ;;
-t | --testsuite) testsuite="yes" ;;
-r | --release) release="yes" ;;
-d | --dry-run) dry_run="yes" ;;
-l | --list-packages) list_packages="yes" ;;
-v | --verbose) verbose="yes" ;;
-*) die "unknown flag \"$1\"" ;;
*) break ;;
esac
shift
done
################################################################################
# Make sure we are called in the correct place, i.e. the top level.
################################################################################
if test ! -d "_darcs" -o ! -f ${package_list}; then
die "run \"$0\" in the top level directory of the project"
fi
message "We are at the top level of a darcs project."
################################################################################
# If requested, list package names and exit.
################################################################################
# I want anonymous shell functions! Join the petition!
echo_package()
{
package_url_prefix=$1; package=$2; kind=$3; version=$4
if test "${kind}" = "core" -o ${extra} = "yes"; then
echo "${package}"
fi
}
if test ${list_packages} = "yes"; then
map_packages echo_package
exit
fi
################################################################################
# Automagically determine our Haskell implementation via .spec files.
################################################################################
implementation="unknown"
for i in *.spec *.spec.in; do
if test -f ${i}; then
implementation=`echo ${i} | sed 's/\.spec$//' | sed 's/\.spec\.in$//'`
break
fi
done
if test ${implementation} = "unknown"; then
die "can't determine Haskell implementation"
fi
message "It looks like we are at the top level of the \"${implementation}\" project."
################################################################################
# Creativity is not *always* a good thing: Figure out where the individual tools
# and packages should live.
################################################################################
case ${implementation} in
ghc)
tools_dir="."
packages_dir="libraries" ;;
hugs98)
tools_dir="."
packages_dir="packages" ;;
nhc98)
tools_dir="src"
packages_dir="src/libraries" ;;
*)
die "unknon implementation \"${implementation}\"" ;;
esac
message "Tools will live in \"${tools_dir}\"."
if test -d ${packages_dir}; then
message "Packages will live in \"${packages_dir}\"."
else
run_command mkdir "${packages_dir}"
message "Packages will live in \"${packages_dir}\" (created)."
fi
################################################################################
# Figure out where to get the other repositories from, based on where this repo
# itself came from.
################################################################################
defaultrepo=`cat _darcs/prefs/defaultrepo`
case ${defaultrepo} in
http://* | *@*:*)
repository_base=`echo ${defaultrepo} | sed 's!/[^/]*$!!'`
lib_repository_base="${repository_base}/packages" ;;
/*)
repository_base=${defaultrepo}
lib_repository_base="${defaultrepo}/libraries" ;;
*)
die "malformed default repository \"${defaultrepo}\"" ;;
esac
message "Repository base is \"${repository_base}\"."
message "Libaries repository base is \"${lib_repository_base}\"."
################################################################################
# Normalize darcs command name.
################################################################################
if test $# -eq 0; then
die "missing darcs command"
fi
case $1 in
g | ge | get)
darcs_command="get" ;;
w | wh | wha | what | whats | whatsn | whatsne | whatsnew)
darcs_command="whatsnew" ;;
*)
darcs_command=$1 ;;
esac
shift
message "The darcs command is \"${darcs_command}\"."
################################################################################
# To avoid pulling in a decade of patches, we make partial repositories the
# default, but the user can override this, of course.
################################################################################
case $* in
*--complete* | *--partial*)
additional_get_option="" ;;
*)
message "Adding \"--partial\" to darcs commands."
additional_get_option="--partial" ;;
esac
################################################################################
# If we are going to retrieve a release version, we need either curl or wget.
# Try to figure out which one via some ugly autoconf-like shell horror.
################################################################################
if test "${darcs_command}" = "get" -a ${release} = "yes"; then
path_separator=":"
test_x_works="no"
# In a dry run, we simply make assumptions, avoiding the creation of a script.
if test ${dry_run} = "yes"; then
message "Note: In a dry run we assume that ':' is the path separator and 'test' does not support '-x'"
else
# For the tests below, we temporarily need an executable file in the current
# directory, which returns successfully.
test_script="darcs-all$$.sh"
cat > ${test_script} << EOF
#! /bin/sh
exit 0
EOF
chmod +x ${test_script}
# The *nix vs. Windows war continues...
( PATH="/nonexistentsillydir;."; ${test_script} ) > /dev/null 2>&1 && path_separator=';'
# The -x option of 'test' is not available everywhere, but it is not strictly
# needed later, anyway.
test -x ${test_script} > /dev/null 2>&1 && test_x_works="yes"
rm -f ${test_script}
fi
# Walk through the PATH to find either curl or wget.
downloader=""
for prog in curl wget; do
saved_IFS=$IFS
IFS=$path_separator
for dir in $PATH; do
IFS=$saved_IFS
test -z "${dir}" && dir="."
if test -f "${dir}/${prog}"; then
test ${test_x_works} = "yes" && test ! -x "${dir}/${prog}" && continue
downloader=${prog}
break
fi
done
IFS=$saved_IFS
test -n "${downloader}" && break
done
if test -z "${downloader}" -a ${dry_run} = "yes"; then
message "Neither \"curl\" nor \"wget\" could be found in the PATH, assuming \"curl\"."
downloader="curl"
fi
case "x${downloader}" in
x) die "Neither \"curl\" nor \"wget\" could be found in the PATH." ;;
xcurl) download_command="curl" ;;
xwget) download_command="wget --output-document=-" ;;
esac
message "We will use \"${download_command}\" to retrieve released packages."
fi
################################################################################
# Process ourselves and any tools.
################################################################################
tools=""
# We don't need to get ourselves again.
if test "${darcs_command}" != "get"; then
tools=". ${tools}"
fi
case ${implementation} in
ghc)
if test "${darcs_command}" = "get"; then
if test ${nofib} = "yes"; then tools="${tools} nofib"; fi
if test ${testsuite} = "yes"; then tools="${tools} testsuite"; fi
else
if test -d "${tools_dir}/nofib"; then tools="${tools} nofib"; fi
if test -d "${tools_dir}/testsuite"; then tools="${tools} testsuite"; fi
fi ;;
hugs98 | nhc98)
tools="${tools} cpphs hsc2hs" ;;
esac
for tool in ${tools}; do
if test "${darcs_command}" = "get"; then
if test -d "${tools_dir}/${tool}"; then
message "The tool \"${tool}\" already exists, skipping."
continue
fi
run_command darcs "${darcs_command}" ${additional_get_option} "$@" --repodir "${tools_dir}/${tool}" "${repository_base}/${tool}"
else
if test ! -d "${tools_dir}/${tool}/_darcs"; then
message "The directory \"${tools_dir}/${tool}\" is not present or not a repository, skipping."
continue
fi
run_command darcs "${darcs_command}" "$@" --repodir "${tools_dir}/${tool}"
fi
done
################################################################################
# Process packages using the package list.
################################################################################
user_darcs_options="$*"
retrieve_package()
{
package_url_prefix=$1; package=$2; kind=$3; version=$4
# We need to handle the "get" command differently, mostly due to the "release"
# mode, where we use curl/wget to retrieve a specific version.
if test "${darcs_command}" = "get"; then
if test "${kind}" = "extra" -a ${extra} = "no"; then
message "Package \"${package}\" is not a core package, skipping."
continue
fi
if test -d "${packages_dir}/${package}"; then
message "Package \"${package}\" already exists, skipping."
continue
fi
if test ${release} = "yes"; then
# Retrieve a numbered version from Hackage via curl/wget.
run_command ${download_command} "${hackage_archive}/${package}/${package}-${version}.tar.gz" | \
( if test ${dry_run} = "yes"; then cat; else gunzip -c | ( cd ${packages_dir}; tar xf - ); fi )
run_command mv "${packages_dir}/${package}-${version}" "${packages_dir}/${package}"
else
# Retrieve a bleeding edge version from the same repository as we came
# from or from a given URL.
if test -z "${package_url_prefix}"; then
package_url_prefix=${lib_repository_base}
fi
run_command darcs "${darcs_command}" ${additional_get_option} ${user_darcs_options} --repodir "${packages_dir}/${package}" "${package_url_prefix}/${package}"
fi
else
# This is not a "get" command, so proceed as usual.
if test ! -d "${packages_dir}/${package}/_darcs"; then
message "The directory \"${packages_dir}/${package}\" is not present or not a repository, skipping."
continue
fi
message "Processing \"${packages_dir}/${package}\""
run_command darcs "${darcs_command}" ${user_darcs_options} --repodir "${packages_dir}/${package}"
fi
}
map_packages retrieve_package