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