Skip to content

Cabal should pass filenames, not module names, to GHC #4350

Open

Description

@simonmar

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

Activity

  1. added this to the 2.2 milestone on Feb 21, 2017
  2. ezyang commented on Feb 21, 2017

    @ezyang
    Contributor

    It is a bit funny because we recently merged http://ghc.haskell.org/trac/ghc/ticket/13129 to help detect when a module isn't listed in other-modules, but it's definitely true that clearing the import list and then explicitly saying where all the files are would work too. This would require Cabal to know how to search the include directories for the source files, but it already knows that.

    One concern is that this is a BC-breaking change; for example, cabal-install used to rely on the fact that you would rebuild the modules picked up from the source dirs to run the library with assertions enabled, even if the "real" library hadn't been built with assertions. Maybe we can figure out some feature switch to toggle this behavior (cabal-version? Something else?)

  3. modified the milestones: 2.2, 2.4 on Aug 29, 2018
  4. modified the milestones: 2.4, 2.4.1 on Sep 17, 2018
  5. modified the milestones: 2.4.1.0, 2.4.2.0 on Apr 26, 2019
  6. modified the milestones: 2.4.2.0, 3.4 on Nov 27, 2019
  7. removed this from the Considered for 3.4 milestone on Sep 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions