1import Distribution.Simple
2import Distribution.PackageDescription ( emptyHookedBuildInfo )
3import Control.Exception ( bracket_ )
4import Control.Monad ( unless )
5import System.Process ( runCommand, runProcess, waitForProcess )
6import System.FilePath ( (</>), (<.>) )
8import System.IO ( stderr )
11import System.IO.Error ( isDoesNotExistError )
12import Data.Maybe ( fromJust, isNothing, catMaybes )
15 defaultMainWithHooks $ simpleUserHooks { runTests = runTestSuite
16 , postBuild = makeManPages }
20runTestSuite _ _ _ _ = do
21 inDirectory "tests" $ runCommand "runhaskell -i.. RunTests.hs" >>= waitForProcess >>= exitWith
23-- | Build man pages from markdown sources in man/man1/.
24makeManPages _ _ _ _ = do
25 mapM_ makeManPage ["pandoc.1", "hsmarkdown.1", "html2markdown.1", "markdown2pdf.1"]
27-- | Build a man page from markdown source in man/man1.
28makeManPage manpage = do
29 let manDir = "man" </> "man1"
30 let pandoc = "dist" </> "build" </> "pandoc" </> "pandoc"
31 let page = manDir </> manpage
32 let source = manDir </> manpage <.> "md"
33 modifiedDeps <- modifiedDependencies page [source]
34 unless (null modifiedDeps) $ do
35 ec <- runProcess pandoc ["-s", "-S", "-r", "markdown", "-w", "man", "-o", page, source]
36 Nothing Nothing Nothing Nothing (Just stderr) >>= waitForProcess
38 ExitSuccess -> putStrLn $ "Created " ++ manDir </> manpage
39 _ -> do putStrLn $ "Error creating " ++ manDir </> manpage
42-- | Returns a list of 'dependencies' that have been modified after 'file'.
43modifiedDependencies :: FilePath -> [FilePath] -> IO [FilePath]
44modifiedDependencies file dependencies = do
45 fileModTime <- catch (getModificationTime file) $
46 \e -> if isDoesNotExistError e
47 then return (TOD 0 0) -- the minimum ClockTime
49 depModTimes <- mapM getModificationTime dependencies
50 let modified = zipWith (\dep time -> if time > fileModTime then Just dep else Nothing) dependencies depModTimes
51 return $ catMaybes modified
53-- | Perform an IO action in a directory.
54inDirectory :: FilePath -> IO a -> IO a
55inDirectory dir action = do
56 oldDir <- getCurrentDirectory
57 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