
I have a cabal package that defines a few dozen modules, and I'm hoping to generate documentation and code coverage for all modules without listing each module explicitly. currently my .cabal includes: library exposed-modules: Language.Idl.Data, Language.Idl.Merge, Language.Idl.Parser, ...lots more... my Setup.hs includes an explicit system call to hpc: exec "hpc" ["markup" , "--include=Language.Idl.Data" , "--include=Language.Idl.Merge" , "--include=Language.Idl.Parser" ...all the same files as above... ] Questions: 1) Is there a way to create haddock docs for /all/ modules, instead of just the ones listed by 'exposed-modules'? 2) Is there a way to query cabal for the list of modules? Or by chance has hpc recently been integrated with cabal? Thanks, Greg

The workaround is for a script to traverse the filesystem and generate a
list of modules that can then be copied into the .cabal for haddock and
Setup.hs for hpc. If anyone else is trying to do the same, here's the code:
http://hpaste.org/fastcgi/hpaste.fcgi/view?id=11224#a11224
script copied below:
import System.Directory(doesDirectoryExist, getDirectoryContents)
import Data.Tree(unfoldTreeM, flatten)
import Control.Monad(filterM)
import System.FilePath(splitDirectories, dropExtension, takeExtension)
import Data.List(sort, intercalate)
main :: IO ()
main = do
paths <- modules
putStrLn (cabal paths)
putStrLn (hpc paths)
cabal :: [String] -> String
cabal xs = header ++ intercalate sep xs
where
header = " exposed-modules: "
sep = ",\n "
hpc :: [String] -> String
hpc = concatMap include
where
include x = pre ++ x ++ "\""
pre = "\n , \"--include="
modules :: IO [String]
modules = do
paths <- filePaths "."
return [modName p | p <- paths, takeExtension p == ".hs"]
where
modName = intercalate "." . splitDirectories . dropExtension
filePaths :: FilePath -> IO [FilePath]
filePaths path = do
tree <- unfoldTreeM childPaths path
filterM (fmap not . doesDirectoryExist) (flatten tree)
childPaths :: FilePath -> IO (FilePath, [String])
childPaths dir = do
b <- doesDirectoryExist dir
fs <- if b then getDirectoryContents dir else return []
return (dir, [dir ++ "/" ++ p | p <- fs, head p /= '.'])
-Greg
On Tue, Oct 27, 2009 at 2:33 PM, Greg Fitzgerald
I have a cabal package that defines a few dozen modules, and I'm hoping to generate documentation and code coverage for all modules without listing each module explicitly.
currently my .cabal includes:
library exposed-modules: Language.Idl.Data, Language.Idl.Merge, Language.Idl.Parser, ...lots more...
my Setup.hs includes an explicit system call to hpc:
exec "hpc" ["markup" , "--include=Language.Idl.Data" , "--include=Language.Idl.Merge" , "--include=Language.Idl.Parser" ...all the same files as above... ]
Questions: 1) Is there a way to create haddock docs for /all/ modules, instead of just the ones listed by 'exposed-modules'? 2) Is there a way to query cabal for the list of modules? Or by chance has hpc recently been integrated with cabal?
Thanks, Greg

On Tue, 2009-10-27 at 14:33 -0700, Greg Fitzgerald wrote:
my Setup.hs includes an explicit system call to hpc:
exec "hpc" ["markup" , "--include=Language.Idl.Data" , "--include=Language.Idl.Merge" , "--include=Language.Idl.Parser" ...all the same files as above... ]
Why do you want to explicitly specify hpc --include=blah for every module? By default "hpc markup" will generate pages for every module in the program. Am I missing something?
Questions: 1) Is there a way to create haddock docs for /all/ modules, instead of just the ones listed by 'exposed-modules'?
Yes $ cabal haddock --help [...] --executables Run haddock for Executables targets --internal Run haddock for internal modules and include all symbols [...] This is also documented in the Cabal user guide.
2) Is there a way to query cabal for the list of modules? Or by chance has hpc recently been integrated with cabal?
Certainly it'd be nice to have more direct support for making a hpc flavour build using cabal. There's an open ticket on that feature request. But I don't think it's that hard at the moment. I use hpc with cabal frequently. Just cabal build --ghc-option=-fhpc. The only thing you have to watch out for is if you've got multiple executables in the .cabal file since the files that hpc writes out for the Main modules clash with each other. Duncan

Duncan wrote:
By default "hpc markup" will generate pages for every module in the program. Am I missing something?
Nope, user error. I started using --include to avoid running coverage over my test framework files, and was looking for something like haddock's "internal" flag before thinking to just delete all the --include lines. "Nothing means something" didn't occur to me. Thanks! Duncan wrote:
$ cabal haddock --help [...] --executables Run haddock for Executables targets --internal Run haddock for internal modules and include all symbols [...]
Great! Looks like these docs are new to 2.4.x. $ haddock --version Haddock version 2.3.0, (c) Simon Marlow 2006 Ported to use the GHC API by David Waern 2006-2008 $ haddock --help | grep internal $ Thanks for your help Duncan. -Greg

On Wed, 2009-10-28 at 10:43 -0700, Greg Fitzgerald wrote:
Duncan wrote:
$ cabal haddock --help [...] --executables Run haddock for Executables targets --internal Run haddock for internal modules and include all symbols [...]
Great! Looks like these docs are new to 2.4.x.
$ haddock --version Haddock version 2.3.0, (c) Simon Marlow 2006 Ported to use the GHC API by David Waern 2006-2008 $ haddock --help | grep internal
Note the command I gave was "cabal haddock" not "haddock". The cabal one calls haddock with the modules in the .cabal file (and other info like the package name, version and description). If what you wanted was to call haddock directly then you can list the modules you like on the command line. It's usually easier to use the cabal wrapper however since it passes all the flags to get links to other packages which otherwise you have to list manually. Duncan
participants (2)
-
Duncan Coutts
-
Greg Fitzgerald