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-26 13:38:46 +00:00
|
|
|
import Data.List (find)
|
|
|
|
import System.FilePath (splitPath,joinPath,(</>))
|
2011-11-01 22:06:53 +00:00
|
|
|
import System.Directory
|
2011-11-26 13:38:46 +00:00
|
|
|
import Text.Regex.Posix ((=~))
|
2011-11-01 22:06:53 +00:00
|
|
|
|
|
|
|
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 =
|
2011-11-26 13:38:46 +00:00
|
|
|
getCurrentDirectory >>= searchIt . splitPath
|
2011-11-01 22:06:53 +00:00
|
|
|
|
|
|
|
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-26 13:38:46 +00:00
|
|
|
findConf (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/"
|
2011-11-26 13:38:46 +00:00
|
|
|
|
|
|
|
findConf :: FilePath -> IO (Maybe FilePath)
|
|
|
|
findConf path = do
|
|
|
|
f <- find (=~ "packages.*\\.conf") <$> getDirectoryContents path
|
|
|
|
return $ ((path </>) <$> f)
|