Fix missing dependencies for Stage2 packages
[ghc.git] / src / Oracles / PackageDeps.hs
1 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
2 module Oracles.PackageDeps (packageDeps, packageDepsOracle) where
3
4 import qualified Data.HashMap.Strict as Map
5
6 import Base
7 import Package
8 import Settings.Paths
9
10 newtype PackageDepsKey = PackageDepsKey String
11 deriving (Show, Typeable, Eq, Hashable, Binary, NFData)
12
13 -- @packageDeps name@ is an action that given a 'Package' looks up its
14 -- dependencies in 'Base.packageDependencies' file. The dependencies need to be
15 -- computed by scanning package cabal files (see Rules.Cabal).
16 packageDeps :: Package -> Action [PackageName]
17 packageDeps pkg = do
18 res <- askOracle . PackageDepsKey $ pkgNameString pkg
19 return . map PackageName $ fromMaybe [] res
20
21 -- Oracle for the package dependencies file
22 packageDepsOracle :: Rules ()
23 packageDepsOracle = do
24 deps <- newCache $ \_ -> do
25 putLoud $ "Reading package dependencies..."
26 contents <- readFileLines packageDependencies
27 return . Map.fromList $
28 [ (p, ps) | line <- contents, let p:ps = words line ]
29 _ <- addOracle $ \(PackageDepsKey pkg) -> Map.lookup pkg <$> deps ()
30 return ()