Skip to content

Commit 8e78b78

Browse files
authored
Merge pull request #6613 from commercialhaskell/fix6611
Fix #6611 Drop support for deprecated config locations
2 parents 88ac953 + 0f48343 commit 8e78b78

File tree

6 files changed

+51
-146
lines changed

6 files changed

+51
-146
lines changed

.stan.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,16 @@
177177

178178
# Anti-pattern: unsafe functions
179179
[[ignore]]
180-
id = "OBS-STAN-0212-5rtOmw-482:33"
180+
id = "OBS-STAN-0212-5rtOmw-460:33"
181181
# ✦ Description: Usage of unsafe functions breaks referential transparency
182182
# ✦ Category: #Unsafe #AntiPattern
183183
# ✦ File: src\Stack\Constants.hs
184184
#
185-
# 481
186-
# 482 ┃ setupGhciShimCode = byteString $(do
187-
# 483 ┃ path <- makeRelativeToProject "src/setup-shim/StackSetupShim.hs"
188-
# 484 ┃ embedFile path)
189-
# 485
185+
# 459
186+
# 460 ┃ setupGhciShimCode = byteString $(do
187+
# 461 ┃ path <- makeRelativeToProject "src/setup-shim/StackSetupShim.hs"
188+
# 462 ┃ embedFile path)
189+
# 463
190190

191191
# Anti-pattern: unsafe functions
192192
[[ignore]]

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ Behavior changes:
3333
of the compiler specified by the snapshot).
3434
* `stack build --flag *:[-]<flag_name>` now only applies the flag setting to
3535
packages for which the Cabal flag is defined, as opposed to all packages.
36+
* On Unix-like operating systems, drop support for `/etc/stack/config`,
37+
deprecated in Stack 0.1.6.0.
38+
* Drop support for, in the Stack root, directory `global` and file `stack.yaml`,
39+
both deprecated in Stack 0.1.6.0.
3640

3741
Other enhancements:
3842

src/Stack/Config.hs

Lines changed: 31 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -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 )
3838
import Data.Aeson.Types ( Value )
3939
import Data.Aeson.WarningParser
4040
( WithJSONWarnings (..), logJSONWarnings )
@@ -69,10 +69,10 @@ import Path
6969
import Path.Extra ( toFilePathNoTrailingSep )
7070
import Path.Find ( findInParents )
7171
import 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
)
7777
import RIO.List ( unzip )
7878
import RIO.Process
@@ -86,10 +86,8 @@ import Stack.Config.Build ( buildOptsFromMonoid )
8686
import Stack.Config.Docker ( dockerOptsFromMonoid )
8787
import Stack.Config.Nix ( nixOptsFromMonoid )
8888
import 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 )
157155
import System.PosixCompat.Files ( fileOwner, getFileStatus )
158156
import 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.
211163
getSnapshots :: 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)
11341084
getExtraConfigs :: 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.
12581186
getDefaultUserConfigPath ::
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

12731198
packagesParser :: Parser [String]
12741199
packagesParser = many (strOption

src/Stack/ConfigCmd.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ cfgCmdSet cmd = do
101101
mstackYaml <- getProjectConfig mstackYamlOption
102102
case mstackYaml of
103103
PCProject stackYaml -> pure stackYaml
104-
PCGlobalProject ->
105-
fmap (</> stackDotYaml) (getImplicitGlobalProjectDir conf)
104+
PCGlobalProject -> getImplicitGlobalProjectDir <&> (</> stackDotYaml)
106105
PCNoProject _extraDeps -> throwIO NoProjectConfigAvailable
107106
-- maybe modify the ~/.stack/config.yaml file instead?
108107
CommandScopeGlobal -> pure conf.userGlobalConfigFile

src/Stack/Constants.hs

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@ module Stack.Constants
2525
, stackProgNameUpper
2626
, wiredInPackages
2727
, cabalPackageName
28-
, implicitGlobalProjectDirDeprecated
2928
, implicitGlobalProjectDir
30-
, defaultUserConfigPathDeprecated
3129
, defaultUserConfigPath
32-
, defaultGlobalConfigPathDeprecated
3330
, defaultGlobalConfigPath
3431
, platformVariantEnvVar
3532
, compilerOptionsCabalFlag
@@ -285,38 +282,19 @@ cabalPackageName :: PackageName
285282
cabalPackageName =
286283
mkPackageName "Cabal"
287284

288-
-- | Deprecated implicit global project directory used when outside of a project.
289-
implicitGlobalProjectDirDeprecated :: Path Abs Dir -- ^ Stack root.
290-
-> Path Abs Dir
291-
implicitGlobalProjectDirDeprecated p =
292-
p </>
293-
$(mkRelDir "global")
294-
295285
-- | Implicit global project directory used when outside of a project.
296286
-- Normally, @getImplicitGlobalProjectDir@ should be used instead.
297-
implicitGlobalProjectDir :: Path Abs Dir -- ^ Stack root.
298-
-> Path Abs Dir
299-
implicitGlobalProjectDir p =
300-
p </>
301-
$(mkRelDir "global-project")
302-
303-
-- | Deprecated default global config path.
304-
defaultUserConfigPathDeprecated :: Path Abs Dir -> Path Abs File
305-
defaultUserConfigPathDeprecated = (</> $(mkRelFile "stack.yaml"))
306-
307-
-- | Default global config path.
308-
-- Normally, @getDefaultUserConfigPath@ should be used instead.
287+
implicitGlobalProjectDir ::
288+
Path Abs Dir -- ^ Stack root.
289+
-> Path Abs Dir
290+
implicitGlobalProjectDir p = p </> $(mkRelDir "global-project")
291+
292+
-- | Default user global configuration path. Normally,
293+
-- @getDefaultUserConfigPath@ should be used instead.
309294
defaultUserConfigPath :: Path Abs Dir -> Path Abs File
310295
defaultUserConfigPath = (</> $(mkRelFile "config.yaml"))
311296

312-
-- | Deprecated default global config path.
313-
-- Note that this will be @Nothing@ on Windows, which is by design.
314-
defaultGlobalConfigPathDeprecated :: Maybe (Path Abs File)
315-
defaultGlobalConfigPathDeprecated = parseAbsFile "/etc/stack/config"
316-
317-
-- | Default global config path.
318-
-- Normally, @getDefaultGlobalConfigPath@ should be used instead.
319-
-- Note that this will be @Nothing@ on Windows, which is by design.
297+
-- | Default global config path. On Windows, by design, this will be @Nothing@.
320298
defaultGlobalConfigPath :: Maybe (Path Abs File)
321299
defaultGlobalConfigPath = parseAbsFile "/etc/stack/config.yaml"
322300

src/Stack/Types/Build/Exception.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ import Distribution.Types.TestSuiteInterface ( TestSuiteInterface )
2727
import qualified Distribution.Version as C
2828
import RIO.NonEmpty ( nonEmpty )
2929
import RIO.Process ( showProcessArgDebug )
30-
import Stack.Constants
31-
( defaultUserConfigPath, wiredInPackages )
30+
import Stack.Constants ( defaultUserConfigPath, wiredInPackages )
3231
import Stack.Prelude
3332
import Stack.Types.Compiler ( ActualCompiler, compilerVersionString )
3433
import Stack.Types.CompilerBuild

0 commit comments

Comments
 (0)