module Distribution.Simple.BuildToolDepends where
import Distribution.Compat.Prelude
import Prelude ()
import qualified Data.Map as Map
import Distribution.Package
import Distribution.PackageDescription
desugarBuildToolSimple
:: PackageName
-> [UnqualComponentName]
-> LegacyExeDependency
-> Maybe ExeDependency
desugarBuildToolSimple :: PackageName
-> [UnqualComponentName]
-> LegacyExeDependency
-> Maybe ExeDependency
desugarBuildToolSimple PackageName
pname [UnqualComponentName]
exeNames (LegacyExeDependency String
name VersionRange
reqVer)
| Bool
foundLocal = ExeDependency -> Maybe ExeDependency
forall a. a -> Maybe a
Just (ExeDependency -> Maybe ExeDependency)
-> ExeDependency -> Maybe ExeDependency
forall a b. (a -> b) -> a -> b
$ PackageName -> UnqualComponentName -> VersionRange -> ExeDependency
ExeDependency PackageName
pname UnqualComponentName
toolName VersionRange
reqVer
| Bool
otherwise = String -> Map String ExeDependency -> Maybe ExeDependency
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup String
name Map String ExeDependency
allowMap
where
toolName :: UnqualComponentName
toolName = String -> UnqualComponentName
mkUnqualComponentName String
name
foundLocal :: Bool
foundLocal = UnqualComponentName
toolName UnqualComponentName -> [UnqualComponentName] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [UnqualComponentName]
exeNames
allowlist :: [String]
allowlist =
[ String
"hscolour"
, String
"haddock"
, String
"happy"
, String
"alex"
, String
"hsc2hs"
, String
"c2hs"
, String
"cpphs"
, String
"greencard"
, String
"hspec-discover"
]
allowMap :: Map String ExeDependency
allowMap = [(String, ExeDependency)] -> Map String ExeDependency
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(String, ExeDependency)] -> Map String ExeDependency)
-> [(String, ExeDependency)] -> Map String ExeDependency
forall a b. (a -> b) -> a -> b
$ ((String -> (String, ExeDependency))
-> [String] -> [(String, ExeDependency)])
-> [String]
-> (String -> (String, ExeDependency))
-> [(String, ExeDependency)]
forall a b c. (a -> b -> c) -> b -> a -> c
flip (String -> (String, ExeDependency))
-> [String] -> [(String, ExeDependency)]
forall a b. (a -> b) -> [a] -> [b]
map [String]
allowlist ((String -> (String, ExeDependency)) -> [(String, ExeDependency)])
-> (String -> (String, ExeDependency)) -> [(String, ExeDependency)]
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)
desugarBuildTool
:: PackageDescription
-> LegacyExeDependency
-> Maybe ExeDependency
desugarBuildTool :: PackageDescription -> LegacyExeDependency -> Maybe ExeDependency
desugarBuildTool PackageDescription
pkg LegacyExeDependency
led =
PackageName
-> [UnqualComponentName]
-> LegacyExeDependency
-> Maybe ExeDependency
desugarBuildToolSimple
(PackageDescription -> PackageName
forall pkg. Package pkg => pkg -> PackageName
packageName PackageDescription
pkg)
((Executable -> UnqualComponentName)
-> [Executable] -> [UnqualComponentName]
forall a b. (a -> b) -> [a] -> [b]
map Executable -> UnqualComponentName
exeName ([Executable] -> [UnqualComponentName])
-> [Executable] -> [UnqualComponentName]
forall a b. (a -> b) -> a -> b
$ PackageDescription -> [Executable]
executables PackageDescription
pkg)
LegacyExeDependency
led
getAllToolDependencies
:: PackageDescription
-> BuildInfo
-> [ExeDependency]
getAllToolDependencies :: PackageDescription -> BuildInfo -> [ExeDependency]
getAllToolDependencies PackageDescription
pkg BuildInfo
bi =
BuildInfo -> [ExeDependency]
buildToolDepends BuildInfo
bi [ExeDependency] -> [ExeDependency] -> [ExeDependency]
forall a. [a] -> [a] -> [a]
++ (LegacyExeDependency -> Maybe ExeDependency)
-> [LegacyExeDependency] -> [ExeDependency]
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 PackageName -> PackageName -> Bool
forall a. Eq a => a -> a -> Bool
== PackageDescription -> PackageName
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
]