{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell   #-}

module Stack.Constants.Config
  ( buildCachesDir
  , configCabalMod
  , configPackageProjectRoot
  , configSetupConfigMod
  , distDirFromDir
  , distRelativeDir
  , ghciDirL
  , hpcDirFromDir
  , hpcRelativeDir
  , imageStagingDir
  , objectInterfaceDirL
  , projectDockerSandboxDir
  , rootDistDirFromDir
  , setupConfigFromDir
  , templatesDir
  , testBuiltFile
  , testSuccessFile
  , workDirFromDir
  ) where

import           Path ( (</>), mkRelDir, mkRelFile, parseRelDir )
import           Stack.Constants ( relDirDist, relDirGhci, relDirHpc )
import           Stack.Prelude
import           Stack.Types.BuildConfig ( HasBuildConfig, projectRootL )
import           Stack.Types.Compiler ( compilerVersionString )
import           Stack.Types.CompilerPaths ( compilerVersionL )
import           Stack.Types.Config ( Config, HasConfig, stackRootL, workDirL )
import           Stack.Types.EnvConfig
                   ( HasEnvConfig, platformGhcRelDir, useShaPathOnWindows )

-- | Output .o/.hi directory.

objectInterfaceDirL :: HasBuildConfig env => Getting r env (Path Abs Dir)
objectInterfaceDirL :: forall env r. HasBuildConfig env => Getting r env (Path Abs Dir)
objectInterfaceDirL = (env -> Path Abs Dir) -> SimpleGetter env (Path Abs Dir)
forall s a. (s -> a) -> SimpleGetter s a
to ((env -> Path Abs Dir) -> SimpleGetter env (Path Abs Dir))
-> (env -> Path Abs Dir) -> SimpleGetter env (Path Abs Dir)
forall a b. (a -> b) -> a -> b
$ \env
env -> -- FIXME is this idiomatic lens code?

  let workDir :: Path Rel Dir
workDir = Getting (Path Rel Dir) env (Path Rel Dir) -> env -> Path Rel Dir
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting (Path Rel Dir) env (Path Rel Dir)
forall env. HasConfig env => Lens' env (Path Rel Dir)
Lens' env (Path Rel Dir)
workDirL env
env
      root :: Path Abs Dir
root = Getting (Path Abs Dir) env (Path Abs Dir) -> env -> Path Abs Dir
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting (Path Abs Dir) env (Path Abs Dir)
forall env r. HasBuildConfig env => Getting r env (Path Abs Dir)
projectRootL env
env
  in  Path Abs Dir
root Path Abs Dir -> Path Rel Dir -> Path Abs Dir
forall b t. Path b Dir -> Path Rel t -> Path b t
</> Path Rel Dir
workDir Path Rel Dir -> Path Rel Dir -> Path Rel Dir
forall b t. Path b Dir -> Path Rel t -> Path b t
</> $(mkRelDir "odir/")

-- | GHCi files directory.

ghciDirL :: HasBuildConfig env => Getting r env (Path Abs Dir)
ghciDirL :: forall env r. HasBuildConfig env => Getting r env (Path Abs Dir)
ghciDirL = (env -> Path Abs Dir) -> SimpleGetter env (Path Abs Dir)
forall s a. (s -> a) -> SimpleGetter s a
to ((env -> Path Abs Dir) -> SimpleGetter env (Path Abs Dir))
-> (env -> Path Abs Dir) -> SimpleGetter env (Path Abs Dir)
forall a b. (a -> b) -> a -> b
$ \env
env -> -- FIXME is this idiomatic lens code?

  let workDir :: Path Rel Dir
workDir = Getting (Path Rel Dir) env (Path Rel Dir) -> env -> Path Rel Dir
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting (Path Rel Dir) env (Path Rel Dir)
forall env. HasConfig env => Lens' env (Path Rel Dir)
Lens' env (Path Rel Dir)
workDirL env
env
      root :: Path Abs Dir
root = Getting (Path Abs Dir) env (Path Abs Dir) -> env -> Path Abs Dir
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting (Path Abs Dir) env (Path Abs Dir)
forall env r. HasBuildConfig env => Getting r env (Path Abs Dir)
projectRootL env
env
  in  Path Abs Dir
root Path Abs Dir -> Path Rel Dir -> Path Abs Dir
forall b t. Path b Dir -> Path Rel t -> Path b t
</> Path Rel Dir
workDir Path Rel Dir -> Path Rel Dir -> Path Rel Dir
forall b t. Path b Dir -> Path Rel t -> Path b t
</> Path Rel Dir
relDirGhci

-- | The directory containing the files used for dirtiness check of source

-- files.

buildCachesDir ::
     (HasEnvConfig env, MonadReader env m, MonadThrow m)
  => Path Abs Dir  -- ^ Package directory.

  -> m (Path Abs Dir)
buildCachesDir :: forall env (m :: * -> *).
(HasEnvConfig env, MonadReader env m, MonadThrow m) =>
Path Abs Dir -> m (Path Abs Dir)
buildCachesDir Path Abs Dir
dir =
  (Path Abs Dir -> Path Abs Dir)
-> m (Path Abs Dir) -> m (Path Abs Dir)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
    (Path Abs Dir -> Path Rel Dir -> Path Abs Dir
forall b t. Path b Dir -> Path Rel t -> Path b t
</> $(mkRelDir "stack-build-caches"))
    (Path Abs Dir -> m (Path Abs Dir)
forall env (m :: * -> *).
(HasEnvConfig env, MonadReader env m, MonadThrow m) =>
Path Abs Dir -> m (Path Abs Dir)
distDirFromDir Path Abs Dir
dir)

-- | The filename used to mark tests as having succeeded.

testSuccessFile ::
     (HasEnvConfig env, MonadReader env m, MonadThrow m)
  => Path Abs Dir  -- ^ Package directory

  -> m (Path Abs File)
testSuccessFile :: forall env (m :: * -> *).
(HasEnvConfig env, MonadReader env m, MonadThrow m) =>
Path Abs Dir -> m (Path Abs File)
testSuccessFile Path Abs Dir
dir =
  (Path Abs Dir -> Path Abs File)
-> m (Path Abs Dir) -> m (Path Abs File)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
    (Path Abs Dir -> Path Rel File -> Path Abs File
forall b t. Path b Dir -> Path Rel t -> Path b t
</> $(mkRelFile "stack-test-success"))
    (Path Abs Dir -> m (Path Abs Dir)
forall env (m :: * -> *).
(HasEnvConfig env, MonadReader env m, MonadThrow m) =>
Path Abs Dir -> m (Path Abs Dir)
distDirFromDir Path Abs Dir
dir)

-- | The filename used to mark tests as having built.

testBuiltFile ::
     (HasEnvConfig env, MonadReader env m, MonadThrow m)
  => Path Abs Dir  -- ^ Package directory

  -> m (Path Abs File)
testBuiltFile :: forall env (m :: * -> *).
(HasEnvConfig env, MonadReader env m, MonadThrow m) =>
Path Abs Dir -> m (Path Abs File)
testBuiltFile Path Abs Dir
dir =
  (Path Abs Dir -> Path Abs File)
-> m (Path Abs Dir) -> m (Path Abs File)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
    (Path Abs Dir -> Path Rel File -> Path Abs File
forall b t. Path b Dir -> Path Rel t -> Path b t
</> $(mkRelFile "stack-test-built"))
    (Path Abs Dir -> m (Path Abs Dir)
forall env (m :: * -> *).
(HasEnvConfig env, MonadReader env m, MonadThrow m) =>
Path Abs Dir -> m (Path Abs Dir)
distDirFromDir Path Abs Dir
dir)

-- | The filename used for modification check of a Cabal file.

configCabalMod ::
     (HasEnvConfig env, MonadReader env m, MonadThrow m)
  => Path Abs Dir  -- ^ Package directory.

  -> m (Path Abs File)
configCabalMod :: forall env (m :: * -> *).
(HasEnvConfig env, MonadReader env m, MonadThrow m) =>
Path Abs Dir -> m (Path Abs File)
configCabalMod Path Abs Dir
dir =
  (Path Abs Dir -> Path Abs File)
-> m (Path Abs Dir) -> m (Path Abs File)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
    (Path Abs Dir -> Path Rel File -> Path Abs File
forall b t. Path b Dir -> Path Rel t -> Path b t
</> $(mkRelFile "stack-cabal-mod"))
    (Path Abs Dir -> m (Path Abs Dir)
forall env (m :: * -> *).
(HasEnvConfig env, MonadReader env m, MonadThrow m) =>
Path Abs Dir -> m (Path Abs Dir)
distDirFromDir Path Abs Dir
dir)

-- | The filename used for modification check of setup-config.

configSetupConfigMod ::
     (HasEnvConfig env, MonadReader env m, MonadThrow m)
  => Path Abs Dir  -- ^ Package directory.

  -> m (Path Abs File)
configSetupConfigMod :: forall env (m :: * -> *).
(HasEnvConfig env, MonadReader env m, MonadThrow m) =>
Path Abs Dir -> m (Path Abs File)
configSetupConfigMod Path Abs Dir
dir =
  (Path Abs Dir -> Path Abs File)
-> m (Path Abs Dir) -> m (Path Abs File)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
    (Path Abs Dir -> Path Rel File -> Path Abs File
forall b t. Path b Dir -> Path Rel t -> Path b t
</> $(mkRelFile "stack-setup-config-mod"))
    (Path Abs Dir -> m (Path Abs Dir)
forall env (m :: * -> *).
(HasEnvConfig env, MonadReader env m, MonadThrow m) =>
Path Abs Dir -> m (Path Abs Dir)
distDirFromDir Path Abs Dir
dir)

-- | The filename used for the project root from the last build of a package.

configPackageProjectRoot ::
     (HasEnvConfig env, MonadReader env m, MonadThrow m)
  => Path Abs Dir  -- ^ Package directory.

  -> m (Path Abs File)
configPackageProjectRoot :: forall env (m :: * -> *).
(HasEnvConfig env, MonadReader env m, MonadThrow m) =>
Path Abs Dir -> m (Path Abs File)
configPackageProjectRoot Path Abs Dir
dir =
  (Path Abs Dir -> Path Abs File)
-> m (Path Abs Dir) -> m (Path Abs File)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
    (Path Abs Dir -> Path Rel File -> Path Abs File
forall b t. Path b Dir -> Path Rel t -> Path b t
</> $(mkRelFile "stack-project-root"))
    (Path Abs Dir -> m (Path Abs Dir)
forall env (m :: * -> *).
(HasEnvConfig env, MonadReader env m, MonadThrow m) =>
Path Abs Dir -> m (Path Abs Dir)
distDirFromDir Path Abs Dir
dir)

-- | Directory for HPC work.

hpcDirFromDir ::
     (HasEnvConfig env, MonadReader env m, MonadThrow m)
  => Path Abs Dir  -- ^ Package directory.

  -> m (Path Abs Dir)
hpcDirFromDir :: forall env (m :: * -> *).
(HasEnvConfig env, MonadReader env m, MonadThrow m) =>
Path Abs Dir -> m (Path Abs Dir)
hpcDirFromDir Path Abs Dir
fp =
  (Path Rel Dir -> Path Abs Dir)
-> m (Path Rel Dir) -> m (Path Abs Dir)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Path Abs Dir
fp </>) m (Path Rel Dir)
forall env (m :: * -> *).
(HasEnvConfig env, MonadReader env m, MonadThrow m) =>
m (Path Rel Dir)
hpcRelativeDir

