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

Replies