haskell / haskell/cabal

Cabal should pass filenames, not module names, to GHC

Open
#4,350 1 comment 0 reactions 0 assignees View on GitHub
type: discussion type: enhancement
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

So here's the problem: suppose you want to have the source files for your unit tests next to the source files for your library. e.g. `Foo.Bar` is the library module, and `Foo.Bar.Tests` is a test suite source file. If you have a *lot* of source files in a deep hierarchy, this layout makes sense, because you don't have to duplicate the directory hierarchy.

You've already listed all the modules in the `.cabal` file, and the sets of modules for the library are disjoint from those for the test suite. Cabal knows exactly which source files correspond to each module.

But, when we invoke GHC, we do it like this:

```
ghc -i. Foo.Bar.Tests -package foo
```

and GHC finds `Foo.Bar` on the search path instead of in the compiled `foo` package. Furthermore, it complains that you haven't added `Foo.Bar` to the `other-modules` field in the test suite. But there's no need for this, we could instead do

```
ghc -i Foo/Bar/Tests.hs -package foo
```

and everything would be fine. It would be less fragile too: if you forgot to list some modules in `other-modules`, GHC won't find them.

CC @JonCoens

Contributor guide

Open the contributing guide

Research direction

Start by locating the Cabal code that assembles the GHC command for test suites, using the .cabal module lists and the Foo/Bar/Tests.hs example as context. Compare the current module-name invocation with the requested filename-based invocation, and verify that the library module is resolved from the compiled package without requiring an unnecessary other-modules entry.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.