9589d12aa0f200478496a0934e2e0709f311683d
[ghc.git] / hadrian / src / Rules / Dependencies.hs
1 module Rules.Dependencies (buildPackageDependencies) where
2
3 import Data.Bifunctor
4 import Data.Function
5
6 import Base
7 import Context
8 import Expression
9 import Oracles.ModuleFiles
10 import Rules.Generate
11 import Target
12 import Utilities
13
14 buildPackageDependencies :: [(Resource, Int)] -> Context -> Rules ()
15 buildPackageDependencies rs context@Context {..} = do
16 root <- buildRootRules
17 root -/- contextDir context -/- ".dependencies.mk" %> \mk -> do
18 srcs <- hsSources context
19 need srcs
20 orderOnly =<< interpretInContext context generatedDependencies
21 if null srcs
22 then writeFileChanged mk ""
23 else buildWithResources rs $
24 target context (Ghc FindHsDependencies stage) srcs [mk]
25 removeFile $ mk <.> "bak"
26
27 root -/- contextDir context -/- ".dependencies" %> \deps -> do
28 mkDeps <- readFile' (deps <.> "mk")
29 writeFileChanged deps . unlines
30 . map (\(src, deps) -> unwords $ src : deps)
31 . map (bimap unifyPath (map unifyPath))
32 . map (bimap head concat . unzip)
33 . groupBy ((==) `on` fst)
34 . sortBy (compare `on` fst)
35 $ parseMakefile mkDeps