-- | Relative location of directory for HPC work.

hpcRelativeDir ::
     (HasEnvConfig env, MonadReader env m, MonadThrow m)
  => m (Path Rel Dir)
hpcRelativeDir :: forall env (m :: * -> *).
(HasEnvConfig env, MonadReader env m, MonadThrow m) =>
m (Path Rel Dir)
hpcRelativeDir =
  (Path Rel Dir -> Path Rel Dir)
-> m (Path Rel Dir) -> m (Path Rel Dir)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Path Rel Dir -> Path Rel Dir -> Path Rel Dir
forall b t. Path b Dir -> Path Rel t -> Path b t
</> Path Rel Dir
relDirHpc) m (Path Rel Dir)
forall env (m :: * -> *).
(HasEnvConfig env, MonadReader env m, MonadThrow m) =>
m (Path Rel Dir)
distRelativeDir

-- | Package's setup-config storing Cabal configuration.

setupConfigFromDir ::
     (HasEnvConfig env, MonadReader env m, MonadThrow m)
  => Path Abs Dir
  -> m (Path Abs File)
setupConfigFromDir :: forall env (m :: * -> *).
(HasEnvConfig env, MonadReader env m, MonadThrow m) =>
Path Abs Dir -> m (Path Abs File)
setupConfigFromDir Path Abs Dir
fp = do
  Path Abs Dir
