1import Distribution.Simple
2import Control.Exception ( bracket_ )
3import Control.Monad ( unless )
4import System.Process ( runCommand, runProcess, waitForProcess )
5import System.FilePath ( (</>), (<.>) )
7import System.IO ( stderr, openTempFile )
10import System.IO.Error ( isDoesNotExistError )
11import Data.Maybe ( fromJust, isNothing, catMaybes )
12import Data.List ( isInfixOf )
15 defaultMainWithHooks $ simpleUserHooks { runTests = runTestSuite
16 , postBuild = makeManPages }
20runTestSuite _ _ _ _ = do
21 tempPath <- catch getTemporaryDirectory (\_ -> return ".")
22 (outputPath, hOut) <- openTempFile tempPath "out"
23 runProcess "pandoc" ["--version"] Nothing Nothing Nothing (Just hOut) Nothing >>= waitForProcess
24 output <- readFile outputPath
25 let highlightingSupport = "with syntax highlighting" `isInfixOf` output
26 let testArgs = if highlightingSupport then ["lhs"] else []
27 let testCmd = "runhaskell -i.. RunTests.hs " ++ unwords testArgs
28 inDirectory "tests" $ runCommand testCmd >>= waitForProcess >>= exitWith
30-- | Build man pages from markdown sources in man/man1/.
31makeManPages _ _ _ _ = do
32 mapM_ makeManPage ["pandoc.1", "hsmarkdown.1", "html2markdown.1", "markdown2pdf.1"]
34-- | Build a man page from markdown source in man/man1.
35makeManPage manpage = do
36 let manDir = "man" </> "man1"
37 let pandoc = "dist" </> "build" </> "pandoc" </> "pandoc"
38 let page = manDir </> manpage
39 let source = manDir </> manpage <.> "md"
40 modifiedDeps <- modifiedDependencies page [source]
41 unless (null modifiedDeps) $ do
42 ec <- runProcess pandoc ["-s", "-S", "-r", "markdown", "-w", "man",
43 "--template=templates/man.template", "-o", page, source]
44 Nothing Nothing Nothing Nothing (Just stderr) >>= waitForProcess
46 ExitSuccess -> putStrLn $ "Created " ++ manDir </> manpage
47 _ -> do putStrLn $ "Error creating " ++ manDir </> manpage
50-- | Returns a list of 'dependencies' that have been modified after 'file'.
51modifiedDependencies :: FilePath -> [FilePath] -> IO [FilePath]
52modifiedDependencies file dependencies = do
53 fileModTime <- catch (getModificationTime file) $
54 \e -> if isDoesNotExistError e
55 then return (TOD 0 0) -- the minimum ClockTime
57 depModTimes <- mapM getModificationTime dependencies
58 let modified = zipWith (\dep time -> if time > fileModTime then Just dep else Nothing) dependencies depModTimes
59 return $ catMaybes modified
61-- | Perform an IO action in a directory.
62inDirectory :: FilePath -> IO a -> IO a
63inDirectory dir action = do
64 oldDir <- getCurrentDirectory
65 bracket_ (setCurrentDirectory dir) (setCurrentDirectory oldDir) action
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list