Make cabal require hsb2hs >= 0.3.1.

This is done by adding `hookedPrograms` in `Setup.hs`,
which allows us to include `hsb2hs` in Build-Tools in cabal.
This commit is contained in:
John MacFarlane 2015-07-05 13:50:10 -07:00
parent 6e121bfafc
commit f1103f8f69
3 changed files with 19 additions and 2 deletions

View file

@ -119,7 +119,7 @@ assume that the pandoc source directory is your working directory.
- `embed_data_files`: embed all data files into the binary (default no).
This is helpful if you want to create a relocatable binary.
Note: if this option is selected, you need to install the
`hsb2hs` preprocessor: `cabal install hsb2hs` (version 0.3 or
`hsb2hs` preprocessor: `cabal install hsb2hs` (version 0.3.1 or
higher is required).
- `https`: enable support for downloading resources over https

View file

@ -23,18 +23,35 @@ import Distribution.PackageDescription (PackageDescription(..), FlagName(..))
import System.Process ( rawSystem )
import System.FilePath ( (</>) )
import System.Directory ( findExecutable )
import Distribution.Verbosity ( Verbosity )
import Distribution.Simple.Utils (info, notice, installOrdinaryFiles)
import Distribution.Simple.Setup
import Distribution.Simple.Program (simpleProgram, Program(..))
import Distribution.Simple.LocalBuildInfo
import Data.Version
import System.Process (readProcess)
import Text.ParserCombinators.ReadP (readP_to_S, skipSpaces, eof)
import Control.Monad (when)
main :: IO ()
main = defaultMainWithHooks $ simpleUserHooks {
-- enable hsb2hs preprocessor for .hsb files
hookedPreProcessors = [ppBlobSuffixHandler]
, hookedPrograms = [(simpleProgram "hsb2hs"){
programFindVersion = findHsb2hsVersion }]
, postCopy = installManPage
}
findHsb2hsVersion :: Verbosity -> FilePath -> IO (Maybe Version)
findHsb2hsVersion verb fp = do
outp <- readProcess fp ["--version"] ""
case readP_to_S (do v <- parseVersion
skipSpaces
eof
return v) outp of
((v,""):_) -> return (Just v)
_ -> return Nothing
ppBlobSuffixHandler :: PPSuffixHandler
ppBlobSuffixHandler = ("hsb", \_ lbi ->
PreProcessor {

View file

@ -292,7 +292,7 @@ Library
cpp-options: -DHTTP_CLIENT
if flag(embed_data_files)
cpp-options: -DEMBED_DATA_FILES
-- Build-Tools: hsb2hs -- not yet recognized by cabal
Build-Tools: hsb2hs >= 0.3.1
other-modules: Text.Pandoc.Data
if os(windows)
Cpp-options: -D_WINDOWS