Skip to content

Commit

Permalink
Revert "Additional helper to get project config dir"
Browse files Browse the repository at this point in the history
This reverts commit e324f19.
  • Loading branch information
Tristan Webb committed Nov 12, 2015
1 parent e324f19 commit f8d0129
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions src/Stack/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -529,19 +529,22 @@ loadYaml path = do
logJSONWarnings (toFilePath path) warnings
return result

-- | Get the parent directory the project config file, if it exists.
getProjectConfigDir :: (MonadIO m, MonadThrow m, MonadLogger m)
=> m (Maybe (Path Abs Dir))
getProjectConfigDir = do
-- | Get the location of the project config file, if it exists.
getProjectConfig :: (MonadIO m, MonadThrow m, MonadLogger m)
=> Maybe (Path Abs File)
-- ^ Override stack.yaml
-> m (Maybe (Path Abs File))
getProjectConfig (Just stackYaml) = return $ Just stackYaml
getProjectConfig Nothing = do
env <- liftIO getEnvironment
case lookup "STACK_YAML" env of
Just fp -> do
$logInfo "Getting project config file from STACK_YAML environment"
liftM Just $ case parseAbsFile fp of
Left _ -> do
currDir <- getWorkingDir
fmap parent (resolveFile currDir fp)
Right path -> return (parent path)
resolveFile currDir fp
Right path -> return path
Nothing -> do
currDir <- getWorkingDir
search currDir
Expand All @@ -552,28 +555,14 @@ getProjectConfigDir = do
$logDebug $ "Checking for project config at: " <> T.pack fp'
exists <- fileExists fp
if exists
then return $ Just dir
then return $ Just fp
else do
let dir' = parent dir
if dir == dir'
-- fully traversed, give up
then return Nothing
else search dir'

-- | Get the path of the project config file, if it exists.
getProjectConfigFile :: (MonadIO m, MonadThrow m, MonadLogger m)
=> Maybe (Path Abs File)
-- ^ Override stack.yaml
-> m (Maybe (Path Abs File))
getProjectConfigFile (Just stackYaml) = return $ Just stackYaml
getProjectConfigFile Nothing =
getProjectConfigDir >>= \case
Nothing ->
return Nothing
Just dir ->
return $
Just (dir </> stackDotYaml)

-- | Find the project config file location, respecting environment variables
-- and otherwise traversing parents. If no config is found, we supply a default
-- based on current directory.
Expand All @@ -582,7 +571,7 @@ loadProjectConfig :: (MonadIO m, MonadThrow m, MonadLogger m)
-- ^ Override stack.yaml
-> m (Maybe (Project, Path Abs File, ConfigMonoid))
loadProjectConfig mstackYaml = do
mfp <- getProjectConfigFile mstackYaml
mfp <- getProjectConfig mstackYaml
case mfp of
Just fp -> do
currDir <- getWorkingDir
Expand Down

0 comments on commit f8d0129

Please sign in to comment.