2011-11-02 01:43:34 +00:00
|
|
|
{-# LANGUAGE DoAndIfThenElse #-}
|
|
|
|
|
2011-11-01 22:06:53 +00:00
|
|
|
module CabalDev (modifyOptions) where
|
|
|
|
|
|
|
|
{-
|
2011-11-02 01:43:34 +00:00
|
|
|
If the directory 'cabal-dev/packages-X.X.X.conf' exists, add it to the
|
2011-11-01 22:06:53 +00:00
|
|
|
options ghc-mod uses to check the source. Otherwise just pass it on.
|
|
|
|
-}
|
|
|
|
|
2011-11-24 11:43:15 +00:00
|
|
|
import Control.Applicative ((<$>))
|
2011-11-01 22:06:53 +00:00
|
|
|
import Data.Maybe (listToMaybe)
|
|
|
|
import System.FilePath.Find
|
2011-11-14 10:20:02 +00:00
|
|
|
import System.FilePath.Posix (splitPath,joinPath,(</>))
|
2011-11-01 22:06:53 +00:00
|
|
|
import System.Posix.Directory (getWorkingDirectory)
|
|
|
|
import System.Directory
|
|
|
|
|
|
|
|
import Types
|
|
|
|
|
|
|
|
modifyOptions :: Options -> IO Options
|
|
|
|
modifyOptions opts =
|
|
|
|
fmap (has_cdev opts) findCabalDev
|
|
|
|
where
|
2011-11-02 01:43:34 +00:00
|
|
|
has_cdev :: Options -> Maybe String -> Options
|
|
|
|
has_cdev op Nothing = op
|
|
|
|
has_cdev op (Just path) = addPath op path
|
2011-11-01 22:06:53 +00:00
|
|
|
|
|
|
|
findCabalDev :: IO (Maybe String)
|
|
|
|
findCabalDev =
|
|
|
|
getWorkingDirectory >>= searchIt . splitPath
|
|
|
|
|
|
|
|
addPath :: Options -> String -> Options
|
|
|
|
addPath orig_opts path = do
|
2011-11-14 10:20:02 +00:00
|
|
|
let orig_ghcopt = ghcOpts orig_opts
|
|
|
|
orig_opts { ghcOpts = orig_ghcopt ++ ["-package-conf", path] }
|
2011-11-01 22:06:53 +00:00
|
|
|
|
|
|
|
searchIt :: [FilePath] -> IO (Maybe FilePath)
|
|
|
|
searchIt [] = return Nothing
|
|
|
|
searchIt path = do
|
|
|
|
a <- doesDirectoryExist (mpath path)
|
2011-11-02 01:43:34 +00:00
|
|
|
if a then do
|
2011-11-24 11:43:15 +00:00
|
|
|
listToMaybe <$> find always (fileName ~~? "packages*.conf") (mpath path)
|
2011-11-02 01:43:34 +00:00
|
|
|
else
|
2011-11-24 11:43:15 +00:00
|
|
|
searchIt $ init path
|
2011-11-02 01:43:34 +00:00
|
|
|
where
|
2011-11-14 10:20:02 +00:00
|
|
|
mpath a = joinPath a </> "cabal-dev/"
|