hasLibs and hasExes honest reporting?

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Wed Apr 30 04:04:41 EDT 2008


On Tue, 2008-04-29 at 17:59 -0400, Yaakov Nemoy wrote:
> Hi List,
> 
> First off, I want to say hi, as this is my first post.  I'm trying to
> get some badly needed updates to cabal-rpm, so we can get more Haskell
> packages into Fedora. 

Great! :-)

> All of the following is with Cabal 1.2.3.0 and
> GHC 6.8.2 as packaged in Fedora 8.
> 
> In the module Distribution.PackageDescription, there are four
> functions, hasExes, and hasLibs, as well as libModules and exeModules.
>  These functions claim to do the obvious for a PackageDescription.
> The only problem I'm having is with packages like xmonad, which have
> both Executables and Libraries.
> 
> In the case of xmobar, hasLibs returns False, and an empty list for
> libModules, but True and a list for hasExes and exeModules
> respectively.

This is as you expect right? The xmobar package contains one exe.

> In the case of xmonad-contrib, the opposite is true, that is there are
> no Executables at all, but a bucket load of Libraries.

Yes.

> In the case of xmonad, hasLibs returns True. but returns a nonempty
> list.  hasExes returns True, and with the same nonempty list.  I would
> expect the lists to be the same, as all the Modules listed therein are
> needed to compile the executable, and also to be linked with the user
> supplied config file.  The only problem I see is with hasLibs itself.

http://hackage.haskell.org/packages/archive/xmonad/0.7/xmonad.cabal

Looking at the xmonad.cabal file we see that xmonad does contain both a
library and an executable, so we would expect hasLibs and hasExes to
return True. The reason the modules returned for both are the same is
because the list of exposed-modules and other-modules in the
xmonad.cabal are exactly the same for the lib and for the exe.

> I heard something a while back that xmonad needs to be compiled twice,
> because this setup is considered an edge case in Cabal.  Because
> xmonad is the reason why I'm working on getting Haskell packages into
> Fedora, I'm not sure I want to think of it that way.  Is this a bug,
> or just a 'feature' I need to watch out for?

What they meant is that it is not currently possible to make a package
with a library and an executable where the executable links against the
library, instead it must compile the same modules that are in the
library itself. So that's what people mean by having to compile things
twice.

If/when it becomes possible we'd write something like:

library
    exposed-modules:    XMonad
                        XMonad.Main
[...etc...]

executable xmonad
    main-is:            Main.hs
    build-depends:      xmonad
[...etc...]

That is, we'd specify that the xmonad depends on the xmonad library.
Then it would not be necessary to list all the modules twice and have
them compiled twice.


So in summary: there is no bug. xmonad really does contain a library and
an executable. The only limitation is that a few modules get compiled
twice rather than once.

Duncan



More information about the cabal-devel mailing list