{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
module Distribution.Types.LocalBuildInfo (
LocalBuildInfo(..),
localComponentId,
localUnitId,
localCompatPackageKey,
localPackage,
componentNameCLBIs,
componentNameTargets',
unitIdTarget',
allTargetsInBuildOrder',
withAllTargetsInBuildOrder',
neededTargetsInBuildOrder',
withNeededTargetsInBuildOrder',
testCoverage,
componentNameTargets,
unitIdTarget,
allTargetsInBuildOrder,
withAllTargetsInBuildOrder,
neededTargetsInBuildOrder,
withNeededTargetsInBuildOrder,
) where
import Prelude ()
import Distribution.Compat.Prelude
import Distribution.Types.PackageDescription
import Distribution.Types.ComponentLocalBuildInfo
import Distribution.Types.ComponentRequestedSpec
import Distribution.Types.ComponentId
import Distribution.Types.PackageId
import Distribution.Types.UnitId
import Distribution.Types.TargetInfo
import Distribution.Simple.InstallDirs hiding (absoluteInstallDirs,
prefixRelativeInstallDirs,
substPathTemplate, )
import Distribution.Simple.Program
import Distribution.PackageDescription
import Distribution.Simple.Compiler
import Distribution.Simple.PackageIndex
import Distribution.Simple.Setup
import Distribution.System
import Distribution.Pretty
import Distribution.Compat.Graph (Graph)
import qualified Distribution.Compat.Graph as Graph
import qualified Data.Map as Map
data LocalBuildInfo = LocalBuildInfo {
LocalBuildInfo -> ConfigFlags
configFlags :: ConfigFlags,
LocalBuildInfo -> FlagAssignment
flagAssignment :: FlagAssignment,
LocalBuildInfo -> ComponentRequestedSpec
componentEnabledSpec :: ComponentRequestedSpec,
:: [String],
LocalBuildInfo -> InstallDirTemplates
installDirTemplates :: InstallDirTemplates,
LocalBuildInfo -> Compiler
compiler :: Compiler,
LocalBuildInfo -> Platform
hostPlatform :: Platform,
LocalBuildInfo -> String
buildDir :: FilePath,
LocalBuildInfo -> Maybe String
cabalFilePath :: Maybe FilePath,
LocalBuildInfo -> Graph ComponentLocalBuildInfo
componentGraph :: Graph ComponentLocalBuildInfo,
LocalBuildInfo -> Map ComponentName [ComponentLocalBuildInfo]
componentNameMap :: Map ComponentName [ComponentLocalBuildInfo],
LocalBuildInfo -> InstalledPackageIndex
installedPkgs :: InstalledPackageIndex,
LocalBuildInfo -> Maybe String
pkgDescrFile :: Maybe FilePath,
LocalBuildInfo -> PackageDescription
localPkgDescr :: PackageDescription,
LocalBuildInfo -> ProgramDb
withPrograms :: ProgramDb,
LocalBuildInfo -> PackageDBStack
withPackageDB :: PackageDBStack,
LocalBuildInfo -> Bool
withVanillaLib:: Bool,
LocalBuildInfo -> Bool
withProfLib :: Bool,
LocalBuildInfo -> Bool
withSharedLib :: Bool,
LocalBuildInfo -> Bool
withStaticLib :: Bool,
LocalBuildInfo -> Bool
withDynExe :: Bool,
LocalBuildInfo -> Bool
withFullyStaticExe :: Bool,
LocalBuildInfo -> Bool
withProfExe :: Bool,
LocalBuildInfo -> ProfDetailLevel
withProfLibDetail :: ProfDetailLevel,
LocalBuildInfo -> ProfDetailLevel
withProfExeDetail :: ProfDetailLevel,
LocalBuildInfo -> OptimisationLevel
withOptimization :: OptimisationLevel,
LocalBuildInfo -> DebugInfoLevel
withDebugInfo :: DebugInfoLevel,
LocalBuildInfo -> Bool
withGHCiLib :: Bool,
LocalBuildInfo -> Bool
splitSections :: Bool,
LocalBuildInfo -> Bool
splitObjs :: Bool,
LocalBuildInfo -> Bool
stripExes :: Bool,
LocalBuildInfo -> Bool
stripLibs :: Bool,
LocalBuildInfo -> Bool
exeCoverage :: Bool,
LocalBuildInfo -> Bool
libCoverage :: Bool,
LocalBuildInfo -> PathTemplate
progPrefix :: PathTemplate,
LocalBuildInfo -> PathTemplate
progSuffix :: PathTemplate,
LocalBuildInfo -> Bool
relocatable :: Bool
} deriving (forall x. Rep LocalBuildInfo x -> LocalBuildInfo
forall x. LocalBuildInfo -> Rep LocalBuildInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LocalBuildInfo x -> LocalBuildInfo
$cfrom :: forall x. LocalBuildInfo -> Rep LocalBuildInfo x
Generic, ReadPrec [LocalBuildInfo]
ReadPrec LocalBuildInfo
Int -> ReadS LocalBuildInfo
ReadS [LocalBuildInfo]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LocalBuildInfo]
$creadListPrec :: ReadPrec [LocalBuildInfo]
readPrec :: ReadPrec LocalBuildInfo
$creadPrec :: ReadPrec LocalBuildInfo
readList :: ReadS [LocalBuildInfo]
$creadList :: ReadS [LocalBuildInfo]
readsPrec :: Int -> ReadS LocalBuildInfo
$creadsPrec :: Int -> ReadS LocalBuildInfo
Read, Int -> LocalBuildInfo -> ShowS
[LocalBuildInfo] -> ShowS
LocalBuildInfo -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LocalBuildInfo] -> ShowS
$cshowList :: [LocalBuildInfo] -> ShowS
show :: LocalBuildInfo -> String
$cshow :: LocalBuildInfo -> String
showsPrec :: Int -> LocalBuildInfo -> ShowS
$cshowsPrec :: Int -> LocalBuildInfo -> ShowS
Show, Typeable)
instance Binary LocalBuildInfo
instance Structured LocalBuildInfo
localComponentId :: LocalBuildInfo -> ComponentId
localComponentId :: LocalBuildInfo -> ComponentId
localComponentId LocalBuildInfo
lbi =
case LocalBuildInfo -> ComponentName -> [ComponentLocalBuildInfo]
componentNameCLBIs LocalBuildInfo
lbi (LibraryName -> ComponentName
CLibName LibraryName
LMainLibName) of
[LibComponentLocalBuildInfo { componentComponentId :: ComponentLocalBuildInfo -> ComponentId
componentComponentId = ComponentId
cid }]
-> ComponentId
cid
[ComponentLocalBuildInfo]
_ -> String -> ComponentId
mkComponentId (forall a. Pretty a => a -> String
prettyShow (LocalBuildInfo -> PackageId
localPackage LocalBuildInfo
lbi))
localPackage :: LocalBuildInfo -> PackageId
localPackage :: LocalBuildInfo -> PackageId
localPackage LocalBuildInfo
lbi = PackageDescription -> PackageId
package (LocalBuildInfo -> PackageDescription
localPkgDescr LocalBuildInfo
lbi)
localUnitId :: LocalBuildInfo -> UnitId
localUnitId :: LocalBuildInfo -> UnitId
localUnitId LocalBuildInfo
lbi =
case LocalBuildInfo -> ComponentName -> [ComponentLocalBuildInfo]
componentNameCLBIs LocalBuildInfo
lbi (LibraryName -> ComponentName
CLibName LibraryName
LMainLibName) of
[LibComponentLocalBuildInfo { componentUnitId :: ComponentLocalBuildInfo -> UnitId
componentUnitId = UnitId
uid }]
-> UnitId
uid
[ComponentLocalBuildInfo]
_ -> PackageId -> UnitId
mkLegacyUnitId forall a b. (a -> b) -> a -> b
$ LocalBuildInfo -> PackageId
localPackage LocalBuildInfo
lbi
localCompatPackageKey :: LocalBuildInfo -> String
localCompatPackageKey :: LocalBuildInfo -> String
localCompatPackageKey LocalBuildInfo
lbi =
case LocalBuildInfo -> ComponentName -> [ComponentLocalBuildInfo]
componentNameCLBIs LocalBuildInfo
lbi (LibraryName -> ComponentName
CLibName LibraryName
LMainLibName) of
[LibComponentLocalBuildInfo { componentCompatPackageKey :: ComponentLocalBuildInfo -> String
componentCompatPackageKey = String
pk }]
-> String
pk
[ComponentLocalBuildInfo]
_ -> forall a. Pretty a => a -> String
prettyShow (LocalBuildInfo -> PackageId
localPackage LocalBuildInfo
lbi)
mkTargetInfo :: PackageDescription -> LocalBuildInfo -> ComponentLocalBuildInfo -> TargetInfo
mkTargetInfo :: PackageDescription
-> LocalBuildInfo -> ComponentLocalBuildInfo -> TargetInfo
mkTargetInfo PackageDescription
pkg_descr LocalBuildInfo
_lbi ComponentLocalBuildInfo
clbi =
TargetInfo {
targetCLBI :: ComponentLocalBuildInfo
targetCLBI = ComponentLocalBuildInfo
clbi,
targetComponent :: Component
targetComponent = PackageDescription -> ComponentName -> Component
getComponent PackageDescription
pkg_descr
(ComponentLocalBuildInfo -> ComponentName
componentLocalName ComponentLocalBuildInfo
clbi)
}
componentNameTargets' :: PackageDescription -> LocalBuildInfo -> ComponentName -> [TargetInfo]
componentNameTargets' :: PackageDescription
-> LocalBuildInfo -> ComponentName -> [TargetInfo]
componentNameTargets' PackageDescription
pkg_descr LocalBuildInfo
lbi ComponentName
cname =
case forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup ComponentName
cname (LocalBuildInfo -> Map ComponentName [ComponentLocalBuildInfo]
componentNameMap LocalBuildInfo
lbi) of
Just [ComponentLocalBuildInfo]
clbis -> forall a b. (a -> b) -> [a] -> [b]
map (PackageDescription
-> LocalBuildInfo -> ComponentLocalBuildInfo -> TargetInfo
mkTargetInfo PackageDescription
pkg_descr LocalBuildInfo
lbi) [ComponentLocalBuildInfo]
clbis
Maybe [ComponentLocalBuildInfo]
Nothing -> []
unitIdTarget' :: PackageDescription -> LocalBuildInfo -> UnitId -> Maybe TargetInfo
unitIdTarget' :: PackageDescription -> LocalBuildInfo -> UnitId -> Maybe TargetInfo
unitIdTarget' PackageDescription
pkg_descr LocalBuildInfo
lbi UnitId
uid =
case forall a. IsNode a => Key a -> Graph a -> Maybe a
Graph.lookup UnitId
uid (LocalBuildInfo -> Graph ComponentLocalBuildInfo
componentGraph LocalBuildInfo
lbi) of
Just ComponentLocalBuildInfo
clbi -> forall a. a -> Maybe a
Just (PackageDescription
-> LocalBuildInfo -> ComponentLocalBuildInfo -> TargetInfo
mkTargetInfo PackageDescription
pkg_descr LocalBuildInfo
lbi ComponentLocalBuildInfo
clbi)
Maybe ComponentLocalBuildInfo
Nothing -> forall a. Maybe a
Nothing
componentNameCLBIs :: LocalBuildInfo -> ComponentName -> [ComponentLocalBuildInfo]
componentNameCLBIs :: LocalBuildInfo -> ComponentName -> [ComponentLocalBuildInfo]
componentNameCLBIs LocalBuildInfo
lbi ComponentName
cname =
case forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup ComponentName
cname (LocalBuildInfo -> Map ComponentName [ComponentLocalBuildInfo]
componentNameMap LocalBuildInfo
lbi) of
Just [ComponentLocalBuildInfo]
clbis -> [ComponentLocalBuildInfo]
clbis
Maybe [ComponentLocalBuildInfo]
Nothing -> []
allTargetsInBuildOrder' :: PackageDescription -> LocalBuildInfo -> [TargetInfo]
allTargetsInBuildOrder' :: PackageDescription -> LocalBuildInfo -> [TargetInfo]
allTargetsInBuildOrder' PackageDescription
pkg_descr LocalBuildInfo
lbi
= forall a b. (a -> b) -> [a] -> [b]
map (PackageDescription
-> LocalBuildInfo -> ComponentLocalBuildInfo -> TargetInfo
mkTargetInfo PackageDescription
pkg_descr LocalBuildInfo
lbi) (forall a. Graph a -> [a]
Graph.revTopSort (LocalBuildInfo -> Graph ComponentLocalBuildInfo
componentGraph LocalBuildInfo
lbi))
withAllTargetsInBuildOrder' :: PackageDescription -> LocalBuildInfo -> (TargetInfo -> IO ()) -> IO ()
withAllTargetsInBuildOrder' :: PackageDescription
-> LocalBuildInfo -> (TargetInfo -> IO ()) -> IO ()
withAllTargetsInBuildOrder' PackageDescription
pkg_descr LocalBuildInfo
lbi TargetInfo -> IO ()
f
= forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, Monad m) =>
t (m a) -> m ()
sequence_ [ TargetInfo -> IO ()
f TargetInfo
target | TargetInfo
target <- PackageDescription -> LocalBuildInfo -> [TargetInfo]
allTargetsInBuildOrder' PackageDescription
pkg_descr LocalBuildInfo
lbi ]
neededTargetsInBuildOrder' :: PackageDescription -> LocalBuildInfo -> [UnitId] -> [TargetInfo]
neededTargetsInBuildOrder' :: PackageDescription -> LocalBuildInfo -> [UnitId] -> [TargetInfo]
neededTargetsInBuildOrder' PackageDescription
pkg_descr LocalBuildInfo
lbi [UnitId]
uids =
case forall a. Graph a -> [Key a] -> Maybe [a]
Graph.closure (LocalBuildInfo -> Graph ComponentLocalBuildInfo
componentGraph LocalBuildInfo
lbi) [UnitId]
uids of
Maybe [ComponentLocalBuildInfo]
Nothing -> forall a. HasCallStack => String -> a
error forall a b. (a -> b) -> a -> b
$ String
"localBuildPlan: missing uids " forall a. [a] -> [a] -> [a]
++ forall a. [a] -> [[a]] -> [a]
intercalate String
", " (forall a b. (a -> b) -> [a] -> [b]
map forall a. Pretty a => a -> String
prettyShow [UnitId]
uids)
Just [ComponentLocalBuildInfo]
clos -> forall a b. (a -> b) -> [a] -> [b]
map (PackageDescription
-> LocalBuildInfo -> ComponentLocalBuildInfo -> TargetInfo
mkTargetInfo PackageDescription
pkg_descr LocalBuildInfo
lbi) (forall a. Graph a -> [a]
Graph.revTopSort (forall a. (IsNode a, Show (Key a)) => [a] -> Graph a
Graph.fromDistinctList [ComponentLocalBuildInfo]
clos))
withNeededTargetsInBuildOrder' :: PackageDescription -> LocalBuildInfo -> [UnitId] -> (TargetInfo -> IO ()) -> IO ()
withNeededTargetsInBuildOrder' :: PackageDescription
-> LocalBuildInfo -> [UnitId] -> (TargetInfo -> IO ()) -> IO ()
withNeededTargetsInBuildOrder' PackageDescription
pkg_descr LocalBuildInfo
lbi [UnitId]
uids TargetInfo -> IO ()
f
= forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, Monad m) =>
t (m a) -> m ()
sequence_ [ TargetInfo -> IO ()
f TargetInfo
target | TargetInfo
target <- PackageDescription -> LocalBuildInfo -> [UnitId] -> [TargetInfo]
neededTargetsInBuildOrder' PackageDescription
pkg_descr LocalBuildInfo
lbi [UnitId]
uids ]
testCoverage :: LocalBuildInfo -> Bool
testCoverage :: LocalBuildInfo -> Bool
testCoverage LocalBuildInfo
lbi = LocalBuildInfo -> Bool
exeCoverage LocalBuildInfo
lbi Bool -> Bool -> Bool
&& LocalBuildInfo -> Bool
libCoverage LocalBuildInfo
lbi
{-# WARNING componentNameTargets, unitIdTarget, allTargetsInBuildOrder, withAllTargetsInBuildOrder, neededTargetsInBuildOrder, withNeededTargetsInBuildOrder "By using this function, you may be introducing a bug where you retrieve a 'Component' which does not have 'HookedBuildInfo' applied to it. See the documentation for 'HookedBuildInfo' for an explanation of the issue. If you have a 'PackageDescription' handy (NOT from the 'LocalBuildInfo'), try using the primed version of the function, which takes it as an extra argument." #-}
componentNameTargets :: LocalBuildInfo -> ComponentName -> [TargetInfo]
componentNameTargets :: LocalBuildInfo -> ComponentName -> [TargetInfo]
componentNameTargets LocalBuildInfo
lbi = PackageDescription
-> LocalBuildInfo -> ComponentName -> [TargetInfo]
componentNameTargets' (LocalBuildInfo -> PackageDescription
localPkgDescr LocalBuildInfo
lbi) LocalBuildInfo
lbi
unitIdTarget :: LocalBuildInfo -> UnitId -> Maybe TargetInfo
unitIdTarget :: LocalBuildInfo -> UnitId -> Maybe TargetInfo
unitIdTarget LocalBuildInfo
lbi = PackageDescription -> LocalBuildInfo -> UnitId -> Maybe TargetInfo
unitIdTarget' (LocalBuildInfo -> PackageDescription
localPkgDescr LocalBuildInfo
lbi) LocalBuildInfo
lbi
allTargetsInBuildOrder :: LocalBuildInfo -> [TargetInfo]
allTargetsInBuildOrder :: LocalBuildInfo -> [TargetInfo]
allTargetsInBuildOrder LocalBuildInfo
lbi = PackageDescription -> LocalBuildInfo -> [TargetInfo]
allTargetsInBuildOrder' (LocalBuildInfo -> PackageDescription
localPkgDescr LocalBuildInfo
lbi) LocalBuildInfo
lbi
withAllTargetsInBuildOrder :: LocalBuildInfo -> (TargetInfo -> IO ()) -> IO ()
withAllTargetsInBuildOrder :: LocalBuildInfo -> (TargetInfo -> IO ()) -> IO ()
withAllTargetsInBuildOrder LocalBuildInfo
lbi = PackageDescription
-> LocalBuildInfo -> (TargetInfo -> IO ()) -> IO ()
withAllTargetsInBuildOrder' (LocalBuildInfo -> PackageDescription
localPkgDescr LocalBuildInfo
lbi) LocalBuildInfo
lbi
neededTargetsInBuildOrder :: LocalBuildInfo -> [UnitId] -> [TargetInfo]
neededTargetsInBuildOrder :: LocalBuildInfo -> [UnitId] -> [TargetInfo]
neededTargetsInBuildOrder LocalBuildInfo
lbi = PackageDescription -> LocalBuildInfo -> [UnitId] -> [TargetInfo]
neededTargetsInBuildOrder' (LocalBuildInfo -> PackageDescription
localPkgDescr LocalBuildInfo
lbi) LocalBuildInfo
lbi
withNeededTargetsInBuildOrder :: LocalBuildInfo -> [UnitId] -> (TargetInfo -> IO ()) -> IO ()
withNeededTargetsInBuildOrder :: LocalBuildInfo -> [UnitId] -> (TargetInfo -> IO ()) -> IO ()
withNeededTargetsInBuildOrder LocalBuildInfo
lbi = PackageDescription
-> LocalBuildInfo -> [UnitId] -> (TargetInfo -> IO ()) -> IO ()
withNeededTargetsInBuildOrder' (LocalBuildInfo -> PackageDescription
localPkgDescr LocalBuildInfo
lbi) LocalBuildInfo
lbi