import Control.Applicative import Control.Monad import Control.Exception as E import Data.Char import Data.List import Data.Maybe import Data.Version import Data.Typeable import System.Environment import System.FilePath hiding ((<.>)) import qualified System.FilePath as FP import System.Directory import System.IO.Unsafe import Text.Printf import GHC.Generics import Prelude main = do print =<< tryFindCabalHelperTreeLibexecDir tryFindCabalHelperTreeLibexecDir :: IO (Maybe FilePath) tryFindCabalHelperTreeLibexecDir = do exe <- getExecutablePath' dir <- case takeFileName exe of "ghc" -> do -- we're probably in ghci; try CWD getCurrentDirectory _ -> return $ (!!4) $ iterate takeDirectory exe print ("dir", dir) exists <- doesFileExist $ dir "cabal-helper.cabal" return $ if exists then Just dir else Nothing getExecutablePath' :: IO FilePath getExecutablePath' = getExecutablePath