Skip to content

Commit 30ed862

Browse files
committed
Fix #5203 Put GHCi configuration scripts in a user-specific location
1 parent d0e4260 commit 30ed862

File tree

7 files changed

+33
-23
lines changed

7 files changed

+33
-23
lines changed

ChangeLog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ Major changes:
1010

1111
Behavior changes:
1212

13+
* Use `$XDG_CACHE_HOME/stack/ghci-script`, rather than `<temp>/haskell-stack-ghci`
14+
(where `<temp>` is the directory yielded by the `temporary` package's
15+
`System.IO.Temp.getCanonicalTemporaryDirectory`), as the base location for
16+
GHCi script files generated by `stack ghci` or `stack repl`. See
17+
[#5203](https://github.com/commercialhaskell/stack/issues/5203)
18+
1319
Other enhancements:
1420

1521
Bug fixes:

doc/ghci.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ but not another is quite likely to cause failures. GHCi will be run with
2929
`-XNoImplicitPrelude`, but it is likely that modules in the other component
3030
assume that the `Prelude` is implicitly imported.
3131

32+
`stack ghci` configures GHCi by using a GHCi script file. Such files are located
33+
in subdirectories of `<XDG_CACHE_HOME>/stack/ghci-script`, where
34+
`<XDG_CACHE_HOME>` refers to the
35+
[XDG Base Directory Specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html)
36+
for user-specific non-essential (cached) data. On Unix-like operating systems,
37+
the default for `<XDG_CACHE_HOME>` is `$HOME/.cache`. On Windows, the default
38+
is `%LOCALAPPDATA%`.
39+
3240
## Selecting Main module
3341

3442
When loading multiple packages, there may be multiple definitions for the `Main`

package.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ dependencies:
125125
- streaming-commons
126126
- tar
127127
- template-haskell
128-
- temporary
129128
- text
130129
- text-metrics
131130
- th-reify-many

src/Stack/Constants.hs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ module Stack.Constants
4646
, relFileCabalMacrosH
4747
, relDirBuild
4848
, relDirBin
49+
, relDirGhci
50+
, relDirGhciScript
4951
, relDirPantry
5052
, relDirPrograms
5153
, relDirUpperPrograms
@@ -90,7 +92,6 @@ module Stack.Constants
9092
, relDirAll
9193
, relFilePackageCache
9294
, relFileDockerfile
93-
, relDirHaskellStackGhci
9495
, relFileGhciScript
9596
, relDirCombined
9697
, relFileHpcIndexHtml
@@ -365,6 +366,12 @@ relDirBuild = $(mkRelDir "build")
365366
relDirBin :: Path Rel Dir
366367
relDirBin = $(mkRelDir "bin")
367368

369+
relDirGhci :: Path Rel Dir
370+
relDirGhci = $(mkRelDir "ghci")
371+
372+
relDirGhciScript :: Path Rel Dir
373+
relDirGhciScript = $(mkRelDir "ghci-script")
374+
368375
relDirPantry :: Path Rel Dir
369376
relDirPantry = $(mkRelDir "pantry")
370377

@@ -501,9 +508,6 @@ relFilePackageCache = $(mkRelFile "package.cache")
501508
relFileDockerfile :: Path Rel File
502509
relFileDockerfile = $(mkRelFile "Dockerfile")
503510

504-
relDirHaskellStackGhci :: Path Rel Dir
505-
relDirHaskellStackGhci = $(mkRelDir "haskell-stack-ghci")
506-
507511
relFileGhciScript :: Path Rel File
508512
relFileGhciScript = $(mkRelFile "ghci-script")
509513

@@ -543,9 +547,6 @@ relDirUnderHome = $(mkRelDir "_home")
543547
relDirSrc :: Path Rel Dir
544548
relDirSrc = $(mkRelDir "src")
545549

546-
relDirStack :: Path Rel File
547-
relDirStack = $(mkRelFile "stack")
548-
549550
relFileLibtinfoSo5 :: Path Rel File
550551
relFileLibtinfoSo5 = $(mkRelFile "libtinfo.so.5")
551552

src/Stack/Constants/Config.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ module Stack.Constants.Config
2424
) where
2525

2626
import Path ( (</>), mkRelDir, mkRelFile, parseRelDir )
27-
import Stack.Constants ( cabalPackageName )
27+
import Stack.Constants
28+
( cabalPackageName, relDirDist, relDirGhci, relDirHpc )
2829
import Stack.Prelude
2930
import Stack.Types.BuildConfig ( HasBuildConfig, projectRootL )
3031
import Stack.Types.CompilerPaths ( cabalVersionL )
@@ -44,7 +45,7 @@ ghciDirL :: HasBuildConfig env => Getting r env (Path Abs Dir)
4445
ghciDirL = to $ \env -> -- FIXME is this idiomatic lens code?
4546
let workDir = view workDirL env
4647
root = view projectRootL env
47-
in root </> workDir </> $(mkRelDir "ghci/")
48+
in root </> workDir </> relDirGhci
4849

