2014-08-18 06:06:36 +00:00
|
|
|
{-# LANGUAGE ScopedTypeVariables, DeriveDataTypeable #-}
|
2014-03-25 02:14:25 +00:00
|
|
|
|
2014-10-22 22:56:18 +00:00
|
|
|
-- | WARNING
|
2015-04-29 16:44:46 +00:00
|
|
|
-- This program is deprecated, use `ghc-mod legacy-interactive` instead.
|
2014-03-27 01:34:43 +00:00
|
|
|
|
2014-03-19 01:23:47 +00:00
|
|
|
module Main where
|
|
|
|
|
2015-08-10 09:10:00 +00:00
|
|
|
import Control.Applicative
|
|
|
|
import Control.Monad
|
|
|
|
import Control.Exception
|
|
|
|
import Data.Version
|
|
|
|
import Data.Maybe
|
|
|
|
import System.IO
|
2015-04-29 16:44:46 +00:00
|
|
|
import System.Exit
|
|
|
|
import System.Process
|
2015-05-06 14:15:04 +00:00
|
|
|
import System.FilePath
|
2015-04-29 16:44:46 +00:00
|
|
|
import System.Environment
|
2015-05-06 14:15:04 +00:00
|
|
|
import Paths_ghc_mod
|
2015-08-10 09:10:00 +00:00
|
|
|
import Utils
|
|
|
|
import Prelude
|
2014-03-25 02:34:58 +00:00
|
|
|
|
2014-03-19 01:23:47 +00:00
|
|
|
main :: IO ()
|
2015-04-29 16:44:46 +00:00
|
|
|
main = do
|
2015-08-10 09:10:00 +00:00
|
|
|
hPutStrLn stderr $
|
|
|
|
"Warning: ghc-modi is deprecated please use 'ghc-mod legacy-interactive' instead"
|
|
|
|
|
2015-04-29 16:44:46 +00:00
|
|
|
args <- getArgs
|
2015-05-06 14:15:04 +00:00
|
|
|
bindir <- getBinDir
|
2015-08-10 09:10:00 +00:00
|
|
|
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) <-
|
|
|
|
createProcess $ proc exe $ ["legacy-interactive"] ++ args
|
|
|
|
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
|