Setup.hs: better version detection in older hsb2hs.
If it returns an error with input `--version`, recover gracefully.
This commit is contained in:
parent
48cd774714
commit
e042f697a4
1 changed files with 11 additions and 7 deletions
18
Setup.hs
18
Setup.hs
|
@ -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,13 +45,16 @@ main = defaultMainWithHooks $ simpleUserHooks {
|
|||
|
||||
findHsb2hsVersion :: Verbosity -> FilePath -> IO (Maybe Version)
|
||||
findHsb2hsVersion verb fp = do
|
||||
outp <- readProcess fp ["--version"] ""
|
||||
case readP_to_S (do v <- parseVersion
|
||||
skipSpaces
|
||||
eof
|
||||
return v) outp of
|
||||
((v,""):_) -> return (Just v)
|
||||
_ -> return Nothing
|
||||
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
|
||||
eof
|
||||
return v) outp of
|
||||
((v,""):_) -> return (Just v)
|
||||
_ -> return Nothing
|
||||
|
||||
ppBlobSuffixHandler :: PPSuffixHandler
|
||||
ppBlobSuffixHandler = ("hsb", \_ lbi ->
|
||||
|
|
Loading…
Reference in a new issue