From 1c5a1c8b3ef9dd158cda528f68a6f68ccc219888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gr=C3=B6ber?= Date: Sat, 7 Feb 2015 23:48:33 +0100 Subject: [PATCH] Add util function for finding libexec binaries --- Language/Haskell/GhcMod/Utils.hs | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/Language/Haskell/GhcMod/Utils.hs b/Language/Haskell/GhcMod/Utils.hs index 5182089..1f1f63d 100644 --- a/Language/Haskell/GhcMod/Utils.hs +++ b/Language/Haskell/GhcMod/Utils.hs @@ -2,6 +2,7 @@ module Language.Haskell.GhcMod.Utils where import Control.Arrow +import Control.Applicative ((<$>)) import Data.Char import Language.Haskell.GhcMod.Error import MonadUtils (MonadIO, liftIO) @@ -9,12 +10,16 @@ import System.Directory (getCurrentDirectory, setCurrentDirectory, doesFileExist import System.Exit (ExitCode(..)) import System.Process (readProcessWithExitCode) import System.Directory (getTemporaryDirectory) -import System.FilePath (splitDrive, pathSeparators) +import System.FilePath (splitDrive, pathSeparators, ()) import System.IO.Temp (createTempDirectory) #ifndef SPEC -import Control.Applicative ((<$>)) +import Paths_ghc_mod (getLibexecDir) import System.Environment -import System.FilePath ((), takeDirectory) +import System.FilePath (takeDirectory) +#else +-- When compiling test suite +import Data.IORef +import System.IO.Unsafe #endif -- dropWhileEnd is not provided prior to base 4.5.0.0. @@ -33,7 +38,7 @@ extractParens str = extractParens' str 0 | s `elem` "}])" = s : extractParens' ss (level-1) | otherwise = s : extractParens' ss level -readProcess' :: (MonadIO m, MonadError GhcModError m) +readProcess' :: (MonadIO m, GmError m) => String -> [String] -> m String @@ -90,5 +95,22 @@ ghcModExecutable = do getExecutablePath' = return "" # endif #else -ghcModExecutable = return "dist/build/ghc-mod/ghc-mod" +ghcModExecutable = fmap ( "dist/build/ghc-mod/ghc-mod") getCurrentDirectory #endif + +#ifdef SPEC +-- Ugly workaround :'( but I can't think of any other way of doing this +-- the test suite changes the cwd often so I can't use relative paths :/ +specRootDir :: IORef FilePath +specRootDir = unsafePerformIO $ newIORef undefined +{-# NOINLINE specRootDir #-} +#endif + +findLibexecExe :: String -> IO FilePath +#ifndef SPEC +findLibexecExe "cabal-helper" = (fmap ( "cabal-helper")) getLibexecDir +#else +findLibexecExe "cabal-helper" = + ( "dist/build/cabal-helper/cabal-helper") <$> (readIORef specRootDir) +#endif +findLibexecExe exe = error $ "findLibexecExe: Unknown executable: " ++ exe