{-# LANGUAGE RecordWildCards #-}
module Distribution.Client.DistDirLayout
(
DistDirLayout (..)
, DistDirParams (..)
, defaultDistDirLayout
, ProjectRoot (..)
, defaultProjectFile
, StoreDirLayout (..)
, defaultStoreDirLayout
, 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
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
}
data DistDirLayout = DistDirLayout
{ DistDirLayout -> [Char]
distProjectRootDirectory :: FilePath
, DistDirLayout -> [Char] -> [Char]
distProjectFile :: String -> FilePath
, DistDirLayout -> [Char]
distDirectory :: FilePath
, DistDirLayout -> DistDirParams -> [Char]
distBuildDirectory :: DistDirParams -> FilePath
, DistDirLayout -> [Char]
distBuildRootDirectory :: FilePath
, DistDirLayout -> [Char]
distDownloadSrcDirectory :: FilePath
, DistDirLayout -> PackageIdentifier -> [Char]
distUnpackedSrcDirectory :: PackageId -> FilePath
, DistDirLayout -> [Char]
distUnpackedSrcRootDirectory :: FilePath
, DistDirLayout -> [Char] -> [Char]
distProjectCacheFile :: String -> FilePath
, DistDirLayout -> [Char]
distProjectCacheDirectory :: FilePath
, DistDirLayout -> DistDirParams -> [Char] -> [Char]
distPackageCacheFile :: DistDirParams -> String -> FilePath
, DistDirLayout -> DistDirParams -> [Char]
distPackageCacheDirectory :: DistDirParams -> FilePath
, DistDirLayout -> PackageIdentifier -> [Char]
distSdistFile :: PackageId -> FilePath
, DistDirLayout -> [Char]
distSdistDirectory :: FilePath
, DistDirLayout -> [Char]
distTempDirectory :: FilePath
, DistDirLayout -> [Char]
distBinDirectory :: FilePath
, DistDirLayout -> CompilerId -> PackageDBCWD
distPackageDB :: CompilerId -> PackageDBCWD
, DistDirLayout -> Maybe [Char]
distHaddockOutputDir :: Maybe FilePath
}
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
}
data CabalDirLayout = CabalDirLayout
{ CabalDirLayout -> StoreDirLayout
cabalStoreDirLayout :: StoreDirLayout
, CabalDirLayout -> [Char]
cabalLogsDirectory :: FilePath
}
data ProjectRoot
=
ProjectRootImplicit FilePath
|
ProjectRootExplicit FilePath FilePath
|
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"
defaultDistDirLayout
:: ProjectRoot
-> Maybe FilePath
-> Maybe FilePath
-> 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
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
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
-> Maybe FilePath
-> 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{..}