git.iko.soy/typeable/pandoc
on master help sign in
Setup.hs: rewrite so as not to use process, directory, filepath.

Using anything outside base is dangerous, since older versions of ghc will link against two different versions. See e.g. - https://groups.google.com/forum/#!topic/pandoc-discuss/0r9Hhl730LY - https://www.reddit.com/r/haskell/comments/3634x2/cabal_is_giving_a_weird_error_when_attempting_to/ - jaspervdj/hakyll#356

commitd62b1cf180281098c3093a817654d24563c4243d authorJohn MacFarlane <jgm@berkeley.edu> dateFri 9 Oct 2015, 21:50 (11 years ago) parent59193d8
1 file changed+10−25
Setup.hs+10−25
Setup.hs+10−25
@@ -20,17 +20,14 @@ import Distribution.Simple
2020import Distribution.Simple.PreProcess
2121import Distribution.Simple.Setup (ConfigFlags(..))
2222import Distribution.PackageDescription (PackageDescription(..), FlagName(..))
23−import System.Process ( rawSystem )
24−import System.FilePath ( (</>) )
25−import System.Directory ( findExecutable )
23+import Distribution.Simple.Utils ( rawSystemExitCode, findProgramVersion )
24+import System.Exit
2625import Distribution.Verbosity ( Verbosity )
2726import Distribution.Simple.Utils (info, notice, installOrdinaryFiles)
2827import Distribution.Simple.Setup
2928import Distribution.Simple.Program (simpleProgram, Program(..))
3029import Distribution.Simple.LocalBuildInfo
3130import Data.Version
32−import System.Process (readProcess)
33−import Text.ParserCombinators.ReadP (readP_to_S, skipSpaces, eof)
3431import Control.Monad (when)
3532import qualified Control.Exception as E
3633
@@ -39,23 +36,11 @@ main = defaultMainWithHooks $ simpleUserHooks {
3936 -- enable hsb2hs preprocessor for .hsb files
4037 hookedPreProcessors = [ppBlobSuffixHandler]
4138 , hookedPrograms = [(simpleProgram "hsb2hs"){
42− programFindVersion = findHsb2hsVersion }]
39+ programFindVersion = \verbosity fp ->
40+ findProgramVersion "--version" id verbosity fp }]
4341 , postCopy = installManPage
4442 }
4543
46−findHsb2hsVersion :: Verbosity -> FilePath -> IO (Maybe Version)
47−findHsb2hsVersion verb fp = do
48− let handleExitFailure :: IOError -> IO (Maybe Version)
49− handleExitFailure _ = return Nothing
50− E.handle handleExitFailure $ do
51− outp <- readProcess fp ["--version"] ""
52− case readP_to_S (do v <- parseVersion
53− skipSpaces
54− eof
55− return v) outp of
56− ((v,""):_) -> return (Just v)
57− _ -> return Nothing
58−
5944ppBlobSuffixHandler :: PPSuffixHandler
6045ppBlobSuffixHandler = ("hsb", \_ lbi ->
6146 PreProcessor {
@@ -67,11 +52,11 @@ ppBlobSuffixHandler = ("hsb", \_ lbi ->
6752 _ -> False
6853 when embedData $
6954 do info verbosity $ "Preprocessing " ++ infile ++ " to " ++ outfile
70− hsb2hsPath <- findExecutable "hsb2hs"
71− case hsb2hsPath of
72− Just p -> rawSystem p [infile, infile, outfile]
73− Nothing -> error "hsb2hs is needed to build this program: cabal install hsb2hs"
74− return ()
55+ ec <- rawSystemExitCode verbosity "hsb2hs"
56+ [infile, infile, outfile]
57+ case ec of
58+ ExitSuccess -> return ()
59+ ExitFailure _ -> error "hsb2hs is needed to build this program"
7560 })
7661
7762installManPage :: Args -> CopyFlags
@@ -80,6 +65,6 @@ installManPage _ flags pkg lbi = do
8065 let verbosity = fromFlag (copyVerbosity flags)
8166 let copydest = fromFlag (copyDest flags)
8267 let mandest = mandir (absoluteInstallDirs pkg lbi copydest)
83− </> "man1"
68+ ++ "/man1"
8469 notice verbosity $ "Copying man page to " ++ mandest
8570 installOrdinaryFiles verbosity mandest [("man", "pandoc.1")]