Gentoo Archives: gentoo-dev

From: Sergei Trofimovich <slyfox@g.o>
To: gentoo-dev@l.g.o
Cc: Sergei Trofimovich <slyfox@g.o>
Subject: [gentoo-dev] [PATCH 4/5] haskell-cabal.eclass: allow EAPI=8
Date: Mon, 05 Jul 2021 22:27:06
Message-Id: 20210705222555.3847172-5-slyfox@gentoo.org
In Reply to: [gentoo-dev] [PATCH 0/6] haskell eclass update to EAPI=8, old EAPI={0..5} removal by Sergei Trofimovich
1 Signed-off-by: Sergei Trofimovich <slyfox@g.o>
2 ---
3 eclass/haskell-cabal.eclass | 20 +++++++++++---------
4 1 file changed, 11 insertions(+), 9 deletions(-)
5
6 diff --git a/eclass/haskell-cabal.eclass b/eclass/haskell-cabal.eclass
7 index f7a6d35e610..a858ddea3ec 100644
8 --- a/eclass/haskell-cabal.eclass
9 +++ b/eclass/haskell-cabal.eclass
10 @@ -1,757 +1,759 @@
11 # Copyright 1999-2021 Gentoo Authors
12 # Distributed under the terms of the GNU General Public License v2
13
14 # @ECLASS: haskell-cabal.eclass
15 # @MAINTAINER:
16 # Haskell herd <haskell@g.o>
17 -# @SUPPORTED_EAPIS: 6 7
18 +# @SUPPORTED_EAPIS: 6 7 8
19 # @AUTHOR:
20 # Original author: Andres Loeh <kosmikus@g.o>
21 # Original author: Duncan Coutts <dcoutts@g.o>
22 # @BLURB: for packages that make use of the Haskell Common Architecture for Building Applications and Libraries (cabal)
23 # @DESCRIPTION:
24 # Basic instructions:
25 #
26 # Before inheriting the eclass, set CABAL_FEATURES to
27 # reflect the tools and features that the package makes
28 # use of.
29 #
30 # Currently supported features:
31 # haddock -- for documentation generation
32 # hscolour -- generation of colourised sources
33 # hoogle -- generation of documentation search index
34 # profile -- if package supports to build profiling-enabled libraries
35 # bootstrap -- only used for the cabal package itself
36 # lib -- the package installs libraries
37 # nocabaldep -- don't add dependency on cabal.
38 # only used for packages that _must_ not pull the dependency
39 # on cabal, but still use this eclass (e.g. haskell-updater).
40 # ghcdeps -- constraint dependency on package to ghc onces
41 # only used for packages that use libghc internally and _must_
42 # not pull upper versions
43 # test-suite -- add support for cabal test-suites (introduced in Cabal-1.8)
44 # rebuild-after-doc-workaround -- enable doctest test failue workaround.
45 # Symptom: when `./setup haddock` is run in a `build-type: Custom`
46 # package it might cause cause the test-suite to fail with
47 # errors like:
48 # > <command line>: cannot satisfy -package-id singletons-2.7-3Z7pnljD8tU1NrslJodXmr
49 # Workaround re-reginsters the package to avoid the failure
50 # (and rebuilds changes).
51 # FEATURE can be removed once https://github.com/haskell/cabal/issues/7213
52 # is fixed.
53
54 -inherit eutils ghc-package multilib toolchain-funcs
55 +case "${EAPI:-0}" in
56 + # eutils is for eqawarn
57 + 6|7) inherit eutils ;;
58 + 8) ;;
59 + *) die "EAPI ${EAPI} unsupported." ;;
60 +esac
61 +
62 +inherit ghc-package multilib toolchain-funcs
63 +
64 +EXPORT_FUNCTIONS pkg_setup src_configure src_compile src_test src_install pkg_postinst pkg_postrm
65
66 # @ECLASS-VARIABLE: CABAL_EXTRA_CONFIGURE_FLAGS
67 # @USER_VARIABLE
68 # @DESCRIPTION:
69 # User-specified additional parameters passed to 'setup configure'.
70 # example: /etc/portage/make.conf:
71 # CABAL_EXTRA_CONFIGURE_FLAGS="--enable-shared --enable-executable-dynamic"
72 : ${CABAL_EXTRA_CONFIGURE_FLAGS:=}
73
74 # @ECLASS-VARIABLE: CABAL_EXTRA_BUILD_FLAGS
75 # @USER_VARIABLE
76 # @DESCRIPTION:
77 # User-specified additional parameters passed to 'setup build'.
78 # example: /etc/portage/make.conf: CABAL_EXTRA_BUILD_FLAGS=-v
79 : ${CABAL_EXTRA_BUILD_FLAGS:=}
80
81 # @ECLASS-VARIABLE: GHC_BOOTSTRAP_FLAGS
82 # @USER_VARIABLE
83 # @DESCRIPTION:
84 # User-specified additional parameters for ghc when building
85 # _only_ 'setup' binary bootstrap.
86 # example: /etc/portage/make.conf: GHC_BOOTSTRAP_FLAGS=-dynamic to make
87 # linking 'setup' faster.
88 : ${GHC_BOOTSTRAP_FLAGS:=}
89
90 # @ECLASS-VARIABLE: CABAL_EXTRA_HADDOCK_FLAGS
91 # @USER_VARIABLE
92 # @DESCRIPTION:
93 # User-specified additional parameters passed to 'setup haddock'.
94 # example: /etc/portage/make.conf:
95 # CABAL_EXTRA_HADDOCK_FLAGS="--haddock-options=--latex --haddock-options=--pretty-html"
96 : ${CABAL_EXTRA_HADDOCK_FLAGS:=}
97
98 # @ECLASS-VARIABLE: CABAL_EXTRA_HOOGLE_FLAGS
99 # @USER_VARIABLE
100 # @DESCRIPTION:
101 # User-specified additional parameters passed to 'setup haddock --hoogle'.
102 # example: /etc/portage/make.conf:
103 # CABAL_EXTRA_HOOGLE_FLAGS="--haddock-options=--show-all"
104 : ${CABAL_EXTRA_HOOGLE_FLAGS:=}
105
106 # @ECLASS-VARIABLE: CABAL_EXTRA_HSCOLOUR_FLAGS
107 # @USER_VARIABLE
108 # @DESCRIPTION:
109 # User-specified additional parameters passed to 'setup hscolour'.
110 # example: /etc/portage/make.conf:
111 # CABAL_EXTRA_HSCOLOUR_FLAGS="--executables --tests"
112 : ${CABAL_EXTRA_HSCOLOUR_FLAGS:=}
113
114
115 # @ECLASS-VARIABLE: CABAL_EXTRA_TEST_FLAGS
116 # @USER_VARIABLE
117 # @DESCRIPTION:
118 # User-specified additional parameters passed to 'setup test'.
119 # example: /etc/portage/make.conf:
120 # CABAL_EXTRA_TEST_FLAGS="-v3 --show-details=streaming"
121 : ${CABAL_EXTRA_TEST_FLAGS:=}
122
123 # @ECLASS-VARIABLE: CABAL_DEBUG_LOOSENING
124 # @DESCRIPTION:
125 # Show debug output for 'cabal_chdeps' function if set.
126 # Needs working 'diff'.
127 : ${CABAL_DEBUG_LOOSENING:=}
128
129 # @ECLASS-VARIABLE: CABAL_REPORT_OTHER_BROKEN_PACKAGES
130 # @DESCRIPTION:
131 # Show other broken packages if 'cabal configure' fails.
132 # It should be normally enabled unless you know you are about
133 # to try to compile a lot of broken packages. Default value: 'yes'
134 # Set to anything else to disable.
135 : ${CABAL_REPORT_OTHER_BROKEN_PACKAGES:=yes}
136
137 # 'dev-haskell/cabal' passes those options with ./configure-based
138 # configuration, but most packages don't need/don't accept it:
139 # #515362, #515362
140 QA_CONFIGURE_OPTIONS+=" --with-compiler --with-hc --with-hc-pkg --with-gcc"
141
142 -case "${EAPI:-0}" in
143 - 6|7) ;;
144 - *) die "EAPI ${EAPI} unsupported." ;;
145 -esac
146 -
147 -EXPORT_FUNCTIONS pkg_setup src_configure src_compile src_test src_install pkg_postinst pkg_postrm
148 -
149 for feature in ${CABAL_FEATURES}; do
150 case ${feature} in
151 haddock) CABAL_USE_HADDOCK=yes;;
152 hscolour) CABAL_USE_HSCOLOUR=yes;;
153 hoogle) CABAL_USE_HOOGLE=yes;;
154 profile) CABAL_USE_PROFILE=yes;;
155 bootstrap) CABAL_BOOTSTRAP=yes;;
156 lib) CABAL_HAS_LIBRARIES=yes;;
157 nocabaldep) CABAL_FROM_GHC=yes;;
158 ghcdeps) CABAL_GHC_CONSTRAINT=yes;;
159 test-suite) CABAL_TEST_SUITE=yes;;
160 rebuild-after-doc-workaround) CABAL_REBUILD_AFTER_DOC_WORKAROUND=yes;;
161
162 *) CABAL_UNKNOWN="${CABAL_UNKNOWN} ${feature}";;
163 esac
164 done
165
166 if [[ -n "${CABAL_USE_HADDOCK}" ]]; then
167 IUSE="${IUSE} doc"
168 fi
169
170 if [[ -n "${CABAL_USE_HSCOLOUR}" ]]; then
171 IUSE="${IUSE} hscolour"
172 DEPEND="${DEPEND} hscolour? ( dev-haskell/hscolour )"
173 fi
174
175 if [[ -n "${CABAL_USE_HOOGLE}" ]]; then
176 # enabled only in ::haskell
177 #IUSE="${IUSE} hoogle"
178 CABAL_USE_HOOGLE=
179 fi
180
181 if [[ -n "${CABAL_USE_PROFILE}" ]]; then
182 IUSE="${IUSE} profile"
183 fi
184
185 if [[ -n "${CABAL_TEST_SUITE}" ]]; then
186 IUSE="${IUSE} test"
187 RESTRICT+=" !test? ( test )"
188 fi
189
190 # returns the version of cabal currently in use.
191 # Rarely it's handy to pin cabal version from outside.
192 : ${_CABAL_VERSION_CACHE:=""}
193 cabal-version() {
194 if [[ -z "${_CABAL_VERSION_CACHE}" ]]; then
195 if [[ "${CABAL_BOOTSTRAP}" ]]; then
196 # We're bootstrapping cabal, so the cabal version is the version
197 # of this package itself.
198 _CABAL_VERSION_CACHE="${PV}"
199 elif [[ "${CABAL_FROM_GHC}" ]]; then
200 _CABAL_VERSION_CACHE="$(ghc-cabal-version)"
201 else
202 # We ask portage, not ghc, so that we only pick up
203 # portage-installed cabal versions.
204 _CABAL_VERSION_CACHE="$(ghc-extractportageversion dev-haskell/cabal)"
205 fi
206 fi
207 echo "${_CABAL_VERSION_CACHE}"
208 }
209
210 cabal-bootstrap() {
211 local setupmodule
212 local cabalpackage
213 local setup_bootstrap_args=()
214
215 if [[ -f "${S}/Setup.lhs" ]]; then
216 setupmodule="${S}/Setup.lhs"
217 elif [[ -f "${S}/Setup.hs" ]]; then
218 setupmodule="${S}/Setup.hs"
219 else
220 eqawarn "No Setup.lhs or Setup.hs found. Either add Setup.hs to package or call cabal-mksetup from ebuild"
221 cabal-mksetup
222 setupmodule="${S}/Setup.hs"
223 fi
224
225 # We build the setup program using the latest version of
226 # cabal that we have installed
227 cabalpackage=Cabal-$(cabal-version)
228 einfo "Using cabal-$(cabal-version)."
229
230 if $(ghc-supports-threaded-runtime); then
231 # Cabal has a bug that deadlocks non-threaded RTS:
232 # https://bugs.gentoo.org/537500
233 # https://github.com/haskell/cabal/issues/2398
234 setup_bootstrap_args+=(-threaded)
235 fi
236
237 make_setup() {
238 set -- -package "${cabalpackage}" --make "${setupmodule}" \
239 $(ghc-make-args) \
240 "${setup_bootstrap_args[@]}" \
241 ${HCFLAGS} \
242 ${GHC_BOOTSTRAP_FLAGS} \
243 "$@" \
244 -o setup
245 echo $(ghc-getghc) "$@"
246 $(ghc-getghc) "$@"
247 }
248 if $(ghc-supports-shared-libraries); then
249 # # some custom build systems might use external libraries,
250 # # for which we don't have shared libs, so keep static fallback
251 # bug #411789, http://hackage.haskell.org/trac/ghc/ticket/5743#comment:3
252 # http://hackage.haskell.org/trac/ghc/ticket/7062
253 # http://hackage.haskell.org/trac/ghc/ticket/3072
254 # ghc does not set RPATH for extralibs, thus we do it ourselves by hands
255 einfo "Prepending $(ghc-libdir) to LD_LIBRARY_PATH"
256 if [[ ${CHOST} != *-darwin* ]]; then
257 LD_LIBRARY_PATH="$(ghc-libdir)${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH}"
258 export LD_LIBRARY_PATH
259 else
260 DYLD_LIBRARY_PATH="$(ghc-libdir)${DYLD_LIBRARY_PATH:+:}${DYLD_LIBRARY_PATH}"
261 export DYLD_LIBRARY_PATH
262 fi
263 { make_setup -dynamic "$@" && ./setup --help >/dev/null; } ||
264 make_setup "$@" || die "compiling ${setupmodule} failed"
265 else
266 make_setup "$@" || die "compiling ${setupmodule} failed"
267 fi
268 }
269
270 cabal-mksetup() {
271 local setupdir=${1:-${S}}
272 local setup_src=${setupdir}/Setup.hs
273
274 rm -vf "${setupdir}"/Setup.{lhs,hs}
275 elog "Creating 'Setup.hs' for 'Simple' build type."
276
277 echo 'import Distribution.Simple; main = defaultMain' \
278 > "${setup_src}" || die "failed to create default Setup.hs"
279 }
280
281 haskell-cabal-run_verbose() {
282 echo "$@"
283 "$@" || die "failed: $@"
284 }
285
286 cabal-hscolour() {
287 haskell-cabal-run_verbose ./setup hscolour "$@"
288 }
289
290 cabal-haddock() {
291 haskell-cabal-run_verbose ./setup haddock "$@"
292 }
293
294 cabal-die-if-nonempty() {
295 local breakage_type=$1
296 shift
297
298 [[ "${#@}" == 0 ]] && return 0
299 eerror "Detected ${breakage_type} packages: ${@}"
300 die "//==-- Please, run 'haskell-updater' to fix ${breakage_type} packages --==//"
301 }
302
303 cabal-show-brokens() {
304 [[ ${CABAL_REPORT_OTHER_BROKEN_PACKAGES} != yes ]] && return 0
305
306 elog "ghc-pkg check: 'checking for other broken packages:'"
307 # pretty-printer
308 $(ghc-getghcpkg) check 2>&1 \
309 | egrep -v '^Warning: haddock-(html|interfaces): ' \
310 | egrep -v '^Warning: include-dirs: ' \
311 | head -n 20
312
313 cabal-die-if-nonempty 'broken' \
314 $($(ghc-getghcpkg) check --simple-output)
315 }
316
317 cabal-show-old() {
318 [[ ${CABAL_REPORT_OTHER_BROKEN_PACKAGES} != yes ]] && return 0
319
320 cabal-die-if-nonempty 'outdated' \
321 $("${EPREFIX}"/usr/sbin/haskell-updater --quiet --upgrade --list-only)
322 }
323
324 cabal-show-brokens-and-die() {
325 cabal-show-brokens
326 cabal-show-old
327
328 die "$@"
329 }
330
331 cabal-configure() {
332 local cabalconf=()
333
334 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
335 # We use the bundled with GHC version if exists
336 # Haddock is very picky about index files
337 # it generates for ghc's base and other packages.
338 local p=${EPREFIX}/usr/bin/haddock-ghc-$(ghc-version)
339 if [[ -f $p ]]; then
340 cabalconf+=(--with-haddock="${p}")
341 else
342 cabalconf+=(--with-haddock=${EPREFIX}/usr/bin/haddock)
343 fi
344 fi
345 if [[ -n "${CABAL_USE_PROFILE}" ]] && use profile; then
346 cabalconf+=(--enable-library-profiling)
347 fi
348
349 if [[ -n "${CABAL_TEST_SUITE}" ]]; then
350 cabalconf+=($(use_enable test tests))
351 fi
352
353 if [[ -n "${CABAL_GHC_CONSTRAINT}" ]]; then
354 cabalconf+=($(cabal-constraint "ghc"))
355 fi
356
357 cabalconf+=(--ghc-options="$(ghc-make-args)")
358
359 local option
360 for option in ${HCFLAGS}
361 do
362 cabalconf+=(--ghc-option="$option")
363 done
364
365 # toolchain
366 cabalconf+=(--with-ar="$(tc-getAR)")
367
368 # Building GHCi libs on ppc64 causes "TOC overflow".
369 if use ppc64; then
370 cabalconf+=(--disable-library-for-ghci)
371 fi
372
373 # currently cabal does not respect CFLAGS and LDFLAGS on it's own (bug #333217)
374 # so translate LDFLAGS to ghc parameters (with mild filtering).
375 local flag
376 for flag in $CFLAGS; do
377 case "${flag}" in
378 -flto|-flto=*)
379 # binutils does not support partial linking yet:
380 # https://github.com/gentoo-haskell/gentoo-haskell/issues/1110
381 # https://sourceware.org/PR12291
382 einfo "Filter '${flag}' out of CFLAGS (avoid lto partial linking)"
383 continue
384 ;;
385 esac
386
387 cabalconf+=(--ghc-option="-optc$flag")
388 done
389 for flag in $LDFLAGS; do
390 case "${flag}" in
391 -flto|-flto=*)
392 # binutils does not support partial linking yet:
393 # https://github.com/gentoo-haskell/gentoo-haskell/issues/1110
394 # https://sourceware.org/PR12291
395 einfo "Filter '${flag}' out of LDFLAGS (avoid lto partial linking)"
396 continue
397 ;;
398 esac
399
400 cabalconf+=(--ghc-option="-optl$flag")
401 done
402
403 # disable executable stripping for the executables, as portage will
404 # strip by itself, and pre-stripping gives a QA warning.
405 # cabal versions previous to 1.4 does not strip executables, and does
406 # not accept the flag.
407 # this fixes numerous bugs, amongst them;
408 # bug #251881, bug #251882, bug #251884, bug #251886, bug #299494
409 cabalconf+=(--disable-executable-stripping)
410
411 cabalconf+=(--docdir="${EPREFIX}"/usr/share/doc/${PF})
412 # As of Cabal 1.2, configure is quite quiet. For diagnostic purposes
413 # it's better if the configure chatter is in the build logs:
414 cabalconf+=(--verbose)
415
416 # We build shared version of our Cabal where ghc ships it's shared
417 # version of it. We will link ./setup as dynamic binary againt Cabal later.
418 [[ ${CATEGORY}/${PN} == "dev-haskell/cabal" ]] && \
419 $(ghc-supports-shared-libraries) && \
420 cabalconf+=(--enable-shared)
421
422 if $(ghc-supports-shared-libraries); then
423 # Experimental support for dynamically linked binaries.
424 # We are enabling it since 7.10.1_rc3
425 if ver_test "$(ghc-version)" -ge "7.10.0.20150316"; then
426 # we didn't enable it before as it was not stable on all arches
427 cabalconf+=(--enable-shared)
428 # Known to break on ghc-7.8/Cabal-1.18
429 # https://ghc.haskell.org/trac/ghc/ticket/9625
430 cabalconf+=(--enable-executable-dynamic)
431 fi
432 fi
433
434 # --sysconfdir appeared in Cabal-1.18+
435 if ./setup configure --help | grep -q -- --sysconfdir; then
436 cabalconf+=(--sysconfdir="${EPREFIX}"/etc)
437 fi
438
439 # appeared in Cabal-1.18+ (see '--disable-executable-stripping')
440 if ./setup configure --help | grep -q -- --disable-library-stripping; then
441 cabalconf+=(--disable-library-stripping)
442 fi
443
444 set -- configure \
445 --ghc --prefix="${EPREFIX}"/usr \
446 --with-compiler="$(ghc-getghc)" \
447 --with-hc-pkg="$(ghc-getghcpkg)" \
448 --prefix="${EPREFIX}"/usr \
449 --libdir="${EPREFIX}"/usr/$(get_libdir) \
450 --libsubdir=${P}/ghc-$(ghc-version) \
451 --datadir="${EPREFIX}"/usr/share/ \
452 --datasubdir=${P}/ghc-$(ghc-version) \
453 "${cabalconf[@]}" \
454 ${CABAL_CONFIGURE_FLAGS} \
455 "$@" \
456 ${CABAL_EXTRA_CONFIGURE_FLAGS}
457 echo ./setup "$@"
458 ./setup "$@" || cabal-show-brokens-and-die "setup configure failed"
459 }
460
461 cabal-build() {
462 set -- build "$@" ${CABAL_EXTRA_BUILD_FLAGS}
463 echo ./setup "$@"
464 ./setup "$@" \
465 || die "setup build failed"
466 }
467
468 cabal-copy() {
469 set -- copy --destdir="${D}" "$@"
470 echo ./setup "$@"
471 ./setup "$@" || die "setup copy failed"
472
473 # cabal is a bit eager about creating dirs,
474 # so remove them if they are empty
475 rmdir "${ED}/usr/bin" 2> /dev/null
476 }
477
478 cabal-pkg() {
479 # This does not actually register since we're using true instead
480 # of ghc-pkg. So it just leaves the .conf file and we can
481 # register that ourselves (if it exists).
482
483 if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then
484 # Newer cabal can generate a package conf for us:
485 ./setup register --gen-pkg-config="${T}/${P}.conf"
486 if [[ -d "${T}/${P}.conf" ]]; then
487 ghc-install-pkg "${T}/${P}.conf"/*
488 else
489 ghc-install-pkg "${T}/${P}.conf"
490 fi
491 fi
492 }
493
494 # Some cabal libs are bundled along with some versions of ghc
495 # eg filepath-1.0 comes with ghc-6.6.1
496 # by putting CABAL_CORE_LIB_GHC_PV="6.6.1" in an ebuild we are declaring that
497 # when building with this version of ghc, the ebuild is a dummy that is it will
498 # install no files since the package is already included with ghc.
499 # However portage still records the dependency and we can upgrade the package
500 # to a later one that's not included with ghc.
501 # You can also put a space separated list, eg CABAL_CORE_LIB_GHC_PV="6.6 6.6.1".
502 # Those versions are taken as-is from ghc `--numeric-version`.
503 # Package manager versions are also supported:
504 # CABAL_CORE_LIB_GHC_PV="7.10.* PM:7.8.4-r1".
505 cabal-is-dummy-lib() {
506 local bin_ghc_version=$(ghc-version)
507 local pm_ghc_version=$(ghc-pm-version)
508
509 for version in ${CABAL_CORE_LIB_GHC_PV}; do
510 [[ "${bin_ghc_version}" == ${version} ]] && return 0
511 [[ "${pm_ghc_version}" == ${version} ]] && return 0
512 done
513
514 return 1
515 }
516
517 # exported function: check if cabal is correctly installed for
518 # the currently active ghc (we cannot guarantee this with portage)
519 haskell-cabal_pkg_setup() {
520 if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then
521 [[ ${RDEPEND} == *dev-lang/ghc* ]] || eqawarn "QA Notice: A library does not have runtime dependency on dev-lang/ghc."
522 fi
523 if [[ -n "${CABAL_UNKNOWN}" ]]; then
524 eqawarn "QA Notice: Unknown entry in CABAL_FEATURES: ${CABAL_UNKNOWN}"
525 fi
526 if cabal-is-dummy-lib; then
527 einfo "${P} is included in ghc-${CABAL_CORE_LIB_GHC_PV}, nothing to install."
528 fi
529 }
530
531 haskell-cabal_src_configure() {
532 cabal-is-dummy-lib && return
533
534 pushd "${S}" > /dev/null || die
535
536 cabal-bootstrap
537
538 cabal-configure "$@"
539
540 popd > /dev/null || die
541 }
542
543 # exported function: nice alias
544 cabal_src_configure() {
545 haskell-cabal_src_configure "$@"
546 }
547
548 # exported function: cabal-style bootstrap configure and compile
549 cabal_src_compile() {
550 cabal-is-dummy-lib && return
551
552 cabal-build
553
554 if [[ -n "$CABAL_USE_HADDOCK" ]] && use doc; then
555 if [[ -n "$CABAL_USE_HSCOLOUR" ]] && use hscolour; then
556 # --hyperlink-source implies calling 'setup hscolour'
557 haddock_args+=(--hyperlink-source)
558 fi
559
560 cabal-haddock "${haddock_args[@]}" $CABAL_EXTRA_HADDOCK_FLAGS
561
562 if [[ -n "$CABAL_USE_HOOGLE" ]] && use hoogle; then
563 cabal-haddock --hoogle $CABAL_EXTRA_HOOGLE_FLAGS
564 fi
565 if [[ -n "${CABAL_REBUILD_AFTER_DOC_WORKAROUND}" ]]; then
566 ewarn "rebuild-after-doc-workaround is enabled. This is a"
567 ewarn "temporary worakround to deal with https://github.com/haskell/cabal/issues/7213"
568 ewarn "until the upstream issue can be resolved."
569 cabal-build
570 fi
571 else
572 if [[ -n "$CABAL_USE_HSCOLOUR" ]] && use hscolour; then
573 cabal-hscolour $CABAL_EXTRA_HSCOLOUR_FLAGS
574 fi
575
576 if [[ -n "$CABAL_USE_HOOGLE" ]] && use hoogle; then
577 ewarn "hoogle USE flag requires doc USE flag, building without hoogle"
578 fi
579 fi
580 }
581
582 haskell-cabal_src_compile() {
583 pushd "${S}" > /dev/null || die
584
585 cabal_src_compile "$@"
586
587 popd > /dev/null || die
588 }
589
590 haskell-cabal_src_test() {
591 local cabaltest=()
592
593 pushd "${S}" > /dev/null || die
594
595 if cabal-is-dummy-lib; then
596 einfo ">>> No tests for dummy library: ${CATEGORY}/${PF}"
597 else
598 einfo ">>> Test phase [cabal test]: ${CATEGORY}/${PF}"
599
600 # '--show-details=streaming' appeared in Cabal-1.20
601 if ./setup test --help | grep -q -- "'streaming'"; then
602 cabaltest+=(--show-details=streaming)
603 fi
604
605 set -- test \
606 "${cabaltest[@]}" \
607 ${CABAL_TEST_FLAGS} \
608 "$@" \
609 ${CABAL_EXTRA_TEST_FLAGS}
610 echo ./setup "$@"
611 ./setup "$@" || die "cabal test failed"
612 fi
613
614 popd > /dev/null || die
615 }
616
617 # exported function: cabal-style copy and register
618 cabal_src_install() {
619 if ! cabal-is-dummy-lib; then
620 cabal-copy
621 cabal-pkg
622 fi
623
624 # create a dummy local package conf file for haskell-updater
625 # if it does not exist (dummy libraries and binaries w/o libraries)
626 local ghc_confdir_with_prefix="$(ghc-confdir)"
627 # remove EPREFIX
628 dodir ${ghc_confdir_with_prefix#${EPREFIX}}
629 local hint_db="${D}/$(ghc-confdir)"
630 local hint_file="${hint_db}/gentoo-empty-${CATEGORY}-${PF}.conf"
631 mkdir -p "${hint_db}" || die
632 touch "${hint_file}" || die
633 }
634
635 haskell-cabal_src_install() {
636 pushd "${S}" > /dev/null || die
637
638 cabal_src_install
639
640 popd > /dev/null || die
641 }
642
643 haskell-cabal_pkg_postinst() {
644 ghc-package_pkg_postinst
645 }
646
647 haskell-cabal_pkg_postrm() {
648 ghc-package_pkg_postrm
649 }
650
651 # @FUNCTION: cabal_flag
652 # @DESCRIPTION:
653 # ebuild.sh:use_enable() taken as base
654 #
655 # Usage examples:
656 #
657 # CABAL_CONFIGURE_FLAGS=$(cabal_flag gui)
658 # leads to "--flags=gui" or "--flags=-gui" (useflag 'gui')
659 #
660 # CABAL_CONFIGURE_FLAGS=$(cabal_flag gtk gui)
661 # also leads to "--flags=gui" or " --flags=-gui" (useflag 'gtk')
662 #
663 cabal_flag() {
664 if [[ -z "$1" ]]; then
665 echo "!!! cabal_flag() called without a parameter." >&2
666 echo "!!! cabal_flag() <USEFLAG> [<cabal_flagname>]" >&2
667 return 1
668 fi
669
670 local UWORD=${2:-$1}
671
672 if use "$1"; then
673 echo "--flags=${UWORD}"
674 else
675 echo "--flags=-${UWORD}"
676 fi
677
678 return 0
679 }
680
681 # @FUNCTION: cabal_chdeps
682 # @DESCRIPTION:
683 # Allows easier patching of $CABAL_FILE (${S}/${PN}.cabal by default)
684 # depends
685 #
686 # Accepts argument list as pairs of substitutions: <from-string> <to-string>...
687 #
688 # Dies on error.
689 #
690 # Usage examples:
691 #
692 # src_prepare() {
693 # cabal_chdeps \
694 # 'base >= 4.2 && < 4.6' 'base >= 4.2 && < 4.7' \
695 # 'containers ==0.4.*' 'containers >= 0.4 && < 0.6'
696 #}
697 # or
698 # src_prepare() {
699 # CABAL_FILE=${S}/${MY_PN}.cabal cabal_chdeps \
700 # 'base >= 4.2 && < 4.6' 'base >= 4.2 && < 4.7'
701 # CABAL_FILE=${S}/${MY_PN}-tools.cabal cabal_chdeps \
702 # 'base == 3.*' 'base >= 4.2 && < 4.7'
703 #}
704 #
705 cabal_chdeps() {
706 local cabal_fn=${MY_PN:-${PN}}.cabal
707 local cf=${CABAL_FILE:-${S}/${cabal_fn}}
708 local from_ss # ss - substring
709 local to_ss
710 local orig_c # c - contents
711 local new_c
712
713 [[ -f $cf ]] || die "cabal file '$cf' does not exist"
714
715 orig_c=$(< "$cf")
716
717 while :; do
718 from_pat=$1
719 to_str=$2
720
721 [[ -n ${from_pat} ]] || break
722 [[ -n ${to_str} ]] || die "'${from_str}' does not have 'to' part"
723
724 einfo "CHDEP: '${from_pat}' -> '${to_str}'"
725
726 # escape pattern-like symbols
727 from_pat=${from_pat//\*/\\*}
728 from_pat=${from_pat//\[/\\[}
729
730 new_c=${orig_c//${from_pat}/${to_str}}
731
732 if [[ -n $CABAL_DEBUG_LOOSENING ]]; then
733 echo "${orig_c}" >"${T}/${cf}".pre
734 echo "${new_c}" >"${T}/${cf}".post
735 diff -u "${T}/${cf}".{pre,post}
736 fi
737
738 [[ "${orig_c}" == "${new_c}" ]] && die "no trigger for '${from_pat}'"
739 orig_c=${new_c}
740 shift
741 shift
742 done
743
744 echo "${new_c}" > "$cf" ||
745 die "failed to update"
746 }
747
748 # @FUNCTION: cabal-constraint
749 # @DESCRIPTION:
750 # Allowes to set contraint to the libraries that are
751 # used by specified package
752 cabal-constraint() {
753 while read p v ; do
754 echo "--constraint \"$p == $v\""
755 done < $(ghc-pkgdeps ${1})
756 }
757
758 # @FUNCTION: replace-hcflags
759 # @USAGE: <old> <new>
760 # @DESCRIPTION:
761 # Replace the <old> flag with <new> in HCFLAGS. Accepts shell globs for <old>.
762 # The implementation is picked from flag-o-matic.eclass:replace-flags()
763 replace-hcflags() {
764 [[ $# != 2 ]] && die "Usage: replace-hcflags <old flag> <new flag>"
765
766 local f new=()
767 for f in ${HCFLAGS} ; do
768 # Note this should work with globs like -O*
769 if [[ ${f} == ${1} ]]; then
770 einfo "HCFLAGS: replacing '${f}' to '${2}'"
771 f=${2}
772 fi
773 new+=( "${f}" )
774 done
775 export HCFLAGS="${new[*]}"
776
777 return 0
778 }
779 --
780 2.32.0