Look up build tools packages based on executables (fixes #30)

This commit is contained in:
Michael Snoyman 2013-01-23 13:45:53 +02:00
parent 024e873af2
commit df836f406e
3 changed files with 24 additions and 6 deletions

View File

@ -7,10 +7,12 @@ module Stackage.Build
import Control.Exception (assert)
import Control.Monad (unless, when)
import qualified Data.Map as Map
import Data.Maybe (mapMaybe)
import Data.Set (empty)
import qualified Data.Set as Set
import Distribution.Text (simpleParse)
import Distribution.Version (withinRange)
import Prelude hiding (pi)
import Stackage.CheckPlan
import Stackage.Config
import Stackage.InstallInfo
@ -142,7 +144,7 @@ iiBuildTools InstallInfo { iiPackageDB = PackageDB m, iiPackages = packages } =
-- tools themselves, and install them in the correct order.
map unPackageName
$ filter (flip Set.notMember coreTools)
$ filter (flip Map.member m)
$ mapMaybe (flip Map.lookup buildToolMap)
$ Set.toList
$ Set.unions
$ map piBuildTools
@ -156,3 +158,11 @@ iiBuildTools InstallInfo { iiPackageDB = PackageDB m, iiPackages = packages } =
-- Build tools shipped with GHC which we should not attempt to build
-- ourselves.
coreTools = Set.fromList $ map PackageName $ words "hsc2hs"
-- The map from build tool name to the package it comes from.
buildToolMap = Map.unions $ map toBuildToolMap $ Map.toList m
toBuildToolMap :: (PackageName, PackageInfo) -> Map Executable PackageName
toBuildToolMap (pn, pi) = Map.unions
$ map (flip Map.singleton pn)
$ Set.toList
$ piExecs pi

View File

@ -71,13 +71,14 @@ loadPackageDB settings core deps = do
_ ->
case Tar.entryContent e of
Tar.NormalFile bs _ -> do
let (deps', hasTests, buildTools', mgpd) = parseDeps bs
let (deps', hasTests, buildTools', mgpd, execs) = parseDeps bs
return $ mappend pdb $ PackageDB $ Map.singleton p PackageInfo
{ piVersion = v
, piDeps = deps'
, piHasTests = hasTests
, piBuildTools = buildTools'
, piGPD = mgpd
, piExecs = execs
}
_ -> return pdb
@ -89,8 +90,11 @@ loadPackageDB settings core deps = do
, mconcat $ map (go gpd . snd) $ condTestSuites gpd
, mconcat $ map (go gpd . snd) $ condBenchmarks gpd
], not $ null $ condTestSuites gpd
, Set.fromList $ map depName $ allBuildInfo gpd, Just gpd)
_ -> (mempty, defaultHasTestSuites, Set.empty, Nothing)
, Set.fromList $ map depName $ allBuildInfo gpd
, Just gpd
, Set.fromList $ map (Executable . fst) $ condExecutables gpd
)
_ -> (mempty, defaultHasTestSuites, Set.empty, Nothing, Set.empty)
where
allBuildInfo gpd = concat
[ maybe mempty (goBI libBuildInfo) $ condLibrary gpd
@ -100,7 +104,7 @@ loadPackageDB settings core deps = do
]
where
goBI f x = buildTools $ f $ condTreeData x
depName (Dependency p _) = p
depName (Dependency (PackageName p) _) = Executable p
go gpd tree
= Map.unionsWith unionVersionRanges
$ Map.fromList (map (\(Dependency p vr) -> (p, vr)) $ condTreeConstraints tree)

View File

@ -30,11 +30,15 @@ data PackageInfo = PackageInfo
{ piVersion :: Version
, piDeps :: Map PackageName VersionRange
, piHasTests :: Bool
, piBuildTools :: Set PackageName
, piBuildTools :: Set Executable
, piGPD :: Maybe GenericPackageDescription
, piExecs :: Set Executable
}
deriving (Show, Eq)
newtype Executable = Executable String
deriving (Show, Eq, Ord)
-- | Information on a package we're going to build.
data BuildInfo = BuildInfo
{ biVersion :: Version