Sorry about the late reply, I just wanted to make sure things would
actually work out.
On Fri, Apr 29, 2016 at 6:11 AM, Neil Mitchell <
ndmit...@gmail.com> wrote:
> Hi Evan,
>
>> It gets the transitive imports
>
> How does it get the transitive imports? Does it `ghc -M` to produce a
> Makefile? Or scan through looking for lines beginning with import?
The latter. At the time I don't remember if I thought it would be
faster than ghc -M or just didn't know about ghc -M. Given a Map
ModuleName Package of course I can also get the packages required.
That map is available from ghc-pkg, though I might have to cache that,
and rebuild manually whenever the package situation changes. Though,
as I actually want the explicit list as discussed below, I don't think
I need to bother with all that.
> Given it sounds like your existing design works well for you, I'd
> consider what you can keep for now. The packages a file uses are
> entirely driven by its imports. If you are using `ghc -M` there is a
> flag -include-pkg-deps which will give you exactly what packages a
> module imports. If you are using import scanning, you could have a
> list of modules that imply the "heavy" modules - e.g. if something
> imports Network.Wai.Handler.Warp it must depend on the warp package.
Finding the dependents isn't the problem, it's that the o-rule needs
to know the packages. For that I wrote a inferPackages :: FilePath ->
[Package] which looks at the directory to figure out the packages.
This is what I was considering "morally equivalent" to a Library {
srcs = "A/**/*.hs", deps = [package1, package2, ...] }.
The problem is then about the "global" targets, e.g. haddock
generation. Instead of just **/*.hs, I need only the source files
that can be compiled given the installed packages (not sure why
haddock needs the package, but it does). This means start with the
enabled binaries and chase down their sources. Which I guess I can
also do perfectly well with the import chaser.
So, I implemented that, and it seems like it works, just with the
tradeoff that it's a lot slower than just getting **/*.hs. But if
libraries are explicitly declared then I can replace that with
A/**/*.hs or whatever.
So it still seems like an explicit Library type is the cleanest
approach. With filename globbing for the srcs list, it doesn't really
duplicate any information I wouldn't have to explicitly write anyway,
since no matter what I need a way to map a source file to a package
list. Or if I explicitly limit srcs to be a directory and contain all
*.hs files underneath, then I can generate haddock for or collect
tests from that library just with filename globbing.
Perhaps if it works out nicely I'll try to extract the generalized
bits into a reusable framework.