conditionally exposing modules in cabal

I would like to conditionally expose a number of internal modules in a
library depending on a cabal flag - the idea is that new features
could be implemented externally to the library without contaminating
the source with undesirable changes. However, I've been unable to
find a way to structure a cabal file that does not require repeating
the list of modules. For example, this works:
exposed-modules:
Public.Stable.Module
if flag(exposeInternals)
exposed-modules:
<long list of internal modules>
else
other-modules:

On Thu, Aug 18, 2011 at 3:33 AM, Rogan Creswick
I would like to conditionally expose a number of internal modules in a library depending on a cabal flag - the idea is that new features could be implemented externally to the library without contaminating the source with undesirable changes. However, I've been unable to find a way to structure a cabal file that does not require repeating the list of modules. For example, this works:
One problem to consider - a downstream user of the new features won't know that they need to pass special flags to your module, and may not even know that they are using your module if the dependency is a few steps removed. What some folks have taken to doing is to either turn of Haddock documentation for the modules (as in Data.ByteString.Internal) or just provide great big warning messages that the functions provided can be used in ways which do not provide key invariants and that the contents of the module is subject to change at any time. Antoine
exposed-modules: Public.Stable.Module if flag(exposeInternals) exposed-modules: <long list of internal modules> else other-modules:
But I don't want to maintain two identical lists of modules in the cabal file.
I've tried putting the section headers in the if's, but this doesn't appear to work (cabal doesn't complain, but the modules to be exposed are not available as expected):
exposed-modules: Public.Stable.Module if flag(exposeInternals) { exposed-modules: } else { other-modules: } <long list of internal modules>
Does anyone have suggestions?
Thanks! Rogan
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Thu, Aug 18, 2011 at 4:41 AM, Antoine Latter
One problem to consider - a downstream user of the new features won't know that they need to pass special flags to your module, and may not even know that they are using your module if the dependency is a few steps removed.
The situation is more that I have a number of independent changes that I'd like to experiment with locally, without ever releasing them individually -- if/when they're released, they would build without the need to set the flag. The net effect is very similar to maintaining multiple branches of the primary project, but with more separation between the stable project and the experimental code. --Rogan
participants (2)
-
Antoine Latter
-
Rogan Creswick