-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmakedeps.sh
executable file
·323 lines (269 loc) · 10.4 KB
/
makedeps.sh
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
#!/bin/bash
# REQUIRES:
# cabal-rpm
# mock
# yum (https://bugzilla.redhat.com/show_bug.cgi?id=1474513)
# This script will, hopefully, build a repository containing all the dependencies
# needed for bdcs.
BASEDIR="${PWD}"
# directory for intermediate files
WORKDIR="${PWD}/build"
# directory for the finished repo
REPODIR="${PWD}/repo"
# SRPMs
SRPMDIR="${PWD}/srpms"
# debuginfo
DEBUGDIR="${PWD}/debuginfo"
### FUNCTIONS
runmock() {
# We need to use --old-chroot because of https://bugzilla.redhat.com/show_bug.cgi?id=1467299
mock --configdir "${WORKDIR}/config" -r weldr --old-chroot --resultdir "${WORKDIR}/results" "$@" || exit 1
}
# Convert a hackage package name to a rpm package name
# *usually* this is just "whatever" -> "ghc-whatever", but packages that provide
# executables don't get the ghc prefix, and the tests and rules are hard to reproduce
# here, and the function that does this is only exposed in cabal-rpm via
# writing out a spec file. So just hard code some known exec packages here and
# maybe file a request against cabal-rpm later.
rpmname() {
local cabalname="$1"
if [ "$cabalname" = "hsc2hs" -o \
"$cabalname" = "hoogle" ]; then
echo "$1"
else
echo "ghc-$1"
fi
}
# Build a package in mock
buildpkg() {
local pkgname="$1"
local specfile="${pkgname}.spec"
# Download the sources
spectool --gf "$specfile" -C "${WORKDIR}/sources" || exit 1
# Start with a fresh results directory
rm -rf "${WORKDIR}/results"/*
# Run mock
runmock --buildsrpm --spec "$specfile" --sources "${WORKDIR}/sources"
runmock --rebuild "${WORKDIR}/results/${pkgname}-"*.src.rpm
# Save the results
mv "${WORKDIR}/results/"*.src.rpm "${SRPMDIR}" || exit 1
mv "${WORKDIR}/results/"*-debuginfo-*.rpm "${DEBUGDIR}" 2>/dev/null || :
mv "${WORKDIR}/results/"*.rpm "${REPODIR}" || exit 1
createrepo_c "${REPODIR}" || exit 1
# dnf unhelpfully caches the metadata from the local repo, so expire the cache
# each time the local repo is updated
dnf clean expire-cache
}
# Test whether a package is already available or not
available() {
# Stupid special case: haskell-gi-overloading is a feature marker. It doesn't compile
# any object files or expose any modules, so the way cabal-rpm handles this is to
# generate a -devel package and no main package. Any package with haskell-gi-overloading
# in the cabal dependencies will end up with a RPM dependency on ghc-haskell-gi-overloading-devel,
# so we just leave it like that instead of editing all the other spec files.
# What all that means right here is that we have to check for the -devel package to say whether
# it's available or not, because the main package does not exist.
local pkgname="$1"
if [ "$pkgname" = "ghc-haskell-gi-overloading" ]; then
pkgname="ghc-haskell-gi-overloading-devel"
fi
local result_count="$(dnf repoquery -q --whatprovides "$pkgname" --repofrompath weldr,"$REPODIR" | wc -l)"
if [ "$result_count" -eq 0 ]; then
return 1
else
return 0
fi
}
# Find and build the unavailable dependencies for a package
builddeps() {
local cabalname="$1"
local pkgname="$(rpmname "${cabalname}")"
# Loop through the dependencies
# cabal-rpm fails with weird messages sometimes so try to catch that
local deplist
deplist="$(cabal-rpm depends "${cabalname}")"
if [[ "$?" -ne 0 ]]; then
exit 1
fi
# two exits so that a failure from the while loop subshell actually gets caught
echo "${deplist}" | grep -v 'in Hackage$' | grep -v '\.pc$' | grep -Fv 'libpthread.so' | while read -r dep ; do
if [ -z "$dep" ]; then
continue
fi
available "$(rpmname "${dep}")" || rebuild "${dep}" || exit 1
done || exit 1
}
makespec() {
local cabalname="$1"
# cabal-rpm doesn't treat hoogle as a package with executables for some reason,
# so just force it.
if [ "$cabalname" = "hoogle" ]; then
cabal-rpm spec -b "${cabalname}"
else
cabal-rpm spec "${cabalname}"
fi
}
# Build a package and its dependencies
rebuild() {
local cabalname="$1"
local suffix="$2"
local pkgname="$(rpmname "${cabalname}")"
# ghc-authenticate-oauth has a requirement on RSA < 2.3, so make
# sure we don't build too new of a version
if [ "$cabalname" = "RSA" ]; then
cabalname="RSA-2.2.0"
fi
builddeps "$cabalname"
# Spit out a spec file and build it
( cd "$BASEDIR" &&
makespec "${cabalname}" &&
fixspec "${pkgname}" &&
addsuffix "${pkgname}" "${suffix}" &&
buildpkg "${pkgname}${suffix}" ) || exit 1
}
# Fix problems in the generated spec files
fixspec() {
local pkgname="$1"
# Whether cabal-rpm specifies that tests should be run or not
# depends on whether it can find the dependencies installed on the
# host system. Instead of having this dependent behavior (and sometimes
# having to fix someone else's tests) just always disable tests.
sed -i 's/%bcond_without tests/%bcond_with tests/' "${pkgname}.spec"
if [[ "$pkgname" = "ghc-haskell-gi" ]]; then
# I'm not real clear on what this line intends to do, but it's wrong
sed -i '/mv %{buildroot}%{_ghcdocdir}\/{,ghc-}%{name}/d' "${pkgname}.spec"
# Change the source of haskell-gi to an upstream commit from github
sed -i -e '1i\
%global commit0 dcf5c7837927632dd5aedb52ad4d70ac84f0c08a\
%global shortcommit0 %(c=%{commit0}; echo ${c:0:7})' "${pkgname}.spec"
sed -i 's/^Source0.*/Source0: https:\/\/github.com\/haskell-gi\/haskell-gi\/archive\/%{commit0}.tar.gz#\/%{name}-%{shortcommit0}.tar.gz/' "${pkgname}.spec"
sed -i 's/^%setup.*/%autosetup -n haskell-gi-%{commit0}/' "${pkgname}.spec"
sed -i 's/Release:.*/&.weldr.1/' ghc-haskell-gi.spec
elif [[ "$pkgname" = "ghc-hspec-discover" ]]; then
# I'm not real clear on what this line intends to do, but it's wrong
sed -i '/mv %{buildroot}%{_ghcdocdir}\/{,ghc-}%{name}/d' "${pkgname}.spec"
elif [[ "$pkgname" =~ ^ghc-gi- ]]; then
# cabal-rpm doesn't think there's a base package, since there's no exposed-modules,
# so we need to add the %files section and a Requires from -devel
# This kind of makes the spec file look weird but who cares
sed -i -e '/^%package devel/a\
Requires: %{name}%{?_isa} = %{version}-%{release}' -e '$a\
\
%files -f %{name}.files\
%license LICENSE' "${pkgname}.spec"
elif [[ "$pkgname" = "ghc-persistent-sqlite" ]]; then
# Build persistent-sqlite against the system sqlite library instead of the one it ships with
sed -i -e '1i\
%global cabal_configure_options -fsystemlib\
BuildRequires: sqlite-devel' "${pkgname}.spec"
elif [[ "$pkgname" = "hoogle" ]]; then
# similar mystery line
sed -i '/mv %{buildroot}%{_ghclicensedir}\/{,ghc-}%{name}/d' "${pkgname}.spec"
else
return 0
fi
}
# If a suffix is requested, append it to the package name
addsuffix() {
local pkgname="$1"
local suffix="$2"
if [ -z "$suffix" ]; then
return 0
fi
mv "${pkgname}.spec" "${pkgname}${suffix}.spec"
# Add the suffix to the name, and fix the .files names
# We need to care about the position of the new Provides lines in that
# you can't use %{version} and %{release} before they are defined.
# Assume that Source0 is late enough
sed -i -e 's/^Name:.*/&'"${suffix}/" \
-e 's/^%files \(.*\)-f %{name}\(.*\)\.files/%files \1-f '"${pkgname}"'\2.files/' \
-e '/^Source0:/a\
Provides: '"${pkgname}"' = %{version}-%{release}\
Provides: '"${pkgname}"'%{_isa} = %{version}-%{release}' \
-e '/^%package devel/a\
Provides: '"${pkgname}"'-devel = %{version}-%{release}\
Provides: '"${pkgname}"'-devel%{_isa} = %{version}-%{release}' \
"${pkgname}${suffix}.spec"
}
# Setup the directories
mkdir -p "${WORKDIR}/config"
mkdir -p "${WORKDIR}/sources"
mkdir -p "${WORKDIR}/results"
mkdir -p "${REPODIR}"
mkdir -p "${SRPMDIR}"
mkdir -p "${DEBUGDIR}"
createrepo_c "${REPODIR}"
dnf clean expire-cache
# Create the config file
cp "${PWD}/mock.cfg" "${WORKDIR}/config/weldr.cfg"
echo "
[weldr]
name=weldr
baseurl=file://$REPODIR/
enabled=1
gpgcheck=0
\"\"\"
config_opts['plugin_conf']['bind_mount_opts']['dirs'].append(('$REPODIR', '$REPODIR'))" >> "${WORKDIR}/config/weldr.cfg"
# Before anything, need an up-to-date package list
cabal update
# If a list of packages was specified, rebuild that
if [ "$#" -gt 0 ]; then
for pkg in "$@"; do
buildpkg "$pkg"
done
else
# Otherwise, try to create and rebuild everything
# Build some newer versions of dependencies
# Append -weldr to the package name so they don't conflict with the Fedora versions
if ! available "ghc-memory >= 0.14.7" ; then
rebuild memory -weldr
fi
if ! available "ghc-gitrev >= 1.3.1" ; then
rebuild gitrev -weldr
fi
if ! available "ghc-cryptonite >= 0.24" ; then
rebuild cryptonite -weldr
fi
# The version of distributive in Fedora has not been rebuilt against its
# dependencies (in particular base-orphans) now in F26 updates. Update to
# the latest version to work around this mess.
if ! available "ghc-distributive >= 0.5.3" ; then
rebuild distributive -weldr
fi
# Built from a local copy of the .spec
if ! available "libgit2 >= 0.26"; then
( cd "$BASEDIR" && buildpkg "libgit2" ) || exit 1
fi
if ! available "libgit2-glib >= 0.26.0"; then
( cd "$BASEDIR" && buildpkg "libgit2-glib" ) || exit 1
fi
# Download bdcs and build its deps
( cd build &&
rm -rf bdcs &&
git clone https://www.github.com/weldr/bdcs &&
cd bdcs/importer &&
builddeps bdcs
) || exit 1
# Same for bdcs-cli
( cd build &&
rm -rf bdcs-cli &&
git clone https://www.github.com/weldr/bdcs-cli &&
cd bdcs-cli &&
builddeps BDCSCli
) || exit 1
# Don't know how to tell cabal-rpm to include test dependencies, so just
# add one more by hand
if ! available "ghc-hspec"; then
rebuild hspec
fi
# BONUS ROUND
# build hoogle against all the stuff we built
# tls-session-manager (needed for warp-tls, needed for hoogle) requires a
# newer version of psqueues
if ! available "ghc-psqueues >= 0.2.3"; then
rebuild psqueues -weldr
fi
if ! available "hoogle"; then
rebuild hoogle
fi
fi