{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE OverloadedStrings #-}
module Stack.Constants
(builtConfigFileFromDir
,builtFileFromDir
,buildPlanDir
,configuredFileFromDir
,defaultShakeThreads
,distDirFromDir
,distRelativeDir
,haskellModuleExts
,imageStagingDir
,projectDockerSandboxDir
,rawGithubUrl
,stackDotYaml
,stackRootEnvVar
,userDocsDir
,configCacheFile
,configCabalMod
,buildCacheFile
,testSuccessFile
,testBuiltFile
,benchBuiltFile
,stackProgName
,stackProgNameUpper
,wiredInPackages
,ghcjsBootPackages
,cabalPackageName
,implicitGlobalProjectDirDeprecated
,implicitGlobalProjectDir
,hpcRelativeDir
,hpcDirFromDir
,objectInterfaceDir
,templatesDir
,defaultUserConfigPathDeprecated
,defaultUserConfigPath
,defaultGlobalConfigPathDeprecated
,defaultGlobalConfigPath
,platformVariantEnvVar
)
where
import Control.Monad.Catch (MonadThrow)
import Control.Monad.Reader
import Data.Char (toUpper)
import Data.HashSet (HashSet)
import qualified Data.HashSet as HashSet
import Data.Text (Text)
import qualified Data.Text as T
import Path as FL
import Prelude
import Stack.Types.Compiler
import Stack.Types.Config
import Stack.Types.PackageIdentifier
import Stack.Types.PackageName
haskellModuleExts :: [Text]
haskellModuleExts = haskellFileExts ++ haskellPreprocessorExts
haskellFileExts :: [Text]
haskellFileExts = ["hs", "hsc", "lhs"]
haskellPreprocessorExts :: [Text]
haskellPreprocessorExts = ["gc", "chs", "hsc", "x", "y", "ly", "cpphs"]
builtFileFromDir :: (MonadThrow m, MonadReader env m, HasPlatform env,HasEnvConfig env)
=> Path Abs Dir
-> m (Path Abs File)
builtFileFromDir fp = do
dist <- distDirFromDir fp
return (dist </> $(mkRelFile "stack.gen"))
configuredFileFromDir :: (MonadThrow m, MonadReader env m, HasPlatform env,HasEnvConfig env)
=> Path Abs Dir
-> m (Path Abs File)
configuredFileFromDir fp = do
dist <- distDirFromDir fp
return (dist </> $(mkRelFile "setup-config"))
builtConfigFileFromDir :: (MonadThrow m, MonadReader env m, HasPlatform env,HasEnvConfig env)
=> Path Abs Dir
-> m (Path Abs File)
builtConfigFileFromDir fp =
liftM (fp </>) builtConfigRelativeFile
builtConfigRelativeFile :: (MonadThrow m, MonadReader env m, HasPlatform env,HasEnvConfig env)
=> m (Path Rel File)
builtConfigRelativeFile = do
dist <- distRelativeDir
return (dist </> $(mkRelFile "stack.config"))
defaultShakeThreads :: Int
defaultShakeThreads = 4
userDocsDir :: Config -> Path Abs Dir
userDocsDir config = configStackRoot config </> $(mkRelDir "doc/")
objectInterfaceDir :: (MonadReader env m, HasConfig env)
=> BuildConfig -> m (Path Abs Dir)
objectInterfaceDir bconfig = do
bcwd <- bcWorkDir bconfig
return (bcwd </> $(mkRelDir "odir/"))
buildCacheFile :: (MonadThrow m, MonadReader env m, HasPlatform env,HasEnvConfig env)
=> Path Abs Dir
-> m (Path Abs File)
buildCacheFile dir =
liftM
(</> $(mkRelFile "stack-build-cache"))
(distDirFromDir dir)
testSuccessFile :: (MonadThrow m, MonadReader env m, HasPlatform env,HasEnvConfig env)
=> Path Abs Dir
-> m (Path Abs File)
testSuccessFile dir =
liftM
(</> $(mkRelFile "stack-test-success"))
(distDirFromDir dir)
testBuiltFile :: (MonadThrow m, MonadReader env m, HasPlatform env,HasEnvConfig env)
=> Path Abs Dir
-> m (Path Abs File)
testBuiltFile dir =
liftM
(</> $(mkRelFile "stack-test-built"))
(distDirFromDir dir)
benchBuiltFile :: (MonadThrow m, MonadReader env m, HasPlatform env,HasEnvConfig env)
=> Path Abs Dir
-> m (Path Abs File)
benchBuiltFile dir =
liftM
(</> $(mkRelFile "stack-bench-built"))
(distDirFromDir dir)
configCacheFile :: (MonadThrow m, MonadReader env m, HasPlatform env,HasEnvConfig env)
=> Path Abs Dir
-> m (Path Abs File)
configCacheFile dir =
liftM
(</> $(mkRelFile "stack-config-cache"))
(distDirFromDir dir)
configCabalMod :: (MonadThrow m, MonadReader env m, HasPlatform env,HasEnvConfig env)
=> Path Abs Dir
-> m (Path Abs File)
configCabalMod dir =
liftM
(</> $(mkRelFile "stack-cabal-mod"))
(distDirFromDir dir)
hpcDirFromDir
:: (MonadThrow m, MonadReader env m, HasPlatform env, HasEnvConfig env)
=> Path Abs Dir
-> m (Path Abs Dir)
hpcDirFromDir fp =
liftM (fp </>) hpcRelativeDir
hpcRelativeDir :: (MonadThrow m, MonadReader env m, HasPlatform env, HasEnvConfig env)
=> m (Path Rel Dir)
hpcRelativeDir =
liftM (</> $(mkRelDir "hpc")) distRelativeDir
distDirFromDir :: (MonadThrow m, MonadReader env m, HasPlatform env, HasEnvConfig env)
=> Path Abs Dir
-> m (Path Abs Dir)
distDirFromDir fp =
liftM (fp </>) distRelativeDir
templatesDir :: Config -> Path Abs Dir
templatesDir config = configStackRoot config </> $(mkRelDir "templates")
distRelativeDir :: (MonadThrow m, MonadReader env m, HasPlatform env, HasEnvConfig env)
=> m (Path Rel Dir)
distRelativeDir = do
cabalPkgVer <- asks (envConfigCabalVersion . getEnvConfig)
platform <- platformGhcRelDir
wc <- getWhichCompiler
envDir <-
parseRelDir $
(if wc == Ghcjs then (++ "_ghcjs") else id) $
packageIdentifierString $
PackageIdentifier cabalPackageName cabalPkgVer
platformAndCabal <- useShaPathOnWindows (platform </> envDir)
workDir <- getWorkDir
return $
workDir </>
$(mkRelDir "dist") </>
platformAndCabal
rawGithubUrl :: Text
-> Text
-> Text
-> Text
-> Text
rawGithubUrl org repo branch file = T.concat
[ "https://raw.githubusercontent.com/"
, org
, "/"
, repo
, "/"
, branch
, "/"
, file
]
projectDockerSandboxDir :: (MonadReader env m, HasConfig env)
=> Path Abs Dir
-> m (Path Abs Dir)
projectDockerSandboxDir projectRoot = do
workDir <- getWorkDir
return $ projectRoot </> workDir </> $(mkRelDir "docker/")
imageStagingDir :: (MonadReader env m, HasConfig env)
=> Path Abs Dir
-> m (Path Abs Dir)
imageStagingDir projectRoot = do
workDir <- getWorkDir
return $ projectRoot </> workDir </> $(mkRelDir "image/")
stackProgNameUpper :: String
stackProgNameUpper = map toUpper stackProgName
stackProgName :: String
stackProgName = "stack"
stackDotYaml :: Path Rel File
stackDotYaml = $(mkRelFile "stack.yaml")
stackRootEnvVar :: String
stackRootEnvVar = "STACK_ROOT"
wiredInPackages :: HashSet PackageName
wiredInPackages =
maybe (error "Parse error in wiredInPackages") HashSet.fromList mparsed
where
mparsed = mapM parsePackageName
[ "ghc-prim"
, "integer-gmp"
, "integer-simple"
, "base"
, "rts"
, "template-haskell"
, "dph-seq"
, "dph-par"
, "ghc"
, "interactive"
]
ghcjsBootPackages :: HashSet PackageName
ghcjsBootPackages =
maybe (error "Parse error in ghcjsBootPackages") HashSet.fromList mparsed
where
mparsed = mapM parsePackageName
[ "array"
, "base"
, "binary"
, "bytestring"
, "containers"
, "deepseq"
, "integer-gmp"
, "pretty"
, "primitive"
, "integer-gmp"
, "pretty"
, "primitive"
, "template-haskell"
, "transformers"
, "directory"
, "filepath"
, "old-locale"
, "process"
, "time"
, "async"
, "aeson"
, "attoparsec"
, "case-insensitive"
, "dlist"
, "extensible-exceptions"
, "hashable"
, "mtl"
, "old-time"
, "parallel"
, "scientific"
, "stm"
, "syb"
, "text"
, "unordered-containers"
, "vector"
]
cabalPackageName :: PackageName
cabalPackageName =
$(mkPackageName "Cabal")
implicitGlobalProjectDirDeprecated :: Path Abs Dir
-> Path Abs Dir
implicitGlobalProjectDirDeprecated p =
p </>
$(mkRelDir "global")
implicitGlobalProjectDir :: Path Abs Dir
-> Path Abs Dir
implicitGlobalProjectDir p =
p </>
$(mkRelDir "global-project")
defaultUserConfigPathDeprecated :: Path Abs Dir -> Path Abs File
defaultUserConfigPathDeprecated = (</> $(mkRelFile "stack.yaml"))
defaultUserConfigPath :: Path Abs Dir -> Path Abs File
defaultUserConfigPath = (</> $(mkRelFile "config.yaml"))
defaultGlobalConfigPathDeprecated :: Maybe (Path Abs File)
defaultGlobalConfigPathDeprecated = parseAbsFile "/etc/stack/config"
defaultGlobalConfigPath :: Maybe (Path Abs File)
defaultGlobalConfigPath = parseAbsFile "/etc/stack/config.yaml"
buildPlanDir :: Path Abs Dir
-> Path Abs Dir
buildPlanDir = (</> $(mkRelDir "build-plan"))
platformVariantEnvVar :: String
platformVariantEnvVar = stackProgNameUpper ++ "_PLATFORM_VARIANT"