2006-10-17 16:22:29 +02:00
|
|
|
import Distribution.Simple
|
2009-02-14 17:25:39 +01:00
|
|
|
import Distribution.Package ( pkgName )
|
|
|
|
import Distribution.Simple.LocalBuildInfo ( packageDeps )
|
2008-08-09 20:14:20 +02:00
|
|
|
import Distribution.PackageDescription ( emptyHookedBuildInfo )
|
|
|
|
import Control.Exception ( bracket_ )
|
2008-10-27 22:52:31 +01:00
|
|
|
import Control.Monad ( unless )
|
2008-08-10 01:45:40 +02:00
|
|
|
import System.Process ( runCommand, runProcess, waitForProcess )
|
|
|
|
import System.FilePath ( (</>), (<.>) )
|
|
|
|
import System.Directory
|
2008-08-09 20:14:20 +02:00
|
|
|
import System.IO ( stderr )
|
|
|
|
import System.Exit
|
2008-08-10 01:45:40 +02:00
|
|
|
import System.Time
|
|
|
|
import System.IO.Error ( isDoesNotExistError )
|
|
|
|
import Data.Maybe ( fromJust, isNothing, catMaybes )
|
2008-08-09 18:51:08 +02:00
|
|
|
|
2008-10-27 22:52:31 +01:00
|
|
|
main = do
|
|
|
|
defaultMainWithHooks $ simpleUserHooks { runTests = runTestSuite
|
|
|
|
, postBuild = makeManPages }
|
|
|
|
exitWith ExitSuccess
|
2008-08-09 18:51:08 +02:00
|
|
|
|
2008-08-09 20:14:20 +02:00
|
|
|
-- | Run test suite.
|
2009-02-14 17:25:39 +01:00
|
|
|
runTestSuite _ _ _ local = do
|
|
|
|
let highlightingSupport = (PackageName "highlighting-kate") `elem` (map pkgName $ packageDeps local)
|
|
|
|
let testArgs = if highlightingSupport then ["lhs"] else []
|
|
|
|
let testCmd = "runhaskell -i.. RunTests.hs " ++ unwords testArgs
|
|
|
|
inDirectory "tests" $ runCommand testCmd >>= waitForProcess >>= exitWith
|
2008-02-09 04:20:42 +01:00
|
|
|
|
2008-08-10 01:45:40 +02:00
|
|
|
-- | Build man pages from markdown sources in man/man1/.
|
|
|
|
makeManPages _ _ _ _ = do
|
2008-10-27 22:52:31 +01:00
|
|
|
mapM_ makeManPage ["pandoc.1", "hsmarkdown.1", "html2markdown.1", "markdown2pdf.1"]
|
2008-08-10 01:45:40 +02:00
|
|
|
|
|
|
|
-- | Build a man page from markdown source in man/man1.
|
|
|
|
makeManPage manpage = do
|
|
|
|
let manDir = "man" </> "man1"
|
|
|
|
let pandoc = "dist" </> "build" </> "pandoc" </> "pandoc"
|
|
|
|
let page = manDir </> manpage
|
|
|
|
let source = manDir </> manpage <.> "md"
|
|
|
|
modifiedDeps <- modifiedDependencies page [source]
|
2008-10-27 22:52:31 +01:00
|
|
|
unless (null modifiedDeps) $ do
|
|
|
|
ec <- runProcess pandoc ["-s", "-S", "-r", "markdown", "-w", "man", "-o", page, source]
|
|
|
|
Nothing Nothing Nothing Nothing (Just stderr) >>= waitForProcess
|
|
|
|
case ec of
|
|
|
|
ExitSuccess -> putStrLn $ "Created " ++ manDir </> manpage
|
|
|
|
_ -> do putStrLn $ "Error creating " ++ manDir </> manpage
|
|
|
|
exitWith ec
|
2008-08-10 01:45:40 +02:00
|
|
|
|
|
|
|
-- | Returns a list of 'dependencies' that have been modified after 'file'.
|
|
|
|
modifiedDependencies :: FilePath -> [FilePath] -> IO [FilePath]
|
|
|
|
modifiedDependencies file dependencies = do
|
|
|
|
fileModTime <- catch (getModificationTime file) $
|
|
|
|
\e -> if isDoesNotExistError e
|
|
|
|
then return (TOD 0 0) -- the minimum ClockTime
|
|
|
|
else ioError e
|
|
|
|
depModTimes <- mapM getModificationTime dependencies
|
|
|
|
let modified = zipWith (\dep time -> if time > fileModTime then Just dep else Nothing) dependencies depModTimes
|
|
|
|
return $ catMaybes modified
|
2008-08-09 20:14:20 +02:00
|
|
|
|
|
|
|
-- | Perform an IO action in a directory.
|
|
|
|
inDirectory :: FilePath -> IO a -> IO a
|
|
|
|
inDirectory dir action = do
|
|
|
|
oldDir <- getCurrentDirectory
|
|
|
|
bracket_ (setCurrentDirectory dir) (setCurrentDirectory oldDir) action
|
|
|
|
|