4950
-- | The directory containing the files used for dirtiness check of source files.
5051
buildCachesDir :: (MonadThrow m, MonadReader env m, HasEnvConfig env)
@@ -112,7 +113,7 @@ hpcDirFromDir fp =
112113
hpcRelativeDir :: (MonadThrow m, MonadReader env m, HasEnvConfig env)
113114
=> m (Path Rel Dir)
114115
hpcRelativeDir =
115-
fmap (</> $(mkRelDir "hpc")) distRelativeDir
116+
fmap (</> relDirHpc) distRelativeDir
116117

117118
-- | Package's setup-config storing Cabal configuration
118119
setupConfigFromDir :: (MonadThrow m, MonadReader env m, HasEnvConfig env)
@@ -145,7 +146,7 @@ rootDistRelativeDir ::
145146
=> m (Path Rel Dir)
146147
rootDistRelativeDir = do
147148
workDir <- view workDirL
148-
pure $ workDir </> $(mkRelDir "dist")
149+
pure $ workDir </> relDirDist
149150

150151
-- | Package's working directory.
151152
workDirFromDir :: (MonadReader env m, HasConfig env)

src/Stack/Ghci.hs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ import qualified Data.Text as T
2525
import qualified Data.Text.Lazy as TL
2626
import qualified Data.Text.Lazy.Encoding as TLE
2727
import qualified Distribution.PackageDescription as C
28-
import Path ((</>), parent, parseAbsDir, parseRelFile )
28+
import Path ((</>), parent, parseRelFile )
2929
import Path.Extra ( forgivingResolveFile', toFilePathNoTrailingSep )
30-
import Path.IO ( doesFileExist, ensureDir )
30+
import Path.IO
31+
( XdgDirectory (..), doesFileExist, ensureDir, getXdgDir )
3132
import RIO.Process
3233
( HasProcessContext, exec, proc, readProcess_
3334
, withWorkingDir
@@ -38,7 +39,7 @@ import Stack.Build.Source
3839
( getLocalFlags, localDependencies, projectLocalPackages )
3940
import Stack.Build.Target ( NeedTargets (..), parseTargets )
4041
import Stack.Constants
41-
( relDirHaskellStackGhci, relFileCabalMacrosH
42+
( relDirGhciScript, relDirStackProgName, relFileCabalMacrosH
4243
, relFileGhciScript, stackProgName'
4344
)
4445
import Stack.Constants.Config ( ghciDirL, objectInterfaceDirL )
@@ -85,7 +86,6 @@ import Stack.Types.SourceMap
8586
, SMTargets (..), SMWanted (..), SourceMap (..), Target (..)
8687
)
8788
import System.IO ( putStrLn )
88-
import System.IO.Temp ( getCanonicalTemporaryDirectory )
8989
import System.Permissions ( setScriptPerms )
9090

9191
-- | Type representing exceptions thrown by functions exported by the
@@ -566,9 +566,8 @@ runGhci GhciOpts{..} targets mainFile pkgs extraFiles exposePackages = do
566566
-- file names are determined by hashing. This also has the nice side
567567
-- effect of making it possible to copy the ghci invocation out of
568568
-- the log and have it still work.
569-
tmpDirectory <-
570-
(</> relDirHaskellStackGhci) <$>
571-
(parseAbsDir =<< liftIO getCanonicalTemporaryDirectory)
569+
tmpDirectory <- getXdgDir XdgCache $
570+
Just (relDirStackProgName </> relDirGhciScript)
572571
ghciDir <- view ghciDirL
573572
ensureDir ghciDir
574573
ensureDir tmpDirectory

stack.cabal

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,6 @@ library
389389
, streaming-commons
390390
, tar
391391
, template-haskell
392-
, temporary
393392
, text
394393
, text-metrics
395394
, th-reify-many
@@ -523,7 +522,6 @@ executable stack
523522
, streaming-commons
524523
, tar
525524
, template-haskell
526-
, temporary
527525
, text
528526
, text-metrics
529527
, th-reify-many
@@ -650,7 +648,6 @@ executable stack-integration-test
650648
, streaming-commons
651649
, tar
652650
, template-haskell
653-
, temporary
654651
, text
655652
, text-metrics
656653
, th-reify-many
@@ -785,7 +782,6 @@ test-suite stack-test
785782
, streaming-commons
786783
, tar
787784
, template-haskell
788-
, temporary
789785
, text
790786
, text-metrics
791787
, th-reify-many

0 commit comments

Comments
 (0)