1import Distribution.Simple
2import Distribution.PackageDescription ( emptyHookedBuildInfo )
3import Control.Exception ( bracket_ )
4import System.Process ( runCommand, runProcess, waitForProcess )
5import System.FilePath ( (</>), (<.>) )
7import System.IO ( stderr )
10import System.IO.Error ( isDoesNotExistError )
11import Data.Maybe ( fromJust, isNothing, catMaybes )
13main = defaultMainWithHooks $
14 simpleUserHooks { runTests = runTestSuite
15 , preConf = checkReferenceODT
16 , postBuild = makeManPages }
19runTestSuite _ _ _ _ = do
20 inDirectory "tests" $ runCommand "runhaskell RunTests.hs" >>= waitForProcess
23-- | If reference.odt needs rebuilding, build it.
24checkReferenceODT _ _ = inDirectory "odt-styles" $ do
25 let refodt = "reference.odt"
26 let deps = [ "meta.xml", "content.xml", "settings.xml", "META-INF/manifest.xml",
27 "Thumbnails/thumbnail.png", "styles.xml", "mimetype" ]
28 modifiedDeps <- modifiedDependencies refodt deps
31 else makeReferenceODT modifiedDeps
32 return emptyHookedBuildInfo
34-- | Create reference.odt by zipping up sources in odt-styles directory.
35makeReferenceODT :: [FilePath] -> IO ()
36makeReferenceODT sources = do
37 zipPathMaybe <- findExecutable "zip"
38 if isNothing zipPathMaybe
39 then error $ "The 'zip' command, which is needed to build reference.odt\n" ++
40 "from sources in the odt-styles directory, was not found.\n" ++
41 "Try again after installing zip (http://www.info-zip.org/Zip.html).\n" ++
42 "Or use the pandoc source tarball, which contains a prebuilt reference.odt."
44 putStrLn "Creating reference.odt:"
45 ec <- runProcess (fromJust zipPathMaybe) (["-9", "-r", "reference.odt"] ++ sources)
46 Nothing Nothing Nothing Nothing (Just stderr) >>= waitForProcess
48 ExitSuccess -> return ()
49 _ -> error "Error creating ODT."
51-- | Build man pages from markdown sources in man/man1/.
52makeManPages _ _ _ _ = do
53 mapM makeManPage ["pandoc.1", "hsmarkdown.1", "markdown2pdf.1", "html2markdown.1"]
56-- | Build a man page from markdown source in man/man1.
57makeManPage manpage = do
58 let manDir = "man" </> "man1"
59 let pandoc = "dist" </> "build" </> "pandoc" </> "pandoc"
60 let page = manDir </> manpage
61 let source = manDir </> manpage <.> "md"
62 modifiedDeps <- modifiedDependencies page [source]
66 ec <- runProcess pandoc ["-s", "-r", "markdown", "-w", "man", "-o", page, source]
67 Nothing Nothing Nothing Nothing (Just stderr) >>= waitForProcess
69 ExitSuccess -> putStrLn $ "Created " ++ manDir </> manpage
70 _ -> error $ "Error creating " ++ manDir </> manpage
72-- | Returns a list of 'dependencies' that have been modified after 'file'.
73modifiedDependencies :: FilePath -> [FilePath] -> IO [FilePath]
74modifiedDependencies file dependencies = do
75 fileModTime <- catch (getModificationTime file) $
76 \e -> if isDoesNotExistError e
77 then return (TOD 0 0) -- the minimum ClockTime
79 depModTimes <- mapM getModificationTime dependencies
80 let modified = zipWith (\dep time -> if time > fileModTime then Just dep else Nothing) dependencies depModTimes
81 return $ catMaybes modified
83-- | Perform an IO action in a directory.
84inDirectory :: FilePath -> IO a -> IO a
85inDirectory dir action = do
86 oldDir <- getCurrentDirectory
87 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