Skip to content
This repository has been archived by the owner on Apr 25, 2020. It is now read-only.

Commit

Permalink
Support installing multiple ghc-mod instances
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielG committed May 21, 2017
1 parent dc0a161 commit 5855f59
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 13 deletions.
18 changes: 5 additions & 13 deletions core/Language/Haskell/GhcMod/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,20 @@ newTempDir _dir =
whenM :: Monad m => m Bool -> m () -> m ()
whenM mb ma = mb >>= flip when ma

-- | Returns the path to the currently running ghc-mod executable. With ghc<7.6
-- this is a guess but >=7.6 uses 'getExecutablePath'.
-- | Returns the path to the currently running ghc-mod executable.
ghcModExecutable :: IO FilePath
ghcModExecutable = do
exe <- getExecutablePath'
exe <- getExecutablePath
stack <- lookupEnv "STACK_EXE"
case takeBaseName exe of
"spec" | Just _ <- stack ->
(</> "ghc-mod") <$> getBinDir
(</> "ghc-mod-real") <$> getBinDir
"spec" ->
(</> "dist/build/ghc-mod/ghc-mod") <$> getCurrentDirectory
(</> "dist/build/ghc-mod-real/ghc-mod-real") <$> getCurrentDirectory
"ghc-mod" ->
return exe
_ ->
return $ takeDirectory exe </> "ghc-mod"

getExecutablePath' :: IO FilePath
#if __GLASGOW_HASKELL__ >= 706
getExecutablePath' = getExecutablePath
#else
getExecutablePath' = getProgName
#endif
return $ takeDirectory exe </> "ghc-mod-real"

canonFilePath :: FilePath -> IO FilePath
canonFilePath f = do
Expand Down
16 changes: 16 additions & 0 deletions ghc-mod.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,22 @@ Library
Build-Depends: convertible < 1.2 && >= 1.1.0.0

Executable ghc-mod
Default-Language: Haskell2010
Main-Is: GHCModWrapper.hs
Other-Modules: Paths_ghc_mod
HS-Source-Dirs: ., src, shared
GHC-Options: -Wall
Build-Depends: base < 5 && >= 4.0
, directory < 1.4
, filepath < 1.5
, process < 1.5

, deepseq < 1.5
, binary < 0.9 && >= 0.5.1.0
, old-time < 1.2
, time < 1.7

Executable ghc-mod-real
Default-Language: Haskell2010
Main-Is: GHCModMain.hs
Other-Modules: Paths_ghc_mod
Expand Down
30 changes: 30 additions & 0 deletions src/GHCModWrapper.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-- | Dispatcher program to support co-installation of multiple ghc-mod
-- instances (compiled against different GHC versions) without breaking the
-- commandline API
module Main where

import System.IO
import System.Exit
import System.Process
import System.FilePath
import System.Environment
import Utils

import Paths_ghc_mod

main :: IO ()
main = do
args <- getArgs
libexecdir <- getLibexecDir
let installedExe = libexecdir </> "ghc-mod-real"
mexe <- mightExist installedExe
case mexe of
Nothing -> do
hPutStrLn stderr $
"ghc-mod: Could not find '"++installedExe++"', check your installation!"
exitWith $ ExitFailure 1

Just exe -> do
(_, _, _, h) <-
createProcess $ proc exe args
exitWith =<< waitForProcess h

0 comments on commit 5855f59

Please sign in to comment.