hasLibs and hasExes honest reporting?

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

On Wed, 2008-04-30 at 15:32 -0400, Yaakov Nemoy wrote:

> >  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.
> Ack, what I meant to say is that hasLibs returns False.

In that case I expect it is because you have used
flattenPackageDescription to get a PackageDescription from a
GenericPackageDescription. This function makes sense in some
circumstances but not for what you want.

If we look in xmonad.cabal we see:

    exposed-modules:    XMonad
    if flag(testing)
        buildable: False

So when the testing flag is True, the library will not be buildable. The
hasLibs function actually only tells you about buildable libraries (the
same goes for hasExes).

If you use flattenPackageDescription on this description you will get a
PackageDescription whith buildable: False because flattening ignores all
conditions and includes *both* sides of conditionals.

So what you want is finalizePackageDescription to get a
PackageDescription that reflects how the package can actually be
configured given the environment in which you expect to use it.

I discussed this point with Brian O'Sullivan on irc the other day.

One API improvement we should do is to make hasLibs and similar
functions take a parameter to say if you want to include or exclude
buildable components since the choice is important and we've had a
couple bugs in cabal because of this issue (for example bugs like not
including non-buildable components in the source tarball).


More information about the cabal-devel mailing list