Cabal hooks

Krasimir Angelov kr.angelov at
Tue Jan 11 17:06:11 EST 2005

On Tue, 11 Jan 2005 12:49:11 +0000, Ross Paterson <ross at> wrote:

> I think these checks are off at the moment.  But you can get the
> effect you're after by using

I still get "*** Exception: Line 1: Parse of field 'name' failed"
error if name field from Setup.buildinfo is empty.

>        main = defaultMainWithHooks defaultUserHooks
> can't you?  (cf fptools/libraries/X11)  There's a need to do
> something different under Windows, though.

My Setup.lhs is something like:

#! runghc

import Distribution.Simple
import Distribution.Setup
import Distribution.PackageDescription

main = defaultMainWithHooks hooks

hooks = defaultUserHooks
  { preConf = hsql_configure

hsql_configure :: [String] -> ConfigFlags -> IO (Maybe PackageDescription)
hsql_configure args flags = do
  let pkg_descr = emptyPackageDescription
        { ccOptions = ...
  writePackageDescription hookedPackageDesc pkg_descr
  return (Just pkg_descr)

It fails because name and version fields of the returned package
description are empty. To work arround I need to use:

hsql_configure :: [String] -> ConfigFlags -> IO (Maybe PackageDescription)
hsql_configure args flags = do
  pkg_descr <- readPackageDescription "Setup.description"
  let pkg_descr' = pkg_descr
        { ccOptions = ...
  writePackageDescription hookedPackageDesc pkg_descr'
  return (Just pkg_descr')

> > Isn't it simpler to change the hooks type to something like:
> >
> > PackageDescription -> IO PackageDescription
> >
> > where the argument is the original description and the result is the
> > possible updated one? This avoids the need of merging and simplifies
> > the library code.
> This relates to the discussion on package description structure.
> With this interface, it would be possible for the preConf hook to
> alter fields that are supposed to be fixed.

The library can check whether some fields are equal in the original
description and in the updated description.


More information about the Libraries mailing list