dist <- Path Abs Dir -> m (Path Abs Dir)
forall env (m :: * -> *).
(HasEnvConfig env, MonadReader env m, MonadThrow m) =>
Path Abs Dir -> m (Path Abs Dir)
distDirFromDir Path Abs Dir
fp
  Path Abs File -> m (Path Abs File)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Path Abs File -> m (Path Abs File))
-> Path Abs File -> m (Path Abs File)
forall a b. (a -> b) -> a -> b
$ Path Abs Dir
dist Path Abs Dir -> Path Rel File -> Path Abs File
forall b t. Path b Dir -> Path Rel t -> Path b t
</> $(mkRelFile "setup-config")

-- | Package's build artifacts directory.

distDirFromDir ::
     (HasEnvConfig env, MonadReader env m, MonadThrow m)
  => Path Abs Dir
  -> m (Path Abs Dir)
distDirFromDir :: forall env (m :: * -> *).
(HasEnvConfig env, MonadReader env m, MonadThrow m) =>
Path Abs Dir -> m (Path Abs Dir)
distDirFromDir Path Abs Dir
fp =
  (Path Rel Dir -> Path Abs Dir)
-> m (Path Rel Dir) -> m (Path Abs Dir)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Path Abs Dir
fp </>) m (Path Rel Dir)
forall env (m :: * -> *).
(HasEnvConfig env, MonadReader env m, MonadThrow m) =>
m (Path Rel Dir)
distRelativeDir

