Discovery of source dependencies without --make

Lars Hupel lars at hupel.info
Tue Nov 25 09:36:53 UTC 2014


(cross-posted from [haskell-cafe])

Hi,

I've got a problem in our – admittedly complex – build process. We're
running an automated grading system for student-submitted homework
exercises. The compilation proceeds in stages:

1) Compile a library file, marked as trustworthy
2) Compile student submissions using Safe Haskell, able to access a
whitelisted set of packages and the previously compiled library files
3) Compile the test suite
4) Link everything together into an executable

The invocation is similar to this:

ghc -c -outputdir "$OUT"          -XTrustworthy Library.hs
ghc -c -outputdir "$OUT" -i"$OUT" -XSafe "$SUBMISSION"
ghc -c -outputdir "$OUT" -i"$OUT" Test_Suite.hs
ghc    -outputdir "$OUT" -i"$OUT" -o "$OUT/runner"

The second stage works well under the assumption that there's just one
single submitted file. If there's more than one, I need to specify them
in topological order wrt their module dependencies. Consider two simple
modules:

A.hs
> module A where
>
> import B
> import Library

B.hs
> module B where

Invoking GHC with "A.hs" "B.hs" will fail:

A.hs:3:1:
    Failed to load interface for ‘B’

My naive attempt at solving that problem was to just insert "--make"
into the compiler flags. No luck, because according to [1, §4.7.3],
"--make" will only look at source files and will ignore the "Library.hi"
file from the previous compilation stage. If I give the path to
"Library.hs" as well, GHC insists on recompiling it with changed flags
("-XSafe" instead of "-XTrustworthy").

Reading a bit further, I discovered the '-M' flag, however, not only
does it output Makefile-formatted output, it also ignores .hi files.

Is there any way to get the dependency discovery of '--make' without the
rest?

I know I could probably make it work if I made a package out of the
first build stage, but I really want to avoid that in order to not
increase the build complexity even further.

Cheers
Lars


[1]
<https://downloads.haskell.org/~ghc/7.6.3/docs/html/users_guide/separate-compilation.html#search-path>


More information about the Glasgow-haskell-users mailing list