cabal hooks interface

Isaac Jones ijones at
Thu Dec 23 01:56:35 EST 2004

ross at writes:

> As an experiment to see what would be useful, I've switched Hugs's
> handling of the more peripheral fptools/libraries packages (QuickCheck,
> mtl, fgl, HaXml, parsec, HUnit, X11, HGL, OpenGL, GLUT and OpenAL) over
> to a variant of Cabal's simple build infrastructure.  The result is in the
> CVS repository as hugs98/libraries/tools/HugsSetup.hs.  It's a Cabal setup
> script that does configure, build and install, but doesn't yet handle
> executables, installed package descriptions or source distributions.
> Nor does it handle any version stuff, and it may be a long time before
> Hugs can handle that.  Still, it does the basic job, and it works with
> all those packages, some of which require system-dependent parameters,
> preprocessing, and compilation of FFI stubs.  I hope that some of it
> (or equivalent) can be incorporated into Cabal, though I expect you
> won't want all of it.

This is indeed very cool.  Much of this should probably just be
integrated into the Distribution.Simple stuff for Hugs.  You should
feel welcome to do that if you like.  If not, this will give me a good
idea of what you believe needs to get done.

I went ahead and committed the hooks stuff to CVS so you can try it

I would guess that if we integrate the stuff that cabal should really
have for Hugs, and use the hooks (which will greatly reduce
boilerplate), HugsSetup.hs will be much smaller.  I think the only
sticking point is whether we have one file or two, the description
verses the build info.

By way of explanation for the hooks: I added the UserHooks type:

data UserHooks = UserHooks
     runTests :: Bool -> IO ExitCode, -- ^Used for './setup test'
     readDesc :: IO (Maybe PackageDescription), -- ^Read the description file

     preConf  :: IO (Maybe PackageDescription),
     postConf :: IO ExitCode,

     preBuild  :: IO (Maybe PackageDescription),
     postBuild :: IO ExitCode,

     preClean  :: IO (Maybe PackageDescription),
     postClean :: IO ExitCode,

     preCopy  :: IO (Maybe PackageDescription),
     postCopy :: IO ExitCode,

     preInst  :: IO (Maybe PackageDescription),
     postInst :: IO ExitCode, -- ^guaranteed to be run on target

     preSDist  :: IO (Maybe PackageDescription),
     postSDist :: IO ExitCode,

     preReg  :: IO (Maybe PackageDescription),
     postReg :: IO ExitCode,

     preUnreg  :: IO (Maybe PackageDescription),
     postUnreg :: IO ExitCode

and a file, hookedPackageDesc which the default pre-hooks read from,
is the same syntax as the package description.  There's a set of
default user-hooks:

defaultUserHooks :: UserHooks

where preConf does nothing, and pre-everything-else reads
hookedPackageDesc.  Then a new main function:

defaultMainWithHooks :: UserHooks
                     -> IO ()

So you can say:

myConf = do whenM (doesFileExist "configure") $
            system "./configure"

main = defaultMainWithHooks defaultUserHooks{preConf=myConf}

We could also try to come up with a good default behavior for preConf.

It looks like you use the params to configure, so maybe the hook
functions need to take the flags for each param as input or something.

This is all very experimental and likely to change.  For instance, I
had the idea that the post-hooks should exit if they got a bad exit
code, but that'll make it impossible to handle exceptions in the
user's 'main' function, and maybe the pre-hooks should have input



More information about the Libraries mailing list