-- | The directory containing all dist directories, including all

-- different platform/compiler combinations.

rootDistDirFromDir ::
     (HasConfig env, MonadReader env m)
  => Path Abs Dir
  -> m (Path Abs Dir)
rootDistDirFromDir :: forall env (m :: * -> *).
(HasConfig env, MonadReader env m) =>
Path Abs Dir -> m (Path Abs Dir)
rootDistDirFromDir Path Abs Dir
fp =
  (Path Rel Dir -> Path Abs Dir)
-> m (Path Rel Dir) -> m (Path Abs Dir)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Path Abs Dir
fp </>) m (Path Rel Dir)
forall env (m :: * -> *).
(HasConfig env, MonadReader env m) =>
m (Path Rel Dir)
rootDistRelativeDir

-- | Relative directory to the top dist directory, containing

-- individual platform/compiler combinations as subdirs.

rootDistRelativeDir ::
     (HasConfig env, MonadReader env m)
  => m (Path Rel Dir)
rootDistRelativeDir :: forall env (m :: * -> *).
(HasConfig env, MonadReader env m) =>
m (Path Rel Dir)
rootDistRelativeDir = do
  Path Rel Dir
workDir <- Getting (Path Rel Dir) env (Path Rel Dir) -> m (Path Rel Dir)
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting (Path Rel Dir) env (Path Rel Dir)
forall env. HasConfig env => Lens' env (Path Rel Dir)
Lens' env (Path Rel Dir)
workDirL
  Path Rel Dir -> m (Path Rel Dir)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Path Rel Dir -> m (Path Rel Dir))
-> Path Rel Dir -> m (Path Rel Dir)
forall a b. (a -> b) -> a -> b
$ Path Rel Dir
workDir Path Rel Dir -> Path Rel Dir -> Path Rel Dir
forall b t. Path b Dir -> Path Rel t -> Path b t
</> Path Rel Dir
relDirDist

