{-# LANGUAGE RecordWildCards #-}
module Distribution.Client.DistDirLayout (
DistDirLayout(..),
DistDirParams(..),
defaultDistDirLayout,
ProjectRoot(..),
StoreDirLayout(..),
defaultStoreDirLayout,
CabalDirLayout(..),
mkCabalDirLayout,
defaultCabalDirLayout
) where
import Distribution.Client.Compat.Prelude
import Prelude ()
import System.FilePath
import Distribution.Client.Config
( defaultStoreDir, defaultLogsDir)
import Distribution.Package
( PackageId, PackageIdentifier, ComponentId, UnitId )
import Distribution.Compiler
import Distribution.Simple.Compiler
( PackageDB(..), PackageDBStack, OptimisationLevel(..) )
import Distribution.Types.ComponentName
import Distribution.Types.LibraryName
import Distribution.System
data DistDirParams = DistDirParams {
DistDirParams -> UnitId
distParamUnitId :: UnitId,
DistDirParams -> PackageId
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 -> String
distProjectRootDirectory :: FilePath,
DistDirLayout -> String -> String
distProjectFile :: String -> FilePath,
DistDirLayout -> String
distDirectory :: FilePath,
DistDirLayout -> DistDirParams -> String
distBuildDirectory :: DistDirParams -> FilePath,
DistDirLayout -> String
distBuildRootDirectory :: FilePath,
DistDirLayout -> String
distDownloadSrcDirectory :: FilePath,
DistDirLayout -> PackageId -> String
distUnpackedSrcDirectory :: PackageId -> FilePath,
DistDirLayout -> String
distUnpackedSrcRootDirectory :: FilePath,
DistDirLayout -> String -> String
distProjectCacheFile :: String -> FilePath,
DistDirLayout -> String
distProjectCacheDirectory :: FilePath,
DistDirLayout -> DistDirParams -> String -> String
distPackageCacheFile :: DistDirParams -> String -> FilePath,
DistDirLayout -> DistDirParams -> String
distPackageCacheDirectory :: DistDirParams -> FilePath,
DistDirLayout -> PackageId -> String
distSdistFile :: PackageId -> FilePath,
DistDirLayout -> String
distSdistDirectory :: FilePath,
DistDirLayout -> String
distTempDirectory :: FilePath,
DistDirLayout -> String
distBinDirectory :: FilePath,
DistDirLayout -> CompilerId -> PackageDB
distPackageDB :: CompilerId -> PackageDB
}
data StoreDirLayout = StoreDirLayout {
StoreDirLayout -> CompilerId -> String
storeDirectory :: CompilerId -> FilePath,
StoreDirLayout -> CompilerId -> UnitId -> String
storePackageDirectory :: CompilerId -> UnitId -> FilePath,
StoreDirLayout -> CompilerId -> String
storePackageDBPath :: CompilerId -> FilePath,
StoreDirLayout -> CompilerId -> PackageDB
storePackageDB :: CompilerId -> PackageDB,
StoreDirLayout -> CompilerId -> PackageDBStack
storePackageDBStack :: CompilerId -> PackageDBStack,
StoreDirLayout -> CompilerId -> String
storeIncomingDirectory :: CompilerId -> FilePath,
StoreDirLayout -> CompilerId -> UnitId -> String
storeIncomingLock :: CompilerId -> UnitId -> FilePath
}
data CabalDirLayout = CabalDirLayout {
CabalDirLayout -> StoreDirLayout
cabalStoreDirLayout :: StoreDirLayout,
CabalDirLayout -> String
cabalLogsDirectory :: FilePath
}
data ProjectRoot =
ProjectRootImplicit FilePath
| ProjectRootExplicit FilePath FilePath
deriving (ProjectRoot -> ProjectRoot -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ProjectRoot -> ProjectRoot -> Bool
$c/= :: ProjectRoot -> ProjectRoot -> Bool
== :: ProjectRoot -> ProjectRoot -> Bool
$c== :: ProjectRoot -> ProjectRoot -> Bool
Eq, Int -> ProjectRoot -> String -> String
[ProjectRoot] -> String -> String
ProjectRoot -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [ProjectRoot] -> String -> String
$cshowList :: [ProjectRoot] -> String -> String
show :: ProjectRoot -> String
$cshow :: ProjectRoot -> String
showsPrec :: Int -> ProjectRoot -> String -> String
$cshowsPrec :: Int -> ProjectRoot -> String -> String
Show)
defaultDistDirLayout :: ProjectRoot
-> Maybe FilePath
-> DistDirLayout
defaultDistDirLayout :: ProjectRoot -> Maybe String -> DistDirLayout
defaultDistDirLayout ProjectRoot
projectRoot Maybe String
mdistDirectory =
DistDirLayout {String
String -> String
PackageId -> String
CompilerId -> PackageDB
DistDirParams -> String
DistDirParams -> String -> String
distPackageDB :: CompilerId -> PackageDB
distBinDirectory :: String
distTempDirectory :: String
distSdistDirectory :: String
distSdistFile :: PackageId -> String
distPackageCacheFile :: DistDirParams -> String -> String
distPackageCacheDirectory :: DistDirParams -> String
distProjectCacheFile :: String -> String
distProjectCacheDirectory :: String
distDownloadSrcDirectory :: String
distUnpackedSrcDirectory :: PackageId -> String
distUnpackedSrcRootDirectory :: String
distBuildDirectory :: DistDirParams -> String
distBuildRootDirectory :: String
distDirectory :: String
distProjectFile :: String -> String
distProjectRootDirectory :: String
distPackageDB :: CompilerId -> PackageDB
distBinDirectory :: String
distTempDirectory :: String
distSdistDirectory :: String
distSdistFile :: PackageId -> String
distPackageCacheDirectory :: DistDirParams -> String
distPackageCacheFile :: DistDirParams -> String -> String
distProjectCacheDirectory :: String
distProjectCacheFile :: String -> String
distUnpackedSrcRootDirectory :: String
distUnpackedSrcDirectory :: PackageId -> String
distDownloadSrcDirectory :: String
distBuildRootDirectory :: String
distBuildDirectory :: DistDirParams -> String
distDirectory :: String
distProjectFile :: String -> String
distProjectRootDirectory :: String
..}
where
(String
projectRootDir, String
projectFile) = case ProjectRoot
projectRoot of
ProjectRootImplicit String
dir -> (String
dir, String
dir String -> String -> String
</> String
"cabal.project")
ProjectRootExplicit String
dir String
file -> (String
dir, String
dir String -> String -> String
</> String
file)
distProjectRootDirectory :: FilePath
distProjectRootDirectory :: String
distProjectRootDirectory = String
projectRootDir
distProjectFile :: String -> FilePath
distProjectFile :: String -> String
distProjectFile String
ext = String
projectFile String -> String -> String
<.> String
ext
distDirectory :: FilePath
distDirectory :: String
distDirectory = String
distProjectRootDirectory
String -> String -> String
</> forall a. a -> Maybe a -> a
fromMaybe String
"dist-newstyle" Maybe String
mdistDirectory
distBuildRootDirectory :: FilePath
distBuildRootDirectory :: String
distBuildRootDirectory = String
distDirectory String -> String -> String
</> String
"build"
distBuildDirectory :: DistDirParams -> FilePath
distBuildDirectory :: DistDirParams -> String
distBuildDirectory DistDirParams
params =
String
distBuildRootDirectory String -> String -> String
</>
forall a. Pretty a => a -> String
prettyShow (DistDirParams -> Platform
distParamPlatform DistDirParams
params) String -> String -> String
</>
forall a. Pretty a => a -> String
prettyShow (DistDirParams -> CompilerId
distParamCompilerId DistDirParams
params) String -> String -> String
</>
forall a. Pretty a => a -> String
prettyShow (DistDirParams -> PackageId
distParamPackageId DistDirParams
params) String -> String -> String
</>
(case DistDirParams -> Maybe ComponentName
distParamComponentName DistDirParams
params of
Maybe ComponentName
Nothing -> String
""
Just (CLibName LibraryName
LMainLibName) -> String
""
Just (CLibName (LSubLibName UnqualComponentName
name)) -> String
"l" String -> String -> String
</> forall a. Pretty a => a -> String
prettyShow UnqualComponentName
name
Just (CFLibName UnqualComponentName
name) -> String
"f" String -> String -> String
</> forall a. Pretty a => a -> String
prettyShow UnqualComponentName
name
Just (CExeName UnqualComponentName
name) -> String
"x" String -> String -> String
</> forall a. Pretty a => a -> String
prettyShow UnqualComponentName
name
Just (CTestName UnqualComponentName
name) -> String
"t" String -> String -> String
</> forall a. Pretty a => a -> String
prettyShow UnqualComponentName
name
Just (CBenchName UnqualComponentName
name) -> String
"b" String -> String -> String
</> forall a. Pretty a => a -> String
prettyShow UnqualComponentName
name) String -> String -> String
</>
(case DistDirParams -> OptimisationLevel
distParamOptimization DistDirParams
params of
OptimisationLevel
NoOptimisation -> String
"noopt"
OptimisationLevel
NormalOptimisation -> String
""
OptimisationLevel
MaximumOptimisation -> String
"opt") String -> String -> String
</>
(let uid_str :: String
uid_str = forall a. Pretty a => a -> String
prettyShow (DistDirParams -> UnitId
distParamUnitId DistDirParams
params)
in if String
uid_str forall a. Eq a => a -> a -> Bool
== forall a. Pretty a => a -> String
prettyShow (DistDirParams -> ComponentId
distParamComponentId DistDirParams
params)
then String
""
else String
uid_str)
distUnpackedSrcRootDirectory :: FilePath
distUnpackedSrcRootDirectory :: String
distUnpackedSrcRootDirectory = String
distDirectory String -> String -> String
</> String
"src"
distUnpackedSrcDirectory :: PackageId -> FilePath
distUnpackedSrcDirectory :: PackageId -> String
distUnpackedSrcDirectory PackageId
pkgid = String
distUnpackedSrcRootDirectory
String -> String -> String
</> forall a. Pretty a => a -> String
prettyShow PackageId
pkgid
distDownloadSrcDirectory :: FilePath
distDownloadSrcDirectory :: String
distDownloadSrcDirectory = String
distUnpackedSrcRootDirectory
distProjectCacheDirectory :: FilePath
distProjectCacheDirectory :: String
distProjectCacheDirectory = String
distDirectory String -> String -> String
</> String
"cache"
distProjectCacheFile :: FilePath -> FilePath
distProjectCacheFile :: String -> String
distProjectCacheFile String
name = String
distProjectCacheDirectory String -> String -> String
</> String
name
distPackageCacheDirectory :: DistDirParams -> FilePath
distPackageCacheDirectory :: DistDirParams -> String
distPackageCacheDirectory DistDirParams
params = DistDirParams -> String
distBuildDirectory DistDirParams
params String -> String -> String
</> String
"cache"
distPackageCacheFile :: DistDirParams -> String -> FilePath
distPackageCacheFile :: DistDirParams -> String -> String
distPackageCacheFile DistDirParams
params String
name = DistDirParams -> String
distPackageCacheDirectory DistDirParams
params String -> String -> String
</> String
name
distSdistFile :: PackageIdentifier -> FilePath
distSdistFile :: PackageId -> String
distSdistFile PackageId
pid = String
distSdistDirectory String -> String -> String
</> forall a. Pretty a => a -> String
prettyShow PackageId
pid String -> String -> String
<.> String
"tar.gz"
distSdistDirectory :: FilePath
distSdistDirectory :: String
distSdistDirectory = String
distDirectory String -> String -> String
</> String
"sdist"
distTempDirectory :: FilePath
distTempDirectory :: String
distTempDirectory = String
distDirectory String -> String -> String
</> String
"tmp"
distBinDirectory :: FilePath
distBinDirectory :: String
distBinDirectory = String
distDirectory String -> String -> String
</> String
"bin"
distPackageDBPath :: CompilerId -> FilePath
distPackageDBPath :: CompilerId -> String
distPackageDBPath CompilerId
compid = String
distDirectory String -> String -> String
</> String
"packagedb" String -> String -> String
</> forall a. Pretty a => a -> String
prettyShow CompilerId
compid
distPackageDB :: CompilerId -> PackageDB
distPackageDB :: CompilerId -> PackageDB
distPackageDB = String -> PackageDB
SpecificPackageDB forall b c a. (b -> c) -> (a -> b) -> a -> c
. CompilerId -> String
distPackageDBPath
defaultStoreDirLayout :: FilePath -> StoreDirLayout
defaultStoreDirLayout :: String -> StoreDirLayout
defaultStoreDirLayout String
storeRoot =
StoreDirLayout {CompilerId -> String
CompilerId -> PackageDBStack
CompilerId -> PackageDB
CompilerId -> UnitId -> String
storeIncomingLock :: CompilerId -> UnitId -> String
storeIncomingDirectory :: CompilerId -> String
storePackageDBStack :: CompilerId -> PackageDBStack
storePackageDB :: CompilerId -> PackageDB
storePackageDBPath :: CompilerId -> String
storePackageDirectory :: CompilerId -> UnitId -> String
storeDirectory :: CompilerId -> String
storeIncomingLock :: CompilerId -> UnitId -> String
storeIncomingDirectory :: CompilerId -> String
storePackageDBStack :: CompilerId -> PackageDBStack
storePackageDB :: CompilerId -> PackageDB
storePackageDBPath :: CompilerId -> String
storePackageDirectory :: CompilerId -> UnitId -> String
storeDirectory :: CompilerId -> String
..}
where
storeDirectory :: CompilerId -> FilePath
storeDirectory :: CompilerId -> String
storeDirectory CompilerId
compid =
String
storeRoot String -> String -> String
</> forall a. Pretty a => a -> String
prettyShow CompilerId
compid
storePackageDirectory :: CompilerId -> UnitId -> FilePath
storePackageDirectory :: CompilerId -> UnitId -> String
storePackageDirectory CompilerId
compid UnitId
ipkgid =
CompilerId -> String
storeDirectory CompilerId
compid String -> String -> String
</> forall a. Pretty a => a -> String
prettyShow UnitId
ipkgid
storePackageDBPath :: CompilerId -> FilePath
storePackageDBPath :: CompilerId -> String
storePackageDBPath CompilerId
compid =
CompilerId -> String
storeDirectory CompilerId
compid String -> String -> String
</> String
"package.db"
storePackageDB :: CompilerId -> PackageDB
storePackageDB :: CompilerId -> PackageDB
storePackageDB CompilerId
compid =
String -> PackageDB
SpecificPackageDB (CompilerId -> String
storePackageDBPath CompilerId
compid)
storePackageDBStack :: CompilerId -> PackageDBStack
storePackageDBStack :: CompilerId -> PackageDBStack
storePackageDBStack CompilerId
compid =
[PackageDB
GlobalPackageDB, CompilerId -> PackageDB
storePackageDB CompilerId
compid]
storeIncomingDirectory :: CompilerId -> FilePath
storeIncomingDirectory :: CompilerId -> String
storeIncomingDirectory CompilerId
compid =
CompilerId -> String
storeDirectory CompilerId
compid String -> String -> String
</> String
"incoming"
storeIncomingLock :: CompilerId -> UnitId -> FilePath
storeIncomingLock :: CompilerId -> UnitId -> String
storeIncomingLock CompilerId
compid UnitId
unitid =
CompilerId -> String
storeIncomingDirectory CompilerId
compid String -> String -> String
</> forall a. Pretty a => a -> String
prettyShow UnitId
unitid String -> String -> String
<.> String
"lock"
defaultCabalDirLayout :: IO CabalDirLayout
defaultCabalDirLayout :: IO CabalDirLayout
defaultCabalDirLayout =
Maybe String -> Maybe String -> IO CabalDirLayout
mkCabalDirLayout forall a. Maybe a
Nothing forall a. Maybe a
Nothing
mkCabalDirLayout :: Maybe FilePath
-> Maybe FilePath
-> IO CabalDirLayout
mkCabalDirLayout :: Maybe String -> Maybe String -> IO CabalDirLayout
mkCabalDirLayout Maybe String
mstoreDir Maybe String
mlogDir = do
StoreDirLayout
cabalStoreDirLayout <-
String -> StoreDirLayout
defaultStoreDirLayout forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall b a. b -> (a -> b) -> Maybe a -> b
maybe IO String
defaultStoreDir forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe String
mstoreDir
String
cabalLogsDirectory <-
forall b a. b -> (a -> b) -> Maybe a -> b
maybe IO String
defaultLogsDir forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe String
mlogDir
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ CabalDirLayout {String
StoreDirLayout
cabalLogsDirectory :: String
cabalStoreDirLayout :: StoreDirLayout
cabalLogsDirectory :: String
cabalStoreDirLayout :: StoreDirLayout
..}