Version 2 (modified by pgavin@…, 6 years ago)

--

Dependency Analysis in Cabal

Please put your ideas & discussion about Cabal dependency analysis here.

ndm's idea

Duncan posted this on hpaste; I'm pasting it here as a starting point.

data Rule {
  targets :: [FilePath],
  dependencies :: [FilePath],
  dynamicDependencies :: Maybe (IO [FilePath]),
  action :: IO ()
}

The semantics are that to generate a set of particular target files we ensure that all the static dependencies are up to date, then if there are any dynamic dependencies we check those are up to date too and finally run the action.

The need for dynamic dependencies is for automatically generating deps by reading a file to look for imports.

So for example:

Two source files: Foo.hs, Bar.hs. Module Foo imports Bar.

So we have some static and dynamic deps, we generate the dynamic deps and put them in a .dep file (or we bundle them alltogether in an appropriate cache file. It doesn't matter for the abstract setup.)

Foo.hs.dep -- contains deps of Foo as a [FilePath?] Bar.hs.dep -- similarly

Foo.hs.dep is generated from Foo.hs

So we'd actually have 4 Rules:

foo_hs_dep = Rule { 
    dependencies = ["Foo.hs"],
    targets = ["Foo.hs.dep"],
    action = generateDepsFor "Foo.hs",
    dynamicDependencies = Nothing
  }

foo_hs = Rule {
  dependencies = ["Foo.hs", "Foo.hs.dep"],
  targets = ["Foo.o", "Foo.hi"]
  action = compile "Foo.hs"
  dynamicDependencies = Just (readCachedDepsFrom "Foo.hs.dep")
}