module Distribution.Simple.BuildToolDepends where
import Prelude ()
import Distribution.Compat.Prelude
import qualified Data.Map as Map
import Distribution.Package
import Distribution.PackageDescription
desugarBuildTool :: PackageDescription
-> LegacyExeDependency
-> Maybe ExeDependency
desugarBuildTool :: PackageDescription -> LegacyExeDependency -> Maybe ExeDependency
desugarBuildTool PackageDescription
pkg LegacyExeDependency
led =
if Bool
foundLocal
then forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ PackageName -> UnqualComponentName -> VersionRange -> ExeDependency
ExeDependency (forall pkg. Package pkg => pkg -> PackageName
packageName PackageDescription
pkg) UnqualComponentName
toolName VersionRange
reqVer
else forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup String
name Map String ExeDependency
whiteMap
where
LegacyExeDependency String
name VersionRange
reqVer = LegacyExeDependency
led
toolName :: UnqualComponentName
toolName = String -> UnqualComponentName
mkUnqualComponentName String
name
foundLocal :: Bool
foundLocal = UnqualComponentName
toolName forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` forall a b. (a -> b) -> [a] -> [b]
map Executable -> UnqualComponentName
exeName (PackageDescription -> [Executable]
executables PackageDescription
pkg)
whitelist :: [String]
whitelist = [ String
"hscolour", String
"haddock", String
"happy", String
"alex", String
"hsc2hs", String
"c2hs"
, String
"cpphs", String
"greencard", String
"hspec-discover"
]
whiteMap :: Map String ExeDependency
whiteMap = forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList forall a b. (a -> b) -> a -> b
$ forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a b. (a -> b) -> [a] -> [b]
map [String]
whitelist forall a b. (a -> b) -> a -> b
$ \String
n ->
(String
n, PackageName -> UnqualComponentName -> VersionRange -> ExeDependency
ExeDependency (String -> PackageName
mkPackageName String
n) (String -> UnqualComponentName
mkUnqualComponentName String
n) VersionRange
reqVer)
getAllToolDependencies :: PackageDescription
-> BuildInfo
-> [ExeDependency]
getAllToolDependencies :: PackageDescription -> BuildInfo -> [ExeDependency]
getAllToolDependencies PackageDescription
pkg BuildInfo
bi =
BuildInfo -> [ExeDependency]
buildToolDepends BuildInfo
bi forall a. [a] -> [a] -> [a]
++ forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (PackageDescription -> LegacyExeDependency -> Maybe ExeDependency
desugarBuildTool PackageDescription
pkg) (BuildInfo -> [LegacyExeDependency]
buildTools BuildInfo
bi)
isInternal :: PackageDescription -> ExeDependency -> Bool
isInternal :: PackageDescription -> ExeDependency -> Bool
isInternal PackageDescription
pkg (ExeDependency PackageName
n UnqualComponentName
_ VersionRange
_) = PackageName
n forall a. Eq a => a -> a -> Bool
== forall pkg. Package pkg => pkg -> PackageName
packageName PackageDescription
pkg
getAllInternalToolDependencies :: PackageDescription
-> BuildInfo
-> [UnqualComponentName]
getAllInternalToolDependencies :: PackageDescription -> BuildInfo -> [UnqualComponentName]
getAllInternalToolDependencies PackageDescription
pkg BuildInfo
bi =
[ UnqualComponentName
toolname
| dep :: ExeDependency
dep@(ExeDependency PackageName
_ UnqualComponentName
toolname VersionRange
_) <- PackageDescription -> BuildInfo -> [ExeDependency]
getAllToolDependencies PackageDescription
pkg BuildInfo
bi
, PackageDescription -> ExeDependency -> Bool
isInternal PackageDescription
pkg ExeDependency
dep
]