Search code examples
haskellcabalsdist

cabal new-sdist includes test files as well


I want to create an sdist package for my Haskell project. For simplicity let's assume the following project structure:

/ root
  | src
    | MyLib.hs
  | test
    | MyLibTest.hs
  | Changelog.md
  | MyProject.cabal
  | LICENSE

There are two targets defined in the cabal file

library
  exposed-modules:    MyLib
  hs-source-dirs:     src
  -- ...

test-suite: MyProject-test
  type:               exitcode-stdio-1.0
  hs-source-dirs:     test
  main-is:            MyLibTest.hs
  -- ...

When I execute cabal new-sdist --list-only I get the following list:

./changelog.md
./MyProject.cabal
./LICENSE
./src/MyLib.hs
./test/MyLibTest.hs

My question: is it ok to include the test-related files in the sdist package or shall I remove them (if so - how)?


Solution

  • Well if you try to generate a library-only sdist, you get this error:

    $ cabal new-sdist --list-only <library-name>
    cabal: The component library cannot be packaged for distribution on its own.
    Only entire packages may be packaged for distribution.
    

    So I'd say it's recommended to upload the whole thing.

    Hackage does let you preview a library before publishing it, using package candidates. I'd say upload your source tarball as a package candidate, and double check your tests don't show up.