Setup.hs woes

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Setup.hs woes

Ramnath R Iyer
Hello,

I've been having some trouble with Setup.hs and could use some help. I'm using stack for building my project, and would like to auto-generate an HTML file as part of the build process. I'm able to specify hooks in Setup.hs to do this, but I'm running into problems.

1. I'm not sure what the "correct" or suitable paths are for publishing HTML documentation. The closest I could find was the doc dir on the install path (see below). Should the HTML be created in a built folder and later copied over to an install/dist dir? The semantics associated with each of these is not clear to me.

2. I played around with some hooks. I was able to generate the HTML file in the installation's doc dir, but it looks like that dir is only created as part of the install hook (naturally), whereas the install hook is never triggered by `stack build`. (The code below never executes if I use the instHook.) What is the right hook to use, and how?

import Distribution.PackageDescription (PackageDescription)
import Distribution.Simple (defaultMainWithHooks, simpleUserHooks)
import Distribution.Simple.InstallDirs (InstallDirs(..), docdir)
import Distribution.Simple.LocalBuildInfo (LocalBuildInfo(..), installDirTemplates, fromPathTemplate)
import Distribution.Simple.Setup (InstallFlags)
import Distribution.Simple.UserHooks (UserHooks, instHook)
import System.Exit (ExitCode(..))
import System.Process (system)

main :: IO ()
main = defaultMainWithHooks simpleUserHooks { instHook = readme } -- does not get invoked; postBuild does work, but where to put the generated file?

readme :: PackageDescription -> LocalBuildInfo -> UserHooks -> InstallFlags -> IO ()
readme _ (LocalBuildInfo { installDirTemplates = InstallDirs { docdir = docdir' }}) _ _ = do
  putStrLn "Generating README.html from README.md..."
  exitCode <- system $ "./doc/generate " ++ (show destination)
  case exitCode of ExitSuccess   -> return ()
                   ExitFailure _ -> fail "README.html could not be generated from README.md"
  return ()
    where destination = fromPathTemplate docdir'

***

(Apologies if this is a duplicate email, wasn't sure if this already got sent previously.)

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners