summaryrefslogtreecommitdiff
path: root/hadrian/src/Rules/Dependencies.hs
diff options
context:
space:
mode:
Diffstat (limited to 'hadrian/src/Rules/Dependencies.hs')
-rw-r--r--hadrian/src/Rules/Dependencies.hs35
1 files changed, 35 insertions, 0 deletions
diff --git a/hadrian/src/Rules/Dependencies.hs b/hadrian/src/Rules/Dependencies.hs
new file mode 100644
index 0000000000..9589d12aa0
--- /dev/null
+++ b/hadrian/src/Rules/Dependencies.hs
@@ -0,0 +1,35 @@
+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 {..} = do
+ root <- buildRootRules
+ root -/- contextDir context -/- ".dependencies.mk" %> \mk -> do
+ srcs <- hsSources context
+ need srcs
+ orderOnly =<< interpretInContext context generatedDependencies
+ if null srcs
+ then writeFileChanged mk ""
+ else buildWithResources rs $
+ target context (Ghc FindHsDependencies stage) srcs [mk]
+ removeFile $ mk <.> "bak"
+
+ root -/- contextDir context -/- ".dependencies" %> \deps -> do
+ mkDeps <- readFile' (deps <.> "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