-- | Package's working directory.

workDirFromDir ::
     (HasConfig env, MonadReader env m)
  => Path Abs Dir
  -> m (Path Abs Dir)
workDirFromDir :: forall env (m :: * -> *).
(HasConfig env, MonadReader env m) =>
Path Abs Dir -> m (Path Abs Dir)
workDirFromDir Path Abs Dir
fp = Getting (Path Abs Dir) env (Path Abs Dir) -> m (Path Abs Dir)
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view (Getting (Path Abs Dir) env (Path Abs Dir) -> m (Path Abs Dir))
-> Getting (Path Abs Dir) env (Path Abs Dir) -> m (Path Abs Dir)
forall a b. (a -> b) -> a -> b
$ (Path Rel Dir -> Const (Path Abs Dir) (Path Rel Dir))
-> env -> Const (Path Abs Dir) env
forall env. HasConfig env => Lens' env (Path Rel Dir)
Lens' env (Path Rel Dir)
workDirL((Path Rel Dir -> Const (Path Abs Dir) (Path Rel Dir))
 -> env -> Const (Path Abs Dir) env)
-> ((Path Abs Dir -> Const (Path Abs Dir) (Path Abs Dir))
    -> Path Rel Dir -> Const (Path Abs Dir) (Path Rel Dir))
-> Getting (Path Abs Dir) env (Path Abs Dir)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Path Rel Dir -> Path Abs Dir)
-> SimpleGetter (Path Rel Dir) (Path Abs Dir)
forall s a. (s -> a) -> SimpleGetter s a
to (Path Abs Dir
fp </>)

-- | Directory for project templates.

templatesDir :: Config -> Path Abs Dir
templatesDir :: Config -> Path Abs Dir
templatesDir Config
config = Getting (Path Abs Dir) Config (Path Abs Dir)
-> Config -> Path Abs Dir
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting (Path Abs Dir) Config (Path Abs Dir)
forall s. HasConfig s => Lens' s (Path Abs Dir)
Lens' Config (Path Abs Dir)
stackRootL Config
config Path Abs Dir -> Path Rel Dir -> Path Abs Dir
forall b t. Path b Dir -> Path Rel t -> Path b t
</> $(mkRelDir "templates")

-- | Relative location of build artifacts.

distRelativeDir ::
     (HasEnvConfig env, MonadReader env m, MonadThrow m)
  => m (Path Rel Dir)
distRelativeDir :: forall env (m :: * -> *).
(HasEnvConfig env, MonadReader env m, MonadThrow m) =>
m (Path Rel Dir)
distRelativeDir = do
  ActualCompiler
compilerVer <- Getting ActualCompiler env ActualCompiler -> m ActualCompiler
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting ActualCompiler env ActualCompiler
forall env. HasCompiler env => SimpleGetter env ActualCompiler
SimpleGetter env ActualCompiler
compilerVersionL
  Path Rel Dir
platform <- m (Path Rel Dir)
forall env (m :: * -> *).
(HasEnvConfig env, MonadReader env m, MonadThrow m) =>
m (Path Rel Dir)
platformGhcRelDir
  -- Compiler version: allows build artefacts to be distinguished by compiler

  -- version, which will also distinguish one Cabal version from another.

  Path Rel Dir
compilerDir <- FilePath -> m (Path Rel Dir)
forall (m :: * -> *). MonadThrow m => FilePath -> m (Path Rel Dir)
parseRelDir (FilePath -> m (Path Rel Dir)) -> FilePath -> m (Path Rel Dir)
forall a b. (a -> b) -> a -> b
$ ActualCompiler -> FilePath
compilerVersionString ActualCompiler
compilerVer
  Path Rel Dir
platformAndCompiler <- Path Rel Dir -> m (Path Rel Dir)
forall (m :: * -> *).
MonadThrow m =>
Path Rel Dir -> m (Path Rel Dir)
useShaPathOnWindows (Path Rel Dir
platform Path Rel Dir -> Path Rel Dir -> Path Rel Dir
forall b t. Path b Dir -> Path Rel t -> Path b t
</> Path Rel Dir
compilerDir)
  Path Rel Dir
