@@ -34,7 +34,7 @@ module Stack.Config
3434 , determineStackRootAndOwnership
3535 ) where
3636
37- import Control.Monad.Extra ( firstJustM , whenJust )
37+ import Control.Monad.Extra ( firstJustM )
3838import Data.Aeson.Types ( Value )
3939import Data.Aeson.WarningParser
4040 ( WithJSONWarnings (.. ), logJSONWarnings )
@@ -69,10 +69,10 @@ import Path
6969import Path.Extra ( toFilePathNoTrailingSep )
7070import Path.Find ( findInParents )
7171import Path.IO
72- ( XdgDirectory (.. ), canonicalizePath , doesDirExist
73- , doesFileExist , ensureDir , forgivingAbsence
74- , getAppUserDataDir , getCurrentDir , getXdgDir , resolveDir
75- , resolveDir' , resolveFile'
72+ ( XdgDirectory (.. ), canonicalizePath , doesFileExist
73+ , ensureDir , forgivingAbsence , getAppUserDataDir
74+ , getCurrentDir , getXdgDir , resolveDir , resolveDir'
75+ , resolveFile'
7676 )
7777import RIO.List ( unzip )
7878import RIO.Process
@@ -86,10 +86,8 @@ import Stack.Config.Build ( buildOptsFromMonoid )
8686import Stack.Config.Docker ( dockerOptsFromMonoid )
8787import Stack.Config.Nix ( nixOptsFromMonoid )
8888import Stack.Constants
89- ( defaultGlobalConfigPath , defaultGlobalConfigPathDeprecated
90- , defaultUserConfigPath , defaultUserConfigPathDeprecated
91- , implicitGlobalProjectDir
92- , implicitGlobalProjectDirDeprecated , inContainerEnvVar
89+ ( defaultGlobalConfigPath , defaultUserConfigPath
90+ , implicitGlobalProjectDir , inContainerEnvVar
9391 , inNixShellEnvVar , osIsWindows , pantryRootEnvVar
9492 , platformVariantEnvVar , relDirBin , relDirStackWork
9593 , relFileReadmeTxt , relFileStorage , relDirPantry
@@ -157,55 +155,9 @@ import System.Info.ShortPathName ( getShortPathName )
157155import System.PosixCompat.Files ( fileOwner , getFileStatus )
158156import System.Posix.User ( getEffectiveUserID )
159157
160- -- | If deprecated path exists, use it and print a warning. Otherwise, return
161- -- the new path.
162- tryDeprecatedPath ::
163- HasTerm env
164- => Maybe T. Text
165- -- ^ Description of file for warning (if Nothing, no deprecation warning is
166- -- displayed)
167- -> (Path Abs a -> RIO env Bool )
168- -- ^ Test for existence
169- -> Path Abs a
170- -- ^ New path
171- -> Path Abs a
172- -- ^ Deprecated path
173- -> RIO env (Path Abs a , Bool )
174- -- ^ (Path to use, whether it already exists)
175- tryDeprecatedPath mWarningDesc exists new old = do
176- newExists <- exists new
177- if newExists
178- then pure (new, True )
179- else do
180- oldExists <- exists old
181- if oldExists
182- then do
183- whenJust mWarningDesc $ \ desc ->
184- prettyWarnL
185- [ flow " Location of"
186- , flow (T. unpack desc)
187- , " at"
188- , style Dir (fromString $ toFilePath old)
189- , flow " is deprecated; rename it to"
190- , style Dir (fromString $ toFilePath new)
191- , " instead."
192- ]
193- pure (old, True )
194- else pure (new, False )
195-
196- -- | Get the location of the implicit global project directory. If the directory
197- -- already exists at the deprecated location, its location is returned.
198- -- Otherwise, the new location is returned.
199- getImplicitGlobalProjectDir :: HasTerm env => Config -> RIO env (Path Abs Dir )
200- getImplicitGlobalProjectDir config =
201- -- TEST no warning printed
202- fst <$> tryDeprecatedPath
203- Nothing
204- doesDirExist
205- (implicitGlobalProjectDir stackRoot)
206- (implicitGlobalProjectDirDeprecated stackRoot)
207- where
208- stackRoot = view stackRootL config
158+ -- | Get the location of the implicit global project directory.
159+ getImplicitGlobalProjectDir :: HasConfig env => RIO env (Path Abs Dir )
160+ getImplicitGlobalProjectDir = view $ stackRootL . to implicitGlobalProjectDir
209161
210162-- | Download the 'Snapshots' value from stackage.org.
211163getSnapshots :: HasConfig env => RIO env Snapshots
@@ -227,9 +179,7 @@ makeConcreteSnapshot as = do
227179 s <-
228180 case as of
229181 ASGlobal -> do
230- config <- view configL
231- implicitGlobalDir <- getImplicitGlobalProjectDir config
232- let fp = implicitGlobalDir </> stackDotYaml
182+ fp <- getImplicitGlobalProjectDir <&> (</> stackDotYaml)
233183 iopc <- loadConfigYaml (parseProjectAndConfigMonoid (parent fp)) fp
234184 ProjectAndConfigMonoid project _ <- liftIO iopc
235185 pure project. snapshot
@@ -785,7 +735,7 @@ withBuildConfig inner = do
785735 pure (p, Left config. userGlobalConfigFile)
786736 PCGlobalProject -> do
787737 logDebug " Run from outside a project, using implicit global project config"
788- destDir <- getImplicitGlobalProjectDir config
738+ destDir <- getImplicitGlobalProjectDir
789739 let dest :: Path Abs File
790740 dest = destDir </> stackDotYaml
791741 dest' :: FilePath
@@ -1134,19 +1084,17 @@ getInNixShell = liftIO (isJust <$> lookupEnv inNixShellEnvVar)
11341084getExtraConfigs :: HasTerm env
11351085 => Path Abs File -- ^ use config path
11361086 -> RIO env [Path Abs File ]
1137- getExtraConfigs userConfigPath = do
1138- defaultStackGlobalConfigPath <- getDefaultGlobalConfigPath
1139- liftIO $ do
1140- env <- getEnvironment
1141- mstackConfig <-
1142- maybe (pure Nothing ) (fmap Just . parseAbsFile)
1143- $ lookup " STACK_CONFIG" env
1144- mstackGlobalConfig <-
1145- maybe (pure Nothing ) (fmap Just . parseAbsFile)
1146- $ lookup " STACK_GLOBAL_CONFIG" env
1147- filterM doesFileExist
1148- $ fromMaybe userConfigPath mstackConfig
1149- : maybe [] pure (mstackGlobalConfig <|> defaultStackGlobalConfigPath)
1087+ getExtraConfigs userConfigPath = liftIO $ do
1088+ env <- getEnvironment
1089+ mstackConfig <-
1090+ maybe (pure Nothing ) (fmap Just . parseAbsFile)
1091+ $ lookup " STACK_CONFIG" env
1092+ mstackGlobalConfig <-
1093+ maybe (pure Nothing ) (fmap Just . parseAbsFile)
1094+ $ lookup " STACK_GLOBAL_CONFIG" env
1095+ filterM doesFileExist
1096+ $ fromMaybe userConfigPath mstackConfig
1097+ : maybe [] pure (mstackGlobalConfig <|> defaultGlobalConfigPath)
11501098
11511099-- | Load and parse YAML from the given config file. Throws
11521100-- 'ParseConfigFileException' when there's a decoding error.
@@ -1234,41 +1182,18 @@ loadProjectConfig mstackYaml = do
12341182 ProjectAndConfigMonoid project config <- liftIO iopc
12351183 pure (project, fp, config)
12361184
1237- -- | Get the location of the default Stack configuration file. If a file already
1238- -- exists at the deprecated location, its location is returned. Otherwise, the
1239- -- new location is returned.
1240- getDefaultGlobalConfigPath ::
1241- HasTerm env
1242- => RIO env (Maybe (Path Abs File ))
1243- getDefaultGlobalConfigPath =
1244- case (defaultGlobalConfigPath, defaultGlobalConfigPathDeprecated) of
1245- (Just new, Just old) ->
1246- Just . fst <$>
1247- tryDeprecatedPath
1248- (Just " non-project global configuration file" )
1249- doesFileExist
1250- new
1251- old
1252- (Just new,Nothing ) -> pure (Just new)
1253- _ -> pure Nothing
1254-
1255- -- | Get the location of the default user configuration file. If a file already
1256- -- exists at the deprecated location, its location is returned. Otherwise, the
1257- -- new location is returned.
1185+ -- | Get the location of the default user global configuration file.
12581186getDefaultUserConfigPath ::
12591187 HasTerm env
12601188 => Path Abs Dir
12611189 -> RIO env (Path Abs File )
1262- getDefaultUserConfigPath stackRoot = do
1263- (path, exists) <- tryDeprecatedPath
1264- (Just " non-project configuration file" )
1265- doesFileExist
1266- (defaultUserConfigPath stackRoot)
1267- (defaultUserConfigPathDeprecated stackRoot)
1268- unless exists $ do
1269- ensureDir (parent path)
1270- liftIO $ writeBinaryFileAtomic path defaultConfigYaml
1271- pure path
1190+ getDefaultUserConfigPath configRoot = do
1191+ let userConfigPath = defaultUserConfigPath configRoot
1192+ userConfigExists <- doesFileExist userConfigPath
1193+ unless userConfigExists $ do
1194+ ensureDir (parent userConfigPath)
1195+ liftIO $ writeBinaryFileAtomic userConfigPath defaultConfigYaml
1196+ pure userConfigPath
12721197
12731198packagesParser :: Parser [String ]
12741199packagesParser = many (strOption
0 commit comments