{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Distribution.PackageDescription.Check.Monad
(
CheckM (..)
, execCheckM
, CheckInterface (..)
, CheckPackageContentOps (..)
, CheckPreDistributionOps (..)
, TargetAnnotation (..)
, PackageCheck (..)
, CheckExplanation (..)
, CEType (..)
, WarnLang (..)
, CheckCtx (..)
, pristineCheckCtx
, initCheckCtx
, PNames (..)
, ppPackageCheck
, isHackageDistError
, asksCM
, localCM
, checkP
, checkPkg
, liftInt
, tellP
, checkSpecVer
) where
import Distribution.Compat.Prelude
import Prelude ()
import Distribution.CabalSpecVersion (CabalSpecVersion)
import Distribution.Package (packageName)
import Distribution.PackageDescription.Check.Warning
import Distribution.Simple.BuildToolDepends (desugarBuildToolSimple)
import Distribution.Simple.Glob (Glob, GlobResult)
import Distribution.Types.ExeDependency (ExeDependency)
import Distribution.Types.GenericPackageDescription
import Distribution.Types.LegacyExeDependency (LegacyExeDependency)
import Distribution.Types.PackageDescription (package, specVersion)
import Distribution.Types.PackageId (PackageIdentifier)
import Distribution.Types.UnqualComponentName
import qualified Control.Monad.Reader as Reader
import qualified Control.Monad.Trans.Class as Trans
import qualified Control.Monad.Writer as Writer
import qualified Data.ByteString.Lazy as BS
import qualified Data.Set as Set
import Control.Monad
data CheckInterface m = CheckInterface
{ forall (m :: * -> *). CheckInterface m -> Bool
ciPureChecks :: Bool
,
forall (m :: * -> *).
CheckInterface m -> Maybe (CheckPackageContentOps m)
ciPackageOps :: Maybe (CheckPackageContentOps m)
,
forall (m :: * -> *).
CheckInterface m -> Maybe (CheckPreDistributionOps m)
ciPreDistOps :: Maybe (CheckPreDistributionOps m)
}
data CheckPackageContentOps m = CheckPackageContentOps
{ forall (m :: * -> *).
CheckPackageContentOps m -> FilePath -> m Bool
doesFileExist :: FilePath -> m Bool
, forall (m :: * -> *).
CheckPackageContentOps m -> FilePath -> m Bool
doesDirectoryExist :: FilePath -> m Bool
, forall (m :: * -> *).
CheckPackageContentOps m -> FilePath -> m [FilePath]
getDirectoryContents :: FilePath -> m [FilePath]
, forall (m :: * -> *).
CheckPackageContentOps m -> FilePath -> m ByteString
getFileContents :: FilePath -> m BS.ByteString
}
data CheckPreDistributionOps m = CheckPreDistributionOps
{ forall (m :: * -> *).
CheckPreDistributionOps m
-> FilePath -> Glob -> m [GlobResult FilePath]
runDirFileGlobM :: FilePath -> Glob -> m [GlobResult FilePath]
, forall (m :: * -> *).
CheckPreDistributionOps m -> FilePath -> m [FilePath]
getDirectoryContentsM :: FilePath -> m [FilePath]
}
data CheckCtx m = CheckCtx
{ forall (m :: * -> *). CheckCtx m -> CheckInterface m
ccInterface :: CheckInterface m
,
forall (m :: * -> *). CheckCtx m -> Bool
ccFlag :: Bool
,
forall (m :: * -> *). CheckCtx m -> CabalSpecVersion
ccSpecVersion :: CabalSpecVersion
,
forall (m :: * -> *).
CheckCtx m -> LegacyExeDependency -> Maybe ExeDependency
ccDesugar :: LegacyExeDependency -> Maybe ExeDependency
,
forall (m :: * -> *). CheckCtx m -> PNames
ccNames :: PNames
}
pristineCheckCtx
:: Monad m
=> CheckInterface m
-> GenericPackageDescription
-> CheckCtx m
pristineCheckCtx :: forall (m :: * -> *).
Monad m =>
CheckInterface m -> GenericPackageDescription -> CheckCtx m
pristineCheckCtx CheckInterface m
ci GenericPackageDescription
gpd =
let ens :: [UnqualComponentName]
ens = ((UnqualComponentName, CondTree ConfVar [Dependency] Executable)
-> UnqualComponentName)
-> [(UnqualComponentName,
CondTree ConfVar [Dependency] Executable)]
-> [UnqualComponentName]
forall a b. (a -> b) -> [a] -> [b]
map (UnqualComponentName, CondTree ConfVar [Dependency] Executable)
-> UnqualComponentName
forall a b. (a, b) -> a
fst (GenericPackageDescription
-> [(UnqualComponentName,
CondTree ConfVar [Dependency] Executable)]
condExecutables GenericPackageDescription
gpd)
in CheckInterface m
-> Bool
-> CabalSpecVersion
-> (LegacyExeDependency -> Maybe ExeDependency)
-> PNames
-> CheckCtx m
forall (m :: * -> *).
CheckInterface m
-> Bool
-> CabalSpecVersion
-> (LegacyExeDependency -> Maybe ExeDependency)
-> PNames
-> CheckCtx m
CheckCtx
CheckInterface m
ci
Bool
False
(PackageDescription -> CabalSpecVersion
specVersion (PackageDescription -> CabalSpecVersion)
-> (GenericPackageDescription -> PackageDescription)
-> GenericPackageDescription
-> CabalSpecVersion
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenericPackageDescription -> PackageDescription
packageDescription (GenericPackageDescription -> CabalSpecVersion)
-> GenericPackageDescription -> CabalSpecVersion
forall a b. (a -> b) -> a -> b
$ GenericPackageDescription
gpd)
(PackageName
-> [UnqualComponentName]
-> LegacyExeDependency
-> Maybe ExeDependency
desugarBuildToolSimple (GenericPackageDescription -> PackageName
forall pkg. Package pkg => pkg -> PackageName
packageName GenericPackageDescription
gpd) [UnqualComponentName]
ens)
(GenericPackageDescription -> PNames
initPNames GenericPackageDescription
gpd)
initCheckCtx :: Monad m => TargetAnnotation a -> CheckCtx m -> CheckCtx m
initCheckCtx :: forall (m :: * -> *) a.
Monad m =>
TargetAnnotation a -> CheckCtx m -> CheckCtx m
initCheckCtx TargetAnnotation a
t CheckCtx m
c = CheckCtx m
c{ccFlag = taPackageFlag t}
data TargetAnnotation a = TargetAnnotation
{ forall a. TargetAnnotation a -> a
taTarget :: a
,
forall a. TargetAnnotation a -> Bool
taPackageFlag :: Bool
}
deriving (Int -> TargetAnnotation a -> ShowS
[TargetAnnotation a] -> ShowS
TargetAnnotation a -> FilePath
(Int -> TargetAnnotation a -> ShowS)
-> (TargetAnnotation a -> FilePath)
-> ([TargetAnnotation a] -> ShowS)
-> Show (TargetAnnotation a)
forall a. Show a => Int -> TargetAnnotation a -> ShowS
forall a. Show a => [TargetAnnotation a] -> ShowS
forall a. Show a => TargetAnnotation a -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> TargetAnnotation a -> ShowS
showsPrec :: Int -> TargetAnnotation a -> ShowS
$cshow :: forall a. Show a => TargetAnnotation a -> FilePath
show :: TargetAnnotation a -> FilePath
$cshowList :: forall a. Show a => [TargetAnnotation a] -> ShowS
showList :: [TargetAnnotation a] -> ShowS
Show, TargetAnnotation a -> TargetAnnotation a -> Bool
(TargetAnnotation a -> TargetAnnotation a -> Bool)
-> (TargetAnnotation a -> TargetAnnotation a -> Bool)
-> Eq (TargetAnnotation a)
forall a. Eq a => TargetAnnotation a -> TargetAnnotation a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => TargetAnnotation a -> TargetAnnotation a -> Bool
== :: TargetAnnotation a -> TargetAnnotation a -> Bool
$c/= :: forall a. Eq a => TargetAnnotation a -> TargetAnnotation a -> Bool
/= :: TargetAnnotation a -> TargetAnnotation a -> Bool
Eq, Eq (TargetAnnotation a)
Eq (TargetAnnotation a) =>
(TargetAnnotation a -> TargetAnnotation a -> Ordering)
-> (TargetAnnotation a -> TargetAnnotation a -> Bool)
-> (TargetAnnotation a -> TargetAnnotation a -> Bool)
-> (TargetAnnotation a -> TargetAnnotation a -> Bool)
-> (TargetAnnotation a -> TargetAnnotation a -> Bool)
-> (TargetAnnotation a -> TargetAnnotation a -> TargetAnnotation a)
-> (TargetAnnotation a -> TargetAnnotation a -> TargetAnnotation a)
-> Ord (TargetAnnotation a)
TargetAnnotation a -> TargetAnnotation a -> Bool
TargetAnnotation a -> TargetAnnotation a -> Ordering
TargetAnnotation a -> TargetAnnotation a -> TargetAnnotation a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (TargetAnnotation a)
forall a. Ord a => TargetAnnotation a -> TargetAnnotation a -> Bool
forall a.
Ord a =>
TargetAnnotation a -> TargetAnnotation a -> Ordering
forall a.
Ord a =>
TargetAnnotation a -> TargetAnnotation a -> TargetAnnotation a
$ccompare :: forall a.
Ord a =>
TargetAnnotation a -> TargetAnnotation a -> Ordering
compare :: TargetAnnota