From 777fbd0920d9b3927cb2c26c08e516d707f2d775 Mon Sep 17 00:00:00 2001 From: Alex Lang Date: Tue, 8 Sep 2015 16:52:27 -0700 Subject: [PATCH] Add an ExplicitProject constructor, which reads options from a file --- Language/Haskell/GhcMod/Cradle.hs | 13 +++++++++++++ Language/Haskell/GhcMod/GhcPkg.hs | 1 + Language/Haskell/GhcMod/PathsAndFiles.hs | 9 +++++++++ Language/Haskell/GhcMod/Target.hs | 8 ++++++++ Language/Haskell/GhcMod/Types.hs | 2 +- 5 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Language/Haskell/GhcMod/Cradle.hs b/Language/Haskell/GhcMod/Cradle.hs index aa2d08260..d2805def6 100644 --- a/Language/Haskell/GhcMod/Cradle.hs +++ b/Language/Haskell/GhcMod/Cradle.hs @@ -37,6 +37,7 @@ findCradle' dir = run $ msum [ stackCradle dir , cabalCradle dir , sandboxCradle dir + , explicitCradle dir , plainCradle dir ] where run a = fillTempDir =<< (fromJust <$> runMaybeT a) @@ -122,3 +123,15 @@ plainCradle wdir = do , cradleCabalFile = Nothing , cradleDistDir = "dist" } + +explicitCradle :: IOish m => FilePath -> MaybeT m Cradle +explicitCradle wdir = do + optionsFile <- MaybeT $ liftIO $ findExplicitOptionsFile wdir + return $ Cradle { + cradleProjectType = ExplicitProject + , cradleCurrentDir = wdir + , cradleRootDir = takeDirectory optionsFile + , cradleTempDir = error "tmpDir" + , cradleCabalFile = Just optionsFile + , cradleDistDir = "" + } diff --git a/Language/Haskell/GhcMod/GhcPkg.hs b/Language/Haskell/GhcMod/GhcPkg.hs index ef06b0926..f3239997e 100644 --- a/Language/Haskell/GhcMod/GhcPkg.hs +++ b/Language/Haskell/GhcMod/GhcPkg.hs @@ -87,6 +87,7 @@ getPackageDbStack = do getCabalPackageDbStack StackProject -> getStackPackageDbStack + ExplicitProject -> return [] return $ fromMaybe stack mCusPkgStack getPackageCachePaths :: IOish m => FilePath -> GhcModT m [FilePath] diff --git a/Language/Haskell/GhcMod/PathsAndFiles.hs b/Language/Haskell/GhcMod/PathsAndFiles.hs index 228cc87d6..ec56fb186 100644 --- a/Language/Haskell/GhcMod/PathsAndFiles.hs +++ b/Language/Haskell/GhcMod/PathsAndFiles.hs @@ -85,6 +85,15 @@ findStackConfigFile dir = do Just (d, Just a) -> return $ Just $ d a Just (_, Nothing) -> error "findStackConfigFile" +findExplicitOptionsFile :: FilePath -> IO (Maybe FilePath) +findExplicitOptionsFile dir = do + dss <- findFileInParentsP (==explicitOptionsFile) dir + return $ case find (not . null . snd) $ dss of + Just (expDir, _:_) -> Just (expDir explicitOptionsFile) + _ -> Nothing + where + explicitOptionsFile = "ghc-mod.options" + getStackDistDir :: (IOish m, GmOut m) => FilePath -> m (Maybe FilePath) getStackDistDir projdir = U.withDirectory_ projdir $ runMaybeT $ do takeWhile (/='\n') <$> readStack ["path", "--dist-dir"] diff --git a/Language/Haskell/GhcMod/Target.hs b/Language/Haskell/GhcMod/Target.hs index 428b7768d..51ef133cc 100644 --- a/Language/Haskell/GhcMod/Target.hs +++ b/Language/Haskell/GhcMod/Target.hs @@ -151,10 +151,18 @@ targetGhcOptions crdl sefnmn = do case cradleProjectType crdl of CabalProject -> cabalOpts crdl StackProject -> cabalOpts crdl + ExplicitProject -> explicitOpts crdl _ -> sandboxOpts crdl where zipMap f l = l `zip` (f `map` l) + explicitOpts :: Cradle -> GhcModT m [String] + explicitOpts Cradle {..} = case cradleCabalFile of + Nothing -> return [] + Just optionsFile -> do + contents <- liftIO $ readFile optionsFile + return $ lines contents + cabalOpts :: Cradle -> GhcModT m [String] cabalOpts Cradle{..} = do mcs <- cabalResolvedComponents diff --git a/Language/Haskell/GhcMod/Types.hs b/Language/Haskell/GhcMod/Types.hs index 3043011dd..179ff9deb 100644 --- a/Language/Haskell/GhcMod/Types.hs +++ b/Language/Haskell/GhcMod/Types.hs @@ -139,7 +139,7 @@ defaultOptions = Options { ---------------------------------------------------------------- -data ProjectType = CabalProject | SandboxProject | PlainProject | StackProject +data ProjectType = CabalProject | SandboxProject | PlainProject | StackProject | ExplicitProject deriving (Eq, Show) -- | The environment where this library is used.