forked from commercialhaskell/stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.hs
More file actions
160 lines (143 loc) · 5.32 KB
/
Copy pathConfig.hs
File metadata and controls
160 lines (143 loc) · 5.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE OverloadedStrings #-}
module Stack.Constants.Config
( distDirFromDir
, rootDistDirFromDir
, workDirFromDir
, distRelativeDir
, imageStagingDir
, projectDockerSandboxDir
, configCabalMod
, buildCachesDir
, testSuccessFile
, testBuiltFile
, hpcRelativeDir
, hpcDirFromDir
, objectInterfaceDirL
, ghciDirL
, templatesDir
) where
import Stack.Prelude
import Stack.Constants
import Stack.Types.Compiler
import Stack.Types.Config
import Path
-- | Output .o/.hi directory.
objectInterfaceDirL :: HasBuildConfig env => Getting r env (Path Abs Dir)
objectInterfaceDirL = to $ \env -> -- FIXME is this idomatic lens code?
let workDir = view workDirL env
root = view projectRootL env
in root </> workDir </> $(mkRelDir "odir/")
-- | GHCi files directory.
ghciDirL :: HasBuildConfig env => Getting r env (Path Abs Dir)
ghciDirL = to $ \env -> -- FIXME is this idomatic lens code?
let workDir = view workDirL env
root = view projectRootL env
in root </> workDir </> $(mkRelDir "ghci/")
-- | The directory containing the files used for dirtiness check of source files.
buildCachesDir :: (MonadThrow m, MonadReader env m, HasEnvConfig env)
=> Path Abs Dir -- ^ Package directory.
-> m (Path Abs Dir)
buildCachesDir dir =
liftM
(</> $(mkRelDir "stack-build-caches"))
(distDirFromDir dir)
-- | The filename used to mark tests as having succeeded
testSuccessFile :: (MonadThrow m, MonadReader env m, HasEnvConfig env)
=> Path Abs Dir -- ^ Package directory
-> m (Path Abs File)
testSuccessFile dir =
liftM
(</> $(mkRelFile "stack-test-success"))
(distDirFromDir dir)
-- | The filename used to mark tests as having built
testBuiltFile :: (MonadThrow m, MonadReader env m, HasEnvConfig env)
=> Path Abs Dir -- ^ Package directory
-> m (Path Abs File)
testBuiltFile dir =
liftM
(</> $(mkRelFile "stack-test-built"))
(distDirFromDir dir)
-- | The filename used for modification check of .cabal
configCabalMod :: (MonadThrow m, MonadReader env m, HasEnvConfig env)
=> Path Abs Dir -- ^ Package directory.
-> m (Path Abs File)
configCabalMod dir =
liftM
(</> $(mkRelFile "stack-cabal-mod"))
(distDirFromDir dir)
-- | Directory for HPC work.
hpcDirFromDir
:: (MonadThrow m, MonadReader env m, HasEnvConfig env)
=> Path Abs Dir -- ^ Package directory.
-> m (Path Abs Dir)
hpcDirFromDir fp =
liftM (fp </>) hpcRelativeDir
-- | Relative location of directory for HPC work.
hpcRelativeDir :: (MonadThrow m, MonadReader env m, HasEnvConfig env)
=> m (Path Rel Dir)
hpcRelativeDir =
liftM (</> $(mkRelDir "hpc")) distRelativeDir
-- | Package's build artifacts directory.
distDirFromDir :: (MonadThrow m, MonadReader env m, HasEnvConfig env)
=> Path Abs Dir
-> m (Path Abs Dir)
distDirFromDir fp =
liftM (fp </>) distRelativeDir
-- | The directory containing all dist directories, including all
-- different GHC/Cabal combos.
rootDistDirFromDir
:: (MonadReader env m, HasConfig env)
=> Path Abs Dir
-> m (Path Abs Dir)
rootDistDirFromDir fp =
liftM (fp </>) rootDistRelativeDir
-- | Relative directory to the top dist directory, containing
-- individual GHC/Cabal combo as subdirs.
rootDistRelativeDir
:: (MonadReader env m, HasConfig env)
=> m (Path Rel Dir)
rootDistRelativeDir = do
workDir <- view workDirL
return $ workDir </> $(mkRelDir "dist")
-- | Package's working directory.
workDirFromDir :: (MonadReader env m, HasConfig env)
=> Path Abs Dir
-> m (Path Abs Dir)
workDirFromDir fp = view $ workDirL.to (fp </>)
-- | Directory for project templates.
templatesDir :: Config -> Path Abs Dir
templatesDir config = view stackRootL config </> $(mkRelDir "templates")
-- | Relative location of build artifacts.
distRelativeDir :: (MonadThrow m, MonadReader env m, HasEnvConfig env)
=> m (Path Rel Dir)
distRelativeDir = do
cabalPkgVer <- view cabalVersionL
platform <- platformGhcRelDir
wc <- view $ actualCompilerVersionL.to whichCompiler
-- Cabal version, suffixed with "_ghcjs" if we're using GHCJS.
envDir <-
parseRelDir $
(if wc == Ghcjs then (++ "_ghcjs") else id) $
packageIdentifierString $
PackageIdentifier cabalPackageName cabalPkgVer
platformAndCabal <- useShaPathOnWindows (platform </> envDir)
allDist <- rootDistRelativeDir
return $ allDist </> platformAndCabal
-- | Docker sandbox from project root.
projectDockerSandboxDir :: (MonadReader env m, HasConfig env)
=> Path Abs Dir -- ^ Project root
-> m (Path Abs Dir) -- ^ Docker sandbox
projectDockerSandboxDir projectRoot = do
workDir <- view workDirL
return $ projectRoot </> workDir </> $(mkRelDir "docker/")
-- | Image staging dir from project root.
imageStagingDir :: (MonadReader env m, HasConfig env, MonadThrow m)
=> Path Abs Dir -- ^ Project root
-> Int -- ^ Index of image
-> m (Path Abs Dir) -- ^ Docker sandbox
imageStagingDir projectRoot imageIdx = do
workDir <- view workDirL
idxRelDir <- parseRelDir (show imageIdx)
return $ projectRoot </> workDir </> $(mkRelDir "image") </> idxRelDir