<commit_before>module Rules.Dependencies (buildPackageDependencies) where

import Expression
import Oracles
import Rules.Actions
import Rules.Resources
import Settings

buildPackageDependencies :: Resources -> PartialTarget -> Rules ()
buildPackageDependencies _ target @ (PartialTarget stage pkg) =
    let path      = targetPath stage pkg
        buildPath = path -/- "build"
        dropBuild = (pkgPath pkg ++) . drop (length buildPath)
        hDepFile  = buildPath -/- ".hs-dependencies"
    in do
        (buildPath <//> "*.c.deps") %> \out -> do
            let srcFile = dropBuild . dropExtension $ out
            need [srcFile]
            build $ fullTarget target (GccM stage) [srcFile] [out]

        hDepFile %> \file -> do
            srcs <- interpretPartial target getPackageSources
            need srcs
            build $ fullTarget target (GhcM stage) srcs [file]
            removeFileIfExists $ file <.> "bak"

        (buildPath -/- ".dependencies") %> \file -> do
            cSrcs <- pkgDataList $ CSrcs path
            let cDepFiles = [ buildPath -/- src <.> "deps" | src <- cSrcs ]
            need $ hDepFile : cDepFiles -- need all for more parallelism
            cDeps <- fmap concat $ mapM readFile' cDepFiles
            hDeps <- readFile' hDepFile
            writeFileChanged file $ cDeps ++ hDeps
<commit_msg>Fix untracked .hs-incl dependencies.<commit_after>module Rules.Dependencies (buildPackageDependencies) where

import Expression
import GHC
import Oracles
import Rules.Actions
import Rules.Resources
import Settings

buildPackageDependencies :: Resources -> PartialTarget -> Rules ()
buildPackageDependencies _ target @ (PartialTarget stage pkg) =
    let path      = targetPath stage pkg
        buildPath = path -/- "build"
        dropBuild = (pkgPath pkg ++) . drop (length buildPath)
        hDepFile  = buildPath -/- ".hs-dependencies"
    in do
        (buildPath <//> "*.c.deps") %> \out -> do
            let srcFile = dropBuild . dropExtension $ out
            need [srcFile]
            build $ fullTarget target (GccM stage) [srcFile] [out]

        hDepFile %> \file -> do
            srcs <- interpretPartial target getPackageSources
            need srcs
            build $ fullTarget target (GhcM stage) srcs [file]
            removeFileIfExists $ file <.> "bak"

        (buildPath -/- ".dependencies") %> \file -> do
            cSrcs <- pkgDataList $ CSrcs path
            let cDepFiles = [ buildPath -/- src <.> "deps" | src <- cSrcs ]
            need $ hDepFile : cDepFiles -- need all for more parallelism
            cDeps <- fmap concat $ mapM readFile' cDepFiles
            hDeps <- readFile' hDepFile
            -- TODO: very ugly and fragile
            let hsIncl hs incl = buildPath -/- hs <.> "o" ++ " : "
                              ++ buildPath -/- incl ++ "\n"
                extraDeps = if pkg /= compiler then [] else
                       hsIncl "PrelNames" "primop-vector-uniques.hs-incl"
                    ++ hsIncl "PrimOp"    "primop-data-decl.hs-incl"
                    ++ hsIncl "PrimOp"    "primop-tag.hs-incl"
                    ++ hsIncl "PrimOp"    "primop-list.hs-incl"
                    ++ hsIncl "PrimOp"    "primop-strictness.hs-incl"
                    ++ hsIncl "PrimOp"    "primop-fixity.hs-incl"
                    ++ hsIncl "PrimOp"    "primop-primop-info.hs-incl"
                    ++ hsIncl "PrimOp"    "primop-out-of-line.hs-incl"
                    ++ hsIncl "PrimOp"    "primop-has-side-effects.hs-incl"
                    ++ hsIncl "PrimOp"    "primop-can-fail.hs-incl"
                    ++ hsIncl "PrimOp"    "primop-code-size.hs-incl"
                    ++ hsIncl "PrimOp"    "primop-commutable.hs-incl"
                    ++ hsIncl "TysPrim"   "primop-vector-tys-exports.hs-incl"
                    ++ hsIncl "TysPrim"   "primop-vector-tycons.hs-incl"
                    ++ hsIncl "TysPrim"   "primop-vector-tys.hs-incl"
            writeFileChanged file $ cDeps ++ hDeps ++ extraDeps

{'fraction_non_alphanumeric': 0.1115527950310559, 'fraction_numerical': 0.0, 'mean_word_length': 1.799721835883171, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2852160', 'n_tokens_mistral': 1244, 'n_tokens_neox': 1171, 'n_words': 302}