forked from commercialhaskell/stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConstants.hs
More file actions
562 lines (445 loc) · 15.8 KB
/
Constants.hs
File metadata and controls
562 lines (445 loc) · 15.8 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
{-# LANGUAGE CPP #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-} -- keep TH usage here
-- | Constants used throughout the project.
module Stack.Constants
(buildPlanDir
,buildPlanCacheDir
,haskellFileExts
,haskellPreprocessorExts
,stackDotYaml
,stackWorkEnvVar
,stackRootEnvVar
,stackRootOptionName
,deprecatedStackRootOptionName
,inContainerEnvVar
,inNixShellEnvVar
,stackProgNameUpper
,wiredInPackages
,cabalPackageName
,implicitGlobalProjectDirDeprecated
,implicitGlobalProjectDir
,defaultUserConfigPathDeprecated
,defaultUserConfigPath
,defaultGlobalConfigPathDeprecated
,defaultGlobalConfigPath
,platformVariantEnvVar
,compilerOptionsCabalFlag
,ghcColorForceFlag
,minTerminalWidth
,maxTerminalWidth
,defaultTerminalWidth
,osIsWindows
,relFileSetupHs
,relFileSetupLhs
,relFileHpackPackageConfig
,relDirGlobalAutogen
,relDirAutogen
,relDirLogs
,relFileCabalMacrosH
,relDirBuild
,relDirBin
,relDirPantry
,relDirPrograms
,relDirUpperPrograms
,relDirStackProgName
,relDirStackWork
,relFileReadmeTxt
,relDirScript
,relFileConfigYaml
,relDirSnapshots
,relDirGlobalHints
,relFileGlobalHintsYaml
,relDirInstall
,relDirCompilerTools
,relDirHoogle
,relFileDatabaseHoo
,relDirPkgdb
,relFileStorage
,relDirLoadedSnapshotCache
,bindirSuffix
,docDirSuffix
,relDirHpc
,relDirLib
,relDirShare
,relDirLibexec
,relDirEtc
,setupGhciShimCode
,relDirSetupExeCache
,relDirSetupExeSrc
,relFileConfigure
,relDirDist
,relFileSetupMacrosH
,relDirSetup
,relFileSetupLower
,relDirMingw
,relDirMingw32
,relDirMingw64
,relDirLocal
,relDirUsr
,relDirInclude
,relFileIndexHtml
,relDirAll
,relFilePackageCache
,relFileDockerfile
,relDirHaskellStackGhci
,relFileGhciScript
,relDirCombined
,relFileHpcIndexHtml
,relDirCustom
,relDirPackageConfInplace
,relDirExtraTixFiles
,relDirInstalledPackages
,backupUrlRelPath
,relDirDotLocal
,relDirDotSsh
,relDirDotStackProgName
,relDirUnderHome
,relDirSrc
,relFileLibtinfoSo5
,relFileLibtinfoSo6
,relFileLibncurseswSo6
,relFileLibgmpSo10
,relFileLibgmpSo3
,relDirNewCabal
,relFileSetupExe
,relFileSetupUpper
,relFile7zexe
,relFile7zdll
,relFileMainHs
,relFileStack
,relFileStackDotExe
,relFileStackDotTmpDotExe
,relFileStackDotTmp
,ghcShowOptionsOutput
,hadrianCmdWindows
,hadrianCmdPosix
,usrLibDirs
,testGhcEnvRelFile
,relFileBuildLock
,stackDeveloperModeDefault
)
where
import Data.ByteString.Builder (byteString)
import Data.Char (toUpper)
import Data.FileEmbed (embedFile, makeRelativeToProject)
import qualified Data.Set as Set
import Distribution.Package (mkPackageName)
import qualified Hpack.Config as Hpack
import qualified Language.Haskell.TH.Syntax as TH (runIO, lift)
import Path as FL
import Stack.Prelude
import Stack.Types.Compiler
import System.Permissions (osIsWindows)
import System.Process (readProcess)
-- | Extensions used for Haskell modules. Excludes preprocessor ones.
haskellFileExts :: [Text]
haskellFileExts = ["hs", "hsc", "lhs"]
-- | Extensions for modules that are preprocessed by common preprocessors.
haskellPreprocessorExts :: [Text]
haskellPreprocessorExts = ["gc", "chs", "hsc", "x", "y", "ly", "cpphs"]
-- | Name of the 'stack' program, uppercased
stackProgNameUpper :: String
stackProgNameUpper = map toUpper stackProgName
-- | The filename used for the stack config file.
stackDotYaml :: Path Rel File
stackDotYaml = $(mkRelFile "stack.yaml")
-- | Environment variable used to override the '.stack-work' relative dir.
stackWorkEnvVar :: String
stackWorkEnvVar = "STACK_WORK"
-- | Environment variable used to override the '~/.stack' location.
stackRootEnvVar :: String
stackRootEnvVar = "STACK_ROOT"
-- | Option name for the global stack root.
stackRootOptionName :: String
stackRootOptionName = "stack-root"
-- | Deprecated option name for the global stack root.
--
-- Deprecated since stack-1.1.0.
--
-- TODO: Remove occurrences of this variable and use 'stackRootOptionName' only
-- after an appropriate deprecation period.
deprecatedStackRootOptionName :: String
deprecatedStackRootOptionName = "global-stack-root"
-- | Environment variable used to indicate stack is running in container.
inContainerEnvVar :: String
inContainerEnvVar = stackProgNameUpper ++ "_IN_CONTAINER"
-- | Environment variable used to indicate stack is running in container.
-- although we already have STACK_IN_NIX_EXTRA_ARGS that is set in the same conditions,
-- it can happen that STACK_IN_NIX_EXTRA_ARGS is set to empty.
inNixShellEnvVar :: String
inNixShellEnvVar = map toUpper stackProgName ++ "_IN_NIX_SHELL"
-- See https://downloads.haskell.org/~ghc/7.10.1/docs/html/libraries/ghc/src/Module.html#integerPackageKey
wiredInPackages :: Set PackageName
wiredInPackages =
maybe (error "Parse error in wiredInPackages") Set.fromList mparsed
where
mparsed = mapM parsePackageName
[ "ghc-prim"
, "integer-gmp"
, "integer-simple"
, "base"
, "rts"
, "template-haskell"
, "dph-seq"
, "dph-par"
, "ghc"
, "interactive"
]
-- | Just to avoid repetition and magic strings.
cabalPackageName :: PackageName
cabalPackageName =
mkPackageName "Cabal"
-- | Deprecated implicit global project directory used when outside of a project.
implicitGlobalProjectDirDeprecated :: Path Abs Dir -- ^ Stack root.
-> Path Abs Dir
implicitGlobalProjectDirDeprecated p =
p </>
$(mkRelDir "global")
-- | Implicit global project directory used when outside of a project.
-- Normally, @getImplicitGlobalProjectDir@ should be used instead.
implicitGlobalProjectDir :: Path Abs Dir -- ^ Stack root.
-> Path Abs Dir
implicitGlobalProjectDir p =
p </>
$(mkRelDir "global-project")
-- | Deprecated default global config path.
defaultUserConfigPathDeprecated :: Path Abs Dir -> Path Abs File
defaultUserConfigPathDeprecated = (</> $(mkRelFile "stack.yaml"))
-- | Default global config path.
-- Normally, @getDefaultUserConfigPath@ should be used instead.
defaultUserConfigPath :: Path Abs Dir -> Path Abs File
defaultUserConfigPath = (</> $(mkRelFile "config.yaml"))
-- | Deprecated default global config path.
-- Note that this will be @Nothing@ on Windows, which is by design.
defaultGlobalConfigPathDeprecated :: Maybe (Path Abs File)
defaultGlobalConfigPathDeprecated = parseAbsFile "/etc/stack/config"
-- | Default global config path.
-- Normally, @getDefaultGlobalConfigPath@ should be used instead.
-- Note that this will be @Nothing@ on Windows, which is by design.
defaultGlobalConfigPath :: Maybe (Path Abs File)
defaultGlobalConfigPath = parseAbsFile "/etc/stack/config.yaml"
-- | Path where build plans are stored.
buildPlanDir :: Path Abs Dir -- ^ Stack root
-> Path Abs Dir
buildPlanDir = (</> $(mkRelDir "build-plan"))
-- | Path where binary caches of the build plans are stored.
buildPlanCacheDir
:: Path Abs Dir -- ^ Stack root
-> Path Abs Dir
buildPlanCacheDir = (</> $(mkRelDir "build-plan-cache"))
-- | Environment variable that stores a variant to append to platform-specific directory
-- names. Used to ensure incompatible binaries aren't shared between Docker builds and host
platformVariantEnvVar :: String
platformVariantEnvVar = stackProgNameUpper ++ "_PLATFORM_VARIANT"
-- | Provides --ghc-options for 'Ghc'
compilerOptionsCabalFlag :: WhichCompiler -> String
compilerOptionsCabalFlag Ghc = "--ghc-options"
-- | The flag to pass to GHC when we want to force its output to be
-- colorized.
ghcColorForceFlag :: String
ghcColorForceFlag = "-fdiagnostics-color=always"
-- | The minimum allowed terminal width. Used for pretty-printing.
minTerminalWidth :: Int
minTerminalWidth = 40
-- | The maximum allowed terminal width. Used for pretty-printing.
maxTerminalWidth :: Int
maxTerminalWidth = 200
-- | The default terminal width. Used for pretty-printing when we can't
-- automatically detect it and when the user doesn't supply one.
defaultTerminalWidth :: Int
defaultTerminalWidth = 100
relFileSetupHs :: Path Rel File
relFileSetupHs = $(mkRelFile "Setup.hs")
relFileSetupLhs :: Path Rel File
relFileSetupLhs = $(mkRelFile "Setup.lhs")
relFileHpackPackageConfig :: Path Rel File
relFileHpackPackageConfig = $(mkRelFile Hpack.packageConfig)
relDirGlobalAutogen :: Path Rel Dir
relDirGlobalAutogen = $(mkRelDir "global-autogen")
relDirAutogen :: Path Rel Dir
relDirAutogen = $(mkRelDir "autogen")
relDirLogs :: Path Rel Dir
relDirLogs = $(mkRelDir "logs")
relFileCabalMacrosH :: Path Rel File
relFileCabalMacrosH = $(mkRelFile "cabal_macros.h")
relDirBuild :: Path Rel Dir
relDirBuild = $(mkRelDir "build")
relDirBin :: Path Rel Dir
relDirBin = $(mkRelDir "bin")
relDirPantry :: Path Rel Dir
relDirPantry = $(mkRelDir "pantry")
relDirPrograms :: Path Rel Dir
relDirPrograms = $(mkRelDir "programs")
relDirUpperPrograms :: Path Rel Dir
relDirUpperPrograms = $(mkRelDir "Programs")
relDirStackProgName :: Path Rel Dir
relDirStackProgName = $(mkRelDir stackProgName)
relDirStackWork :: Path Rel Dir
relDirStackWork = $(mkRelDir ".stack-work")
relFileReadmeTxt :: Path Rel File
relFileReadmeTxt = $(mkRelFile "README.txt")
relDirScript :: Path Rel Dir
relDirScript = $(mkRelDir "script")
relFileConfigYaml :: Path Rel File
relFileConfigYaml = $(mkRelFile "config.yaml")
relDirSnapshots :: Path Rel Dir
relDirSnapshots = $(mkRelDir "snapshots")
relDirGlobalHints :: Path Rel Dir
relDirGlobalHints = $(mkRelDir "global-hints")
relFileGlobalHintsYaml :: Path Rel File
relFileGlobalHintsYaml = $(mkRelFile "global-hints.yaml")
relDirInstall :: Path Rel Dir
relDirInstall = $(mkRelDir "install")
relDirCompilerTools :: Path Rel Dir
relDirCompilerTools = $(mkRelDir "compiler-tools")
relDirHoogle :: Path Rel Dir
relDirHoogle = $(mkRelDir "hoogle")
relFileDatabaseHoo :: Path Rel File
relFileDatabaseHoo = $(mkRelFile "database.hoo")
relDirPkgdb :: Path Rel Dir
relDirPkgdb = $(mkRelDir "pkgdb")
relFileStorage :: Path Rel File
relFileStorage = $(mkRelFile "stack.sqlite3")
relDirLoadedSnapshotCache :: Path Rel Dir
relDirLoadedSnapshotCache = $(mkRelDir "loaded-snapshot-cached")
-- | Suffix applied to an installation root to get the bin dir
bindirSuffix :: Path Rel Dir
bindirSuffix = relDirBin
-- | Suffix applied to an installation root to get the doc dir
docDirSuffix :: Path Rel Dir
docDirSuffix = $(mkRelDir "doc")
relDirHpc :: Path Rel Dir
relDirHpc = $(mkRelDir "hpc")
relDirLib :: Path Rel Dir
relDirLib = $(mkRelDir "lib")
relDirShare :: Path Rel Dir
relDirShare = $(mkRelDir "share")
relDirLibexec :: Path Rel Dir
relDirLibexec = $(mkRelDir "libexec")
relDirEtc :: Path Rel Dir
relDirEtc = $(mkRelDir "etc")
setupGhciShimCode :: Builder
setupGhciShimCode = byteString $(do
path <- makeRelativeToProject "src/setup-shim/StackSetupShim.hs"
embedFile path)
relDirSetupExeCache :: Path Rel Dir
relDirSetupExeCache = $(mkRelDir "setup-exe-cache")
relDirSetupExeSrc :: Path Rel Dir
relDirSetupExeSrc = $(mkRelDir "setup-exe-src")
relFileConfigure :: Path Rel File
relFileConfigure = $(mkRelFile "configure")
relDirDist :: Path Rel Dir
relDirDist = $(mkRelDir "dist")
relFileSetupMacrosH :: Path Rel File
relFileSetupMacrosH = $(mkRelFile "setup_macros.h")
relDirSetup :: Path Rel Dir
relDirSetup = $(mkRelDir "setup")
relFileSetupLower :: Path Rel File
relFileSetupLower = $(mkRelFile "setup")
relDirMingw :: Path Rel Dir
relDirMingw = $(mkRelDir "mingw")
relDirMingw32 :: Path Rel Dir
relDirMingw32 = $(mkRelDir "mingw32")
relDirMingw64 :: Path Rel Dir
relDirMingw64 = $(mkRelDir "mingw64")
relDirLocal :: Path Rel Dir
relDirLocal = $(mkRelDir "local")
relDirUsr :: Path Rel Dir
relDirUsr = $(mkRelDir "usr")
relDirInclude :: Path Rel Dir
relDirInclude = $(mkRelDir "include")
relFileIndexHtml :: Path Rel File
relFileIndexHtml = $(mkRelFile "index.html")
relDirAll :: Path Rel Dir
relDirAll = $(mkRelDir "all")
relFilePackageCache :: Path Rel File
relFilePackageCache = $(mkRelFile "package.cache")
relFileDockerfile :: Path Rel File
relFileDockerfile = $(mkRelFile "Dockerfile")
relDirHaskellStackGhci :: Path Rel Dir
relDirHaskellStackGhci = $(mkRelDir "haskell-stack-ghci")
relFileGhciScript :: Path Rel File
relFileGhciScript = $(mkRelFile "ghci-script")
relDirCombined :: Path Rel Dir
relDirCombined = $(mkRelDir "combined")
relFileHpcIndexHtml :: Path Rel File
relFileHpcIndexHtml = $(mkRelFile "hpc_index.html")
relDirCustom :: Path Rel Dir
relDirCustom = $(mkRelDir "custom")
relDirPackageConfInplace :: Path Rel Dir
relDirPackageConfInplace = $(mkRelDir "package.conf.inplace")
relDirExtraTixFiles :: Path Rel Dir
relDirExtraTixFiles = $(mkRelDir "extra-tix-files")
relDirInstalledPackages :: Path Rel Dir
relDirInstalledPackages = $(mkRelDir "installed-packages")
backupUrlRelPath :: Path Rel File
backupUrlRelPath = $(mkRelFile "downloaded.template.file.hsfiles")
relDirDotLocal :: Path Rel Dir
relDirDotLocal = $(mkRelDir ".local")
relDirDotSsh :: Path Rel Dir
relDirDotSsh = $(mkRelDir ".ssh")
relDirDotStackProgName :: Path Rel Dir
relDirDotStackProgName = $(mkRelDir ('.' : stackProgName))
relDirUnderHome :: Path Rel Dir
relDirUnderHome = $(mkRelDir "_home")
relDirSrc :: Path Rel Dir
relDirSrc = $(mkRelDir "src")
relFileLibtinfoSo5 :: Path Rel File
relFileLibtinfoSo5 = $(mkRelFile "libtinfo.so.5")
relFileLibtinfoSo6 :: Path Rel File
relFileLibtinfoSo6 = $(mkRelFile "libtinfo.so.6")
relFileLibncurseswSo6 :: Path Rel File
relFileLibncurseswSo6 = $(mkRelFile "libncursesw.so.6")
relFileLibgmpSo10 :: Path Rel File
relFileLibgmpSo10 = $(mkRelFile "libgmp.so.10")
relFileLibgmpSo3 :: Path Rel File
relFileLibgmpSo3 = $(mkRelFile "libgmp.so.3")
relDirNewCabal :: Path Rel Dir
relDirNewCabal = $(mkRelDir "new-cabal")
relFileSetupExe :: Path Rel File
relFileSetupExe = $(mkRelFile "Setup.exe")
relFileSetupUpper :: Path Rel File
relFileSetupUpper = $(mkRelFile "Setup")
relFile7zexe :: Path Rel File
relFile7zexe = $(mkRelFile "7z.exe")
relFile7zdll :: Path Rel File
relFile7zdll = $(mkRelFile "7z.dll")
relFileMainHs :: Path Rel File
relFileMainHs = $(mkRelFile "Main.hs")
relFileStackDotExe :: Path Rel File
relFileStackDotExe = $(mkRelFile "stack.exe")
relFileStackDotTmpDotExe :: Path Rel File
relFileStackDotTmpDotExe = $(mkRelFile "stack.tmp.exe")
relFileStackDotTmp :: Path Rel File
relFileStackDotTmp = $(mkRelFile "stack.tmp")
relFileStack :: Path Rel File
relFileStack = $(mkRelFile "stack")
-- Technically, we should be consulting the user's current ghc,
-- but that would require loading up a BuildConfig.
ghcShowOptionsOutput :: [String]
ghcShowOptionsOutput =
$(TH.runIO (readProcess "ghc" ["--show-options"] "") >>= TH.lift . lines)
-- | Relative path inside a GHC repo to the Hadrian build batch script
hadrianCmdWindows :: Path Rel File
hadrianCmdWindows = $(mkRelFile "hadrian/build.stack.bat")
-- | Relative path inside a GHC repo to the Hadrian build shell script
hadrianCmdPosix :: Path Rel File
hadrianCmdPosix = $(mkRelFile "hadrian/build.stack.sh")
-- | Used in Stack.Setup for detecting libtinfo, see comments at use site
usrLibDirs :: [Path Abs Dir]
#if WINDOWS
usrLibDirs = []
#else
usrLibDirs = [$(mkAbsDir "/usr/lib"),$(mkAbsDir "/usr/lib64")]
#endif
-- | Relative file path for a temporary GHC environment file for tests
testGhcEnvRelFile :: Path Rel File
testGhcEnvRelFile = $(mkRelFile "test-ghc-env")
-- | File inside a dist directory to use for locking
relFileBuildLock :: Path Rel File
relFileBuildLock = $(mkRelFile "build-lock")
-- | What should the default be for stack-developer-mode
stackDeveloperModeDefault :: Bool
stackDeveloperModeDefault = STACK_DEVELOPER_MODE_DEFAULT