{-# LANGUAGE RecordWildCards #-}

-- |
--
-- The layout of the .\/dist\/ directory where cabal keeps all of its state
-- and build artifacts.
module Distribution.Client.DistDirLayout
  ( -- * 'DistDirLayout'
    DistDirLayout (..)
  , DistDirParams (..)
  , defaultDistDirLayout

    -- * 'ProjectRoot'
  , ProjectRoot (..)
  , defaultProjectFile

    -- * 'StoreDirLayout'
  , StoreDirLayout (..)
  , defaultStoreDirLayout

    -- * 'CabalDirLayout'
  , CabalDirLayout (..)
  , mkCabalDirLayout
  , defaultCabalDirLayout
  ) where

import Distribution.Client.Compat.Prelude
import Prelude ()

import System.FilePath

import Distribution.Client.Config
  ( defaultLogsDir
  , defaultStoreDir
  )
import Distribution.Compiler
import Distribution.Package
  ( ComponentId
  , PackageId
  , PackageIdentifier
  , UnitId
  )
import Distribution.Simple.Compiler
  ( Compiler (..)
  , OptimisationLevel (..)
  , PackageDBCWD
  , PackageDBStackCWD
  , PackageDBX (..)
  )
import Distribution.Simple.Configure (interpretPackageDbFlags)
import Distribution.System
import Distribution.Types.ComponentName
import Distribution.Types.LibraryName

-- | Information which can be used to construct the path to
-- the build directory of a build.  This is LESS fine-grained
-- than what goes into the hashed 'InstalledPackageId',
-- and for good reason: we don't want this path to change if
-- the user, say, adds a dependency to their project.
data DistDirParams = DistDirParams
  { DistDirParams -> UnitId
distParamUnitId :: UnitId
  , DistDirParams -> PackageIdentifier
distParamPackageId :: PackageId
  , DistDirParams -> ComponentId
distParamComponentId :: ComponentId
  , DistDirParams -> Maybe ComponentName
distParamComponentName :: Maybe ComponentName
  , DistDirParams -> CompilerId
distParamCompilerId :: CompilerId
  , DistDirParams -> Platform
distParamPlatform :: Platform
  , DistDirParams -> OptimisationLevel
distParamOptimization :: OptimisationLevel
  -- TODO (see #3343):
  --  Flag assignments
  --  Optimization
  }

-- | The layout of the project state directory. Traditionally this has been
-- called the @dist@ directory.
data DistDirLayout = DistDirLayout
  { DistDirLayout -> [Char]
distProjectRootDirectory :: FilePath
  -- ^ The root directory of the project. Many other files are relative to
  -- this location (e.g. the @cabal.project@ file).
  , DistDirLayout -> [Char] -> [Char]
distProjectFile :: String -> FilePath
  -- ^ The @cabal.project@ file and related like @cabal.project.freeze@.
  -- The parameter is for the extension, like \"freeze\", or \"\" for the
  -- main file.
  , DistDirLayout -> [Char]
distDirectory :: FilePath
  -- ^ The \"dist\" directory, which is the root of where cabal keeps all
  -- its state including the build artifacts from each package we build.
  , DistDirLayout -> DistDirParams -> [Char]
distBuildDirectory :: DistDirParams -> FilePath
  -- ^ The directory under dist where we keep the build artifacts for a
  -- package we're building from a local directory.
  --
  -- This uses a 'UnitId' not just a 'PackageName' because technically
  -- we can have multiple instances of the same package in a solution
  -- (e.g. setup deps).
  , DistDirLayout -> [Char]
distBuildRootDirectory :: FilePath
  , DistDirLayout -> [Char]
distDownloadSrcDirectory :: FilePath
  -- ^ The directory under dist where we download tarballs and source
  -- control repos to.
  , DistDirLayout -> PackageIdentifier -> [Char]
distUnpackedSrcDirectory :: PackageId -> FilePath
  -- ^ The directory under dist where we put the unpacked sources of
  -- packages, in those cases where it makes sense to keep the build
  -- artifacts to reduce rebuild times.
  , DistDirLayout -> [Char]
distUnpackedSrcRootDirectory :: FilePath
  , DistDirLayout -> [Char] -> [Char]
distProjectCacheFile :: String -> FilePath
  -- ^ The location for project-wide cache files (e.g. state used in
  -- incremental rebuilds).
  , DistDirLayout -> [Char]
distProjectCacheDirectory :: FilePath
  , DistDirLayout -> DistDirParams -> [Char] -> [Char]
distPackageCacheFile :: DistDirParams -> String -> FilePath
  -- ^ The location for package-specific cache files (e.g. state used in
  -- incremental rebuilds).
  , DistDirLayout -> DistDirParams -> [Char]
distPackageCacheDirectory :: DistDirParams -> FilePath
  , DistDirLayout -> PackageIdentifier -> [Char]
distSdistFile :: PackageId -> FilePath
  -- ^ The location that sdists are placed by default.
  , DistDirLayout -> [Char]
distSdistDirectory :: FilePath
  , DistDirLayout -> [Char]
distTempDirectory :: FilePath
  , DistDirLayout -> [Char]
distBinDirectory :: FilePath
  , DistDirLayout -> CompilerId -> PackageDBCWD
distPackageDB :: CompilerId -> PackageDBCWD
  , DistDirLayout -> Maybe [Char]
distHaddockOutputDir :: Maybe FilePath
  -- ^ Is needed when `--haddock-output-dir` flag is used.
  }

-- | The layout of a cabal nix-style store.
data StoreDirLayout = StoreDirLayout
  { StoreDirLayout -> Compiler -> [Char]
storeDirectory :: Compiler -> FilePath
  , StoreDirLayout -> Compiler -> UnitId -> [Char]
storePackageDirectory :: Compiler -> UnitId -> FilePath
  , StoreDirLayout -> Compiler -> [Char]
storePackageDBPath :: Compiler -> FilePath
  , StoreDirLayout -> Compiler -> PackageDBCWD
storePackageDB :: Compiler -> PackageDBCWD
  , StoreDirLayout
-> Compiler -> [Maybe PackageDBCWD] -> PackageDBStackCWD
storePackageDBStack :: Compiler -> [Maybe PackageDBCWD] -> PackageDBStackCWD
  , StoreDirLayout -> Compiler -> [Char]
storeIncomingDirectory :: Compiler -> FilePath
  , StoreDirLayout -> Compiler -> UnitId -> [Char]
storeIncomingLock :: Compiler -> UnitId -> FilePath
  }

-- TODO: move to another module, e.g. CabalDirLayout?
-- or perhaps rename this module to DirLayouts.

-- | The layout of the user-wide cabal directory, that is the @~/.cabal@ dir
-- on unix, and equivalents on other systems.
--
-- At the moment this is just a partial specification, but the idea is
-- eventually to cover it all.
data CabalDirLayout = CabalDirLayout
  { CabalDirLayout -> StoreDirLayout
cabalStoreDirLayout :: StoreDirLayout
  , CabalDirLayout -> [Char]
cabalLogsDirectory :: FilePath
  }

-- | Information about the root directory of the project.
--
-- It can either be an implicit project root in the current dir if no
-- @cabal.project@ file is found, or an explicit root if either
-- the file is found or the project root directory was specified.
data ProjectRoot
  = -- | An implicit project root. It contains the absolute project
    -- root dir.
    ProjectRootImplicit FilePath
  | -- | An explicit project root. It contains the absolute project
    -- root dir and the relative @cabal.project@ file (or explicit override)
    ProjectRootExplicit FilePath FilePath
  | -- | An explicit, absolute project root dir and an explicit, absolute
    -- @cabal.project@ file.
    ProjectRootExplicitAbsolute FilePath FilePath
  deriving (ProjectRoot -> ProjectRoot -> Bool
(ProjectRoot -> ProjectRoot -> Bool)
-> (ProjectRoot -> ProjectRoot -> Bool) -> Eq ProjectRoot
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ProjectRoot -> ProjectRoot -> Bool
== :: ProjectRoot -> ProjectRoot -> Bool
$c/= :: ProjectRoot -> ProjectRoot -> Bool
/= :: ProjectRoot -> ProjectRoot -> Bool
Eq, Int -> ProjectRoot -> [Char] -> [Char]
[ProjectRoot] -> [Char] -> [Char]
ProjectRoot -> [Char]
(Int -> ProjectRoot -> [Char] -> [Char])
-> (ProjectRoot -> [Char])
-> ([ProjectRoot] -> [Char] -> [Char])
-> Show ProjectRoot
forall a.
(Int -> a -> [Char] -> [Char])
-> (a -> [Char]) -> ([a] -> [Char] -> [Char]) -> Show a
$cshowsPrec :: Int -> ProjectRoot -> [Char] -> [Char]
showsPrec :: Int -> ProjectRoot -> [Char] -> [Char]
$cshow :: ProjectRoot -> [Char]
show :: ProjectRoot -> [Char]
$cshowList :: [ProjectRoot] -> [Char] -> [Char]
showList :: [ProjectRoot] -> [Char] -> [Char]
Show)

defaultProjectFile :: FilePath
defaultProjectFile :: [Char]
defaultProjectFile = [Char]
"cabal.project"

-- | Make the default 'DistDirLayout' based on the project root dir and
-- optional overrides for the location of the @dist@ directory, the
-- @cabal.project@ file and the documentation directory.
defaultDistDirLayout
  :: ProjectRoot
  -- ^ the project root
  -> Maybe FilePath
  -- ^ the @dist@ directory (relative to package root)
  -> Maybe FilePath
  -- ^ the documentation directory
  -> DistDirLayout
defaultDistDirLayout :: ProjectRoot -> Maybe [Char] -> Maybe [Char] -> DistDirLayout
defaultDistDirLayout ProjectRoot
projectRoot Maybe [Char]
mdistDirectory Maybe [Char]
haddockOutputDir =
  DistDirLayout{[Char]
Maybe [Char]
[Char] -> [Char]
CompilerId -> PackageDBCWD
PackageIdentifier -> [Char]
DistDirParams -> [Char]
DistDirParams -> [Char] -> [Char]
distProjectRootDirectory :: [Char]
distProjectFile :: [Char] -> [Char]
distDirectory :: [Char]
distBuildDirectory :: DistDirParams -> [Char]
distBuildRootDirectory :: [Char]
distDownloadSrcDirectory :: [Char]
distUnpackedSrcDirectory :: PackageIdentifier -> [Char]
distUnpackedSrcRootDirectory :: [Char]
distProjectCacheFile :: [Char] -> [Char]
distProjectCacheDirectory :: [Char]
distPackageCacheFile :: DistDirParams -> [Char] -> [Char]
distPackageCacheDirectory :: DistDirParams -> [Char]
distSdistFile :: PackageIdentifier -> [Char]
distSdistDirectory :: [Char]
distTempDirectory :: [Char]
distBinDirectory :: [Char]
distPackageDB :: CompilerId -> PackageDBCWD
distHaddockOutputDir :: Maybe [Char]
distProjectRootDirectory :: [Char]
distProjectFile :: [Char] -> [Char]
distDirectory :: [Char]
distBuildRootDirectory :: [Char]
distBuildDirectory :: DistDirParams -> [Char]
distUnpackedSrcRootDirectory :: [Char]
distUnpackedSrcDirectory :: PackageIdentifier -> [Char]
distDownloadSrcDirectory :: [Char]
distProjectCacheDirectory :: [Char]
distProjectCacheFile :: [Char] -> [Char]
distPackageCacheDirectory :: DistDirParams -> [Char]
distPackageCacheFile :: DistDirParams -> [Char] -> [Char]
distSdistFile :: PackageIdentifier -> [Char]
distSdistDirectory :: [Char]
distTempDirectory :: [Char]
distBinDirectory :: [Char]
distPackageDB :: CompilerId -> PackageDBCWD
distHaddockOutputDir :: Maybe [Char]
..}
  where
    ([Char]
projectRootDir, [Char]
projectFile) = case ProjectRoot
projectRoot of
      ProjectRootImplicit [Char]
dir -> ([Char]
dir, [Char]
dir [Char] -> [Char] -> [Char]
</> [Char]
defaultProjectFile)
      ProjectRootExplicit [Char]
dir [Char]
file -> ([Char]
dir, [Char]
dir [Char] -> [Char] -> [Char]
</> [Char]
file)
      ProjectRootExplicitAbsolute [Char]
dir [Char]
file -> ([Char]
dir, [Char]
file)

    distProjectRootDirectory :: FilePath
    distProjectRootDirectory :: [Char]
distProjectRootDirectory = [Char]
projectRootDir

    distProjectFile :: String -> FilePath
    distProjectFile :: [Char] -> [Char]
distProjectFile [Char]
ext = [Char]
projectFile [Char] -> [Char] -> [Char]
<.> [Char]
ext

    distDirectory :: FilePath
    distDirectory :: [Char]
distDirectory =
      [Char]
distProjectRootDirectory
        [Char] -> [Char] -> [Char]
</> [Char] -> Maybe [Char] -> [Char]
forall a. a -> Maybe a -> a
fromMaybe [Char]
"dist-newstyle" Maybe [Char]
mdistDirectory
    -- TODO: switch to just dist at some point, or some other new name

    distBuildRootDirectory :: FilePath
    distBuildRootDirectory :: [Char]
distBuildRootDirectory = [Char]
distDirectory [Char] -> [Char] -> [Char]
</> [Char]
"build"

    distBuildDirectory :: DistDirParams -> FilePath
    distBuildDirectory :: DistDirParams -> [Char]
distBuildDirectory DistDirParams
params =
      [Char]
distBuildRootDirectory
        [Char] -> [Char] -> [Char]
</> Platform -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow (DistDirParams -> Platform
distParamPlatform DistDirParams
params)
        [Char] -> [Char] -> [Char]
</> CompilerId -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow (DistDirParams -> CompilerId
distParamCompilerId DistDirParams
params)
        [Char] -> [Char] -> [Char]
</> PackageIdentifier -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow (DistDirParams -> PackageIdentifier
distParamPackageId DistDirParams
params)
        [Char] -> [Char] -> [Char]
</> ( case DistDirParams -> Maybe ComponentName
distParamComponentName DistDirParams
params of
                Maybe ComponentName
Nothing -> [Char]
""
                Just (CLibName LibraryName
LMainLibName) -> [Char]
""
                Just (CLibName (LSubLibName UnqualComponentName
name)) -> [Char]
"l" [Char] -> [Char] -> [Char]
</> UnqualComponentName -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow UnqualComponentName
name
                Just (CFLibName UnqualComponentName
name) -> [Char]
"f" [Char] -> [Char] -> [Char]
</> UnqualComponentName -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow UnqualComponentName
name
                Just (CExeName UnqualComponentName
name) -> [Char]
"x" [Char] -> [Char] -> [Char]
</> UnqualComponentName -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow UnqualComponentName
name
                Just (CTestName UnqualComponentName
name) -> [Char]
"t" [Char] -> [Char] -> [Char]
</> UnqualComponentName -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow UnqualComponentName
name
                Just (CBenchName UnqualComponentName
name) -> [Char]
"b" [Char] -> [Char] -> [Char]
</> UnqualComponentName -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow UnqualComponentName
name
            )
        [Char] -> [Char] -> [Char]
</> ( case DistDirParams -> OptimisationLevel
distParamOptimization DistDirParams
params of
                OptimisationLevel
NoOptimisation -> [Char]
"noopt"
                OptimisationLevel
NormalOptimisation -> [Char]
""
                OptimisationLevel
MaximumOptimisation -> [Char]
"opt"
            )
        [Char] -> [Char] -> [Char]
</> ( let uid_str :: [Char]
uid_str = UnitId -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow (DistDirParams -> UnitId
distParamUnitId DistDirParams
params)
               in if [Char]
uid_str [Char] -> [Char] -> Bool
forall a. Eq a => a -> a -> Bool
== ComponentId -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow (DistDirParams -> ComponentId
distParamComponentId DistDirParams
params)
                    then [Char]
""
                    else [Char]
uid_str
            )

    distUnpackedSrcRootDirectory :: FilePath
    distUnpackedSrcRootDirectory :: [Char]
distUnpackedSrcRootDirectory = [Char]
distDirectory [Char] -> [Char] -> [Char]
</> [Char]
"src"

    distUnpackedSrcDirectory :: PackageId -> FilePath
    distUnpackedSrcDirectory :: PackageIdentifier -> [Char]
distUnpackedSrcDirectory PackageIdentifier
pkgid =
      [Char]
distUnpackedSrcRootDirectory
        [Char] -> [Char] -> [Char]
</> PackageIdentifier -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow PackageIdentifier
pkgid
    -- we shouldn't get name clashes so this should be fine:
    distDownloadSrcDirectory :: FilePath
    distDownloadSrcDirectory :: [Char]
distDownloadSrcDirectory = [Char]
distUnpackedSrcRootDirectory

    distProjectCacheDirectory :: FilePath
    distProjectCacheDirectory :: [Char]
distProjectCacheDirectory = [Char]
distDirectory [Char] -> [Char] -> [Char]
</> [Char]
"cache"

    distProjectCacheFile :: FilePath -> FilePath
    distProjectCacheFile :: [Char] -> [Char]
distProjectCacheFile [Char]
name = [Char]
distProjectCacheDirectory [Char] -> [Char] -> [Char]
</> [Char]
name

    distPackageCacheDirectory :: DistDirParams -> FilePath
    distPackageCacheDirectory :: DistDirParams -> [Char]
distPackageCacheDirectory DistDirParams
params = DistDirParams -> [Char]
distBuildDirectory DistDirParams
params [Char] -> [Char] -> [Char]
</> [Char]
"cache"

    distPackageCacheFile :: DistDirParams -> String -> FilePath
    distPackageCacheFile :: DistDirParams -> [Char] -> [Char]
distPackageCacheFile DistDirParams
params [Char]
name = DistDirParams -> [Char]
distPackageCacheDirectory DistDirParams
params [Char] -> [Char] -> [Char]
</> [Char]
name

    distSdistFile :: PackageIdentifier -> FilePath
    distSdistFile :: PackageIdentifier -> [Char]
distSdistFile PackageIdentifier
pid = [Char]
distSdistDirectory [Char] -> [Char] -> [Char]
</> PackageIdentifier -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow PackageIdentifier
pid [Char] -> [Char] -> [Char]
<.> [Char]
"tar.gz"

    distSdistDirectory :: FilePath
    distSdistDirectory :: [Char]
distSdistDirectory = [Char]
distDirectory [Char] -> [Char] -> [Char]
</> [Char]
"sdist"

    distTempDirectory :: FilePath
    distTempDirectory :: [Char]
distTempDirectory = [Char]
distDirectory [Char] -> [Char] -> [Char]
</> [Char]
"tmp"

    distBinDirectory :: FilePath
    distBinDirectory :: [Char]
distBinDirectory = [Char]
distDirectory [Char] -> [Char] -> [Char]
</> [Char]
"bin"

    distPackageDBPath :: CompilerId -> FilePath
    distPackageDBPath :: CompilerId -> [Char]
distPackageDBPath CompilerId
compid = [Char]
distDirectory [Char] -> [Char] -> [Char]
</> [Char]
"packagedb" [Char] -> [Char] -> [Char]
</> CompilerId -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow CompilerId
compid

    distPackageDB :: CompilerId -> PackageDBCWD
    distPackageDB :: CompilerId -> PackageDBCWD
distPackageDB = [Char] -> PackageDBCWD
forall fp. fp -> PackageDBX fp
SpecificPackageDB ([Char] -> PackageDBCWD)
-> (CompilerId -> [Char]) -> CompilerId -> PackageDBCWD
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CompilerId -> [Char]
distPackageDBPath

    distHaddockOutputDir :: Maybe FilePath
    distHaddockOutputDir :: Maybe [Char]
distHaddockOutputDir = Maybe [Char]
haddockOutputDir

defaultStoreDirLayout :: FilePath -> StoreDirLayout
defaultStoreDirLayout :: [Char] -> StoreDirLayout
defaultStoreDirLayout [Char]
storeRoot =
  StoreDirLayout{Compiler -> [Char]
Compiler -> PackageDBCWD
Compiler -> [Maybe PackageDBCWD] -> PackageDBStackCWD
Compiler -> UnitId -> [Char]
storeDirectory :: Compiler -> [Char]
storePackageDirectory :: Compiler -> UnitId -> [Char]
storePackageDBPath :: Compiler -> [Char]
storePackageDB :: Compiler -> PackageDBCWD
storePackageDBStack :: Compiler -> [Maybe PackageDBCWD] -> PackageDBStackCWD
storeIncomingDirectory :: Compiler -> [Char]
storeIncomingLock :: Compiler -> UnitId -> [Char]
storeDirectory :: Compiler -> [Char]
storePackageDirectory :: Compiler -> UnitId -> [Char]
storePackageDBPath :: Compiler -> [Char]
storePackageDB :: Compiler -> PackageDBCWD
storePackageDBStack :: Compiler -> [Maybe PackageDBCWD] -> PackageDBStackCWD
storeIncomingDirectory :: Compiler -> [Char]
storeIncomingLock :: Compiler -> UnitId -> [Char]
..}
  where
    storeDirectory :: Compiler -> FilePath
    storeDirectory :: Compiler -> [Char]
storeDirectory Compiler
compiler =
      [Char]
storeRoot [Char] -> [Char] -> [Char]
</> case Compiler -> AbiTag
compilerAbiTag Compiler
compiler of
        AbiTag
NoAbiTag -> CompilerId -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow (Compiler -> CompilerId
compilerId Compiler
compiler)
        AbiTag [Char]
tag -> CompilerId -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow (Compiler -> CompilerId
compilerId Compiler
compiler) [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> [Char]
"-" [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> [Char]
tag

    storePackageDirectory :: Compiler -> UnitId -> FilePath
    storePackageDirectory :: Compiler -> UnitId -> [Char]
storePackageDirectory Compiler
compiler UnitId
ipkgid =
      Compiler -> [Char]
storeDirectory Compiler
compiler [Char] -> [Char] -> [Char]
</> UnitId -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow UnitId
ipkgid

    storePackageDBPath :: Compiler -> FilePath
    storePackageDBPath :: Compiler -> [Char]
storePackageDBPath Compiler
compiler =
      Compiler -> [Char]
storeDirectory Compiler
compiler [Char] -> [Char] -> [Char]
</> [Char]
"package.db"

    storePackageDB :: Compiler -> PackageDBCWD
    storePackageDB :: Compiler -> PackageDBCWD
storePackageDB Compiler
compiler =
      [Char] -> PackageDBCWD
forall fp. fp -> PackageDBX fp
SpecificPackageDB (Compiler -> [Char]
storePackageDBPath Compiler
compiler)

    storePackageDBStack :: Compiler -> [Maybe PackageDBCWD] -> PackageDBStackCWD
    storePackageDBStack :: Compiler -> [Maybe PackageDBCWD] -> PackageDBStackCWD
storePackageDBStack Compiler
compiler [Maybe PackageDBCWD]
extraPackageDB =
      (Bool -> [Maybe PackageDBCWD] -> PackageDBStackCWD
forall fp. Bool -> [Maybe (PackageDBX fp)] -> PackageDBStackX fp
interpretPackageDbFlags Bool
False [Maybe PackageDBCWD]
extraPackageDB)
        PackageDBStackCWD -> PackageDBStackCWD -> PackageDBStackCWD
forall a. [a] -> [a] -> [a]
++ [Compiler -> PackageDBCWD
storePackageDB Compiler
compiler]

    storeIncomingDirectory :: Compiler -> FilePath
    storeIncomingDirectory :: Compiler -> [Char]
storeIncomingDirectory Compiler
compiler =
      Compiler -> [Char]
storeDirectory Compiler
compiler [Char] -> [Char] -> [Char]
</> [Char]
"incoming"

    storeIncomingLock :: Compiler -> UnitId -> FilePath
    storeIncomingLock :: Compiler -> UnitId -> [Char]
storeIncomingLock Compiler
compiler UnitId
unitid =
      Compiler -> [Char]
storeIncomingDirectory Compiler
compiler [Char] -> [Char] -> [Char]
</> UnitId -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow UnitId
unitid [Char] -> [Char] -> [Char]
<.> [Char]
"lock"

defaultCabalDirLayout :: IO CabalDirLayout
defaultCabalDirLayout :: IO CabalDirLayout
defaultCabalDirLayout =
  Maybe [Char] -> Maybe [Char] -> IO CabalDirLayout
mkCabalDirLayout Maybe [Char]
forall a. Maybe a
Nothing Maybe [Char]
forall a. Maybe a
Nothing

mkCabalDirLayout
  :: Maybe FilePath
  -- ^ Store directory. Must be absolute
  -> Maybe FilePath
  -- ^ Log directory
  -> IO CabalDirLayout
mkCabalDirLayout :: Maybe [Char] -> Maybe [Char] -> IO CabalDirLayout
mkCabalDirLayout Maybe [Char]
mstoreDir Maybe [Char]
mlogDir = do
  cabalStoreDirLayout <-
    [Char] -> StoreDirLayout
defaultStoreDirLayout ([Char] -> StoreDirLayout) -> IO [Char] -> IO StoreDirLayout
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IO [Char] -> ([Char] -> IO [Char]) -> Maybe [Char] -> IO [Char]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe IO [Char]
defaultStoreDir [Char] -> IO [Char]
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe [Char]
mstoreDir
  cabalLogsDirectory <-
    maybe defaultLogsDir pure mlogDir
  pure $ CabalDirLayout{..}