Setup.hs: better version detection in older hsb2hs.

If it returns an error with input `--version`, recover
gracefully.
This commit is contained in:
John MacFarlane 2015-07-06 13:38:46 -07:00
parent 48cd774714
commit e042f697a4

View file

@ -32,6 +32,7 @@ import Data.Version
import System.Process (readProcess)
import Text.ParserCombinators.ReadP (readP_to_S, skipSpaces, eof)
import Control.Monad (when)
import qualified Control.Exception as E
main :: IO ()
main = defaultMainWithHooks $ simpleUserHooks {
@ -44,6 +45,9 @@ main = defaultMainWithHooks $ simpleUserHooks {
findHsb2hsVersion :: Verbosity -> FilePath -> IO (Maybe Version)
findHsb2hsVersion verb fp = do
let handleExitFailure :: IOError -> IO (Maybe Version)
handleExitFailure _ = return Nothing
E.handle handleExitFailure $ do
outp <- readProcess fp ["--version"] ""
case readP_to_S (do v <- parseVersion
skipSpaces