allDist <- m (Path Rel Dir)
forall env (m :: * -> *).
(HasConfig env, MonadReader env m) =>
m (Path Rel Dir)
rootDistRelativeDir
  Path Rel Dir -> m (Path Rel Dir)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Path Rel Dir -> m (Path Rel Dir))
-> Path Rel Dir -> m (Path Rel Dir)
forall a b. (a -> b) -> a -> b
$ Path Rel Dir
allDist Path Rel Dir -> Path Rel Dir -> Path Rel Dir
forall b t. Path b Dir -> Path Rel t -> Path b t
</> Path Rel Dir
platformAndCompiler

-- | Docker sandbox from project root.

projectDockerSandboxDir :: (HasConfig env, MonadReader env m)
  => Path Abs Dir      -- ^ Project root

  -> m (Path Abs Dir)  -- ^ Docker sandbox

projectDockerSandboxDir :: forall env (m :: * -> *).
(HasConfig env, MonadReader env m) =>
Path Abs Dir -> m (Path Abs Dir)
projectDockerSandboxDir Path Abs Dir
projectRoot = do
  Path Rel Dir
workDir <- Getting (Path Rel Dir) env (Path Rel Dir) -> m (Path Rel Dir)
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting (Path Rel Dir) env (Path Rel Dir)
forall env. HasConfig env => Lens' env (Path Rel Dir)
Lens' env (Path Rel Dir)
workDirL
  Path Abs Dir -> m (Path Abs Dir)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Path Abs Dir -> m (Path Abs Dir))
-> Path Abs Dir -> m (Path Abs Dir)
forall a b. (a -> b) -> a -> b
$ Path Abs Dir
projectRoot Path Abs Dir -> Path Rel Dir -> Path Abs Dir
forall b t. Path b Dir -> Path Rel t -> Path b t
</> Path Rel Dir
workDir Path Rel Dir -> Path Rel Dir -> Path Rel Dir
forall b t. Path b Dir -> Path Rel t -> Path b t
</> $(mkRelDir "docker/")

-- | Image staging dir from project root.

imageStagingDir ::
     (HasConfig env, MonadReader env m, MonadThrow m)
  => Path Abs Dir      -- ^ Project root

  -> Int               -- ^ Index of image

  -> m (Path Abs Dir)  -- ^ Docker sandbox

imageStagingDir :: forall env (m :: * -> *).
(HasConfig env, MonadReader env m, MonadThrow m) =>
Path Abs Dir -> Int -> m (Path Abs Dir)
imageStagingDir Path Abs Dir
projectRoot Int
imageIdx = do
  Path Rel Dir
workDir <- Getting (Path Rel Dir) env (Path Rel Dir) -> m (Path Rel Dir)
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting (Path Rel Dir) env (Path Rel Dir)
forall env. HasConfig env => Lens' env (Path Rel Dir)
Lens' env (Path Rel Dir)
workDirL
  Path Rel Dir
idxRelDir <- FilePath -> m (Path Rel Dir)
forall (m :: * -> *). MonadThrow m => FilePath -> m (Path Rel Dir)
parseRelDir (Int -> FilePath
forall a. Show a => a -> FilePath
show Int
imageIdx)
  Path Abs Dir -> m (Path Abs Dir)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Path Abs Dir -> m (Path Abs Dir))
-> Path Abs Dir -> m (Path Abs Dir)
forall a b. (a -> b) -> a -> b
$ Path Abs Dir
projectRoot Path Abs Dir -> Path Rel Dir -> Path Abs Dir
forall b t. Path b Dir -> Path Rel t -> Path b t
</> Path Rel Dir
workDir Path Rel Dir -> Path Rel Dir -> Path Rel Dir
forall b t. Path b Dir -> Path Rel t -> Path b t
</> $(mkRelDir "image") Path Rel Dir -> Path Rel Dir -> Path Rel Dir
forall b t. Path b Dir -> Path Rel t -> Path b t
</> Path Rel Dir
idxRelDir