diff --git a/src/Stack/Config.hs b/src/Stack/Config.hs index 990183cae9..ef4b4434a0 100644 --- a/src/Stack/Config.hs +++ b/src/Stack/Config.hs @@ -529,10 +529,13 @@ 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 @@ -540,8 +543,8 @@ getProjectConfigDir = do 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 @@ -552,7 +555,7 @@ 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' @@ -560,20 +563,6 @@ getProjectConfigDir = do 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. @@ -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