/[gentoo-x86]/eclass/haskell-cabal.eclass
Gentoo

Contents of /eclass/haskell-cabal.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.52 - (hide annotations) (download)
Mon Jul 20 15:05:49 2015 UTC (2 years, 4 months ago) by slyfox
Branch: MAIN
Changes since 1.51: +20 -2 lines
Workaround upstream cabal tests hangup bug #537500 by Michael Orlitzky; use ghc's haddock for doc generation.

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

  ViewVC Help
Powered by ViewVC 1.1.20