aboutsummaryrefslogtreecommitdiff
path: root/Setup.hs
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2008-08-09 18:14:20 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2008-08-09 18:14:20 +0000
commitdb729a08c89d7d93483a9b4e880d4f3bef17d521 (patch)
tree44c13e46b3a66c19385a8c1e42b656c8ba2c00a7 /Setup.hs
parent5d3d2d79b3e217e3b420e3d56c5e844e5cae5cf1 (diff)
downloadpandoc-db729a08c89d7d93483a9b4e880d4f3bef17d521.tar.gz
Added preconfigure hook to build reference.odt if missing.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@1386 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'Setup.hs')
-rw-r--r--Setup.hs47
1 files changed, 41 insertions, 6 deletions
diff --git a/Setup.hs b/Setup.hs
index bdef399a8..9bcbaa78a 100644
--- a/Setup.hs
+++ b/Setup.hs
@@ -1,13 +1,48 @@
import Distribution.Simple
+import Distribution.PackageDescription ( emptyHookedBuildInfo )
+import Control.Exception ( bracket_ )
import System.Process ( runCommand, waitForProcess )
-import System.Directory ( setCurrentDirectory )
+import System.FilePath ( (</>) )
+import System.Directory ( getCurrentDirectory, setCurrentDirectory, findExecutable, doesFileExist )
+import System.IO ( stderr )
+import System.Exit
+import Data.Maybe ( fromJust )
-main = defaultMainWithHooks (simpleUserHooks {runTests = runTestSuite})
-
-testDir = "tests"
+main = defaultMainWithHooks (simpleUserHooks {runTests = runTestSuite, preConf = checkReferenceODT})
+-- | Run test suite.
runTestSuite _ _ _ _ = do
- setCurrentDirectory testDir
- runCommand "runhaskell RunTests.hs" >>= waitForProcess
+ inDirectory "tests" $ runCommand "runhaskell RunTests.hs" >>= waitForProcess
return ()
+-- | If reference.odt does not exist, build it.
+checkReferenceODT _ _ = do
+ refODTexists <- doesFileExist ("odt-styles" </> "reference.odt")
+ if refODTexists
+ then return ()
+ else makeReferenceODT
+ return emptyHookedBuildInfo
+
+-- | Create reference.odt by zipping up sources in odt-styles directory.
+makeReferenceODT :: IO ()
+makeReferenceODT = do
+ zipPathMaybe <- findExecutable "zip"
+ if zipPathMaybe == Nothing
+ then error $ "The 'zip' command, which is needed to build reference.odt\n" ++
+ "from sources in the odt-styles directory, was not found.\n" ++
+ "Try again after installing zip (http://www.info-zip.org/Zip.html).\n" ++
+ "Or use the pandoc source tarball, which contains a prebuilt reference.odt."
+ else do
+ putStrLn "Creating reference.odt:"
+ inDirectory "odt-styles" $ do
+ ec <- runCommand "zip -9 -r reference.odt *" >>= waitForProcess
+ case ec of
+ ExitSuccess -> putStrLn "Done."
+ _ -> error "Error creating ODT."
+
+-- | 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
+