Skip to content
This repository has been archived by the owner on Apr 25, 2020. It is now read-only.

Commit

Permalink
Add an ExplicitProject constructor, which reads options from a file
Browse files Browse the repository at this point in the history
  • Loading branch information
alang9 committed Sep 9, 2015
1 parent dbf215a commit 777fbd0
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Language/Haskell/GhcMod/Cradle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 = ""
}
1 change: 1 addition & 0 deletions Language/Haskell/GhcMod/GhcPkg.hs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ getPackageDbStack = do
getCabalPackageDbStack
StackProject ->
getStackPackageDbStack
ExplicitProject -> return []
return $ fromMaybe stack mCusPkgStack

getPackageCachePaths :: IOish m => FilePath -> GhcModT m [FilePath]
Expand Down
9 changes: 9 additions & 0 deletions Language/Haskell/GhcMod/PathsAndFiles.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
8 changes: 8 additions & 0 deletions Language/Haskell/GhcMod/Target.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Language/Haskell/GhcMod/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 777fbd0

Please sign in to comment.