Bind ghc-modi executable to right ghc-mod exe

This commit is contained in:
Daniel Gröber 2015-08-10 11:10:00 +02:00
parent 54dcfdf291
commit 2cd4d6bd80
2 changed files with 42 additions and 4 deletions

View File

@ -184,15 +184,18 @@ Executable ghc-modi
Main-Is: GHCModi.hs Main-Is: GHCModi.hs
Other-Modules: Paths_ghc_mod Other-Modules: Paths_ghc_mod
Misc Misc
Utils
GHC-Options: -Wall -threaded -fno-warn-deprecations GHC-Options: -Wall -threaded -fno-warn-deprecations
if os(windows) if os(windows)
Cpp-Options: -DWINDOWS Cpp-Options: -DWINDOWS
Default-Extensions: ConstraintKinds, FlexibleContexts Default-Extensions: ConstraintKinds, FlexibleContexts
HS-Source-Dirs: src HS-Source-Dirs: src, .
Build-Depends: base >= 4.0 && < 5 Build-Depends: base >= 4.0 && < 5
, directory , directory
, filepath , filepath
, process , process
, time
, old-time
Test-Suite doctest Test-Suite doctest
Type: exitcode-stdio-1.0 Type: exitcode-stdio-1.0

View File

@ -5,16 +5,51 @@
module Main where module Main where
import Control.Applicative
import Control.Monad
import Control.Exception
import Data.Version
import Data.Maybe
import System.IO
import System.Exit import System.Exit
import System.Process import System.Process
import System.FilePath import System.FilePath
import System.Environment import System.Environment
import Paths_ghc_mod import Paths_ghc_mod
import Utils
import Prelude
main :: IO () main :: IO ()
main = do main = do
hPutStrLn stderr $
"Warning: ghc-modi is deprecated please use 'ghc-mod legacy-interactive' instead"
args <- getArgs args <- getArgs
bindir <- getBinDir bindir <- getBinDir
let installedExe = bindir </> "ghc-mod"
mexe <- mplus <$> mightExist installedExe <*> pathExe
case mexe of
Nothing -> do
hPutStrLn stderr $
"ghc-modi: Could not find '"++installedExe++"', check your installation!"
exitWith $ ExitFailure 1
Just exe -> do
(_, _, _, h) <- (_, _, _, h) <-
createProcess $ proc (bindir </> "ghc-mod") $ ["legacy-interactive"] ++ args createProcess $ proc exe $ ["legacy-interactive"] ++ args
exitWith =<< waitForProcess h exitWith =<< waitForProcess h
pathExe :: IO (Maybe String)
pathExe = do
ev <- try $ words <$> readProcess "ghc-mod" ["--version"] ""
let mexe = case ev of
Left (SomeException _) -> Nothing
Right ["ghc-mod", "version", ver
, "compiled", "by", "GHC", _]
| showVersion version == ver -> do
Just "ghc-mod"
Right _ -> Nothing
when (isNothing mexe) $
hPutStrLn stderr "ghc-modi: ghc-mod executable on PATH has different version, check your installation!"
return mexe