1import Distribution.Simple
2import Distribution.Simple.Setup
3 (copyDest, copyVerbosity, fromFlag, installVerbosity, BuildFlags(..))
4import Distribution.PackageDescription
5 (PackageDescription(..), Executable(..), BuildInfo(..))
6import Distribution.Simple.LocalBuildInfo
7 (LocalBuildInfo(..), absoluteInstallDirs)
8import Distribution.Verbosity ( Verbosity, silent )
9import Distribution.Simple.InstallDirs (mandir, bindir, CopyDest (NoCopyDest))
10import Distribution.Simple.Utils (copyFiles)
11import Control.Exception ( bracket_ )
12import Control.Monad ( unless )
13import System.Process ( runCommand, runProcess, waitForProcess )
14import System.FilePath ( (</>), (<.>) )
15import System.Directory
16import System.IO ( stderr )
19import System.IO.Error ( isDoesNotExistError )
20import Data.Maybe ( catMaybes )
21import Data.List ( (\\) )
25 defaultMainWithHooks $ simpleUserHooks {
26 runTests = runTestSuite
27 , postBuild = makeManPages
28 , postCopy = \ _ flags pkg lbi -> do
29 installManpages pkg lbi (fromFlag $ copyVerbosity flags)
30 (fromFlag $ copyDest flags)
31 installScripts pkg lbi (fromFlag $ copyVerbosity flags)
32 (fromFlag $ copyDest flags)
33 , postInst = \ _ flags pkg lbi -> do
34 installManpages pkg lbi (fromFlag $ installVerbosity flags) NoCopyDest
35 installScripts pkg lbi (fromFlag $ installVerbosity flags) NoCopyDest
40runTestSuite :: Args -> Bool -> PackageDescription -> LocalBuildInfo -> IO a
41runTestSuite _ _ pkg _ = do
42 let isHighlightingKate (Dependency (PackageName "highlighting-kate") _) = True
43 isHighlightingKate _ = False
44 let highlightingSupport = any isHighlightingKate $ buildDepends pkg
45 let testArgs = ["lhs" | highlightingSupport]
46 let testCmd = "runhaskell -i.. RunTests.hs " ++ unwords testArgs
47 inDirectory "tests" $ runCommand testCmd >>= waitForProcess >>= exitWith
49-- | Build man pages from markdown sources in man/man1/.
50makeManPages :: Args -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
51makeManPages _ flags _ buildInfo =
52 mapM_ (makeManPage pandocPath (fromFlag $ buildVerbosity flags)) manpages
53 where pandocPath = (buildDir buildInfo) </> "pandoc" </> "pandoc"
56manpages = ["pandoc.1", "markdown2pdf.1"]
59manDir = "man" </> "man1"
61-- | Build a man page from markdown source in man/man1.
62makeManPage :: FilePath -> Verbosity -> FilePath -> IO ()
63makeManPage pandoc verbosity manpage = do
64 let page = manDir </> manpage
65 let source = page <.> "md"
66 modifiedDeps <- modifiedDependencies page [source]
67 unless (null modifiedDeps) $ do
68 ec <- runProcess pandoc ["-s", "-S", "-r", "markdown", "-w", "man",
69 "--template=templates/man.template", "-o", page, source]
70 Nothing Nothing Nothing Nothing (Just stderr) >>= waitForProcess
72 ExitSuccess -> unless (verbosity == silent) $
73 putStrLn $ "Created " ++ page
74 ExitFailure n -> putStrLn ("Error creating " ++ page ++
75 ". Exit code = " ++ show n) >> exitWith ec
77installScripts :: PackageDescription -> LocalBuildInfo
78 -> Verbosity -> CopyDest -> IO ()
79installScripts pkg lbi verbosity copy =
80 copyFiles verbosity (bindir (absoluteInstallDirs pkg lbi copy))
81 (zip (repeat ".") (wrappers \\ exes))
82 where exes = map exeName $ filter isBuildable $ executables pkg
83 isBuildable = buildable . buildInfo
84 wrappers = ["markdown2pdf"]
86installManpages :: PackageDescription -> LocalBuildInfo
87 -> Verbosity -> CopyDest -> IO ()
88installManpages pkg lbi verbosity copy =
89 copyFiles verbosity (mandir (absoluteInstallDirs pkg lbi copy) </> "man1")
90 (zip (repeat manDir) manpages)
92-- | Returns a list of 'dependencies' that have been modified after 'file'.
93modifiedDependencies :: FilePath -> [FilePath] -> IO [FilePath]
94modifiedDependencies file dependencies = do
95 fileModTime <- catch (getModificationTime file) $
96 \e -> if isDoesNotExistError e
97 then return (TOD 0 0) -- the minimum ClockTime
99 depModTimes <- mapM getModificationTime dependencies
100 let modified = zipWith (\dep time -> if time > fileModTime then Just dep else Nothing) dependencies depModTimes
101 return $ catMaybes modified
103-- | Perform an IO action in a directory.
104inDirectory :: FilePath -> IO a -> IO a
105inDirectory dir action = do
106 oldDir <- getCurrentDirectory
107 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