sdist ships (duplicate) generated modules in the source directories
- Dominant language
- Haskell
- Stars
- 1.7k
- Forks
- 750
- Avg merge
- 4d 3h
- Merged PRs (30d)
- 28
Description
Originating from https://github.com/haskell/cabal/issues/7251#issuecomment-767487524 :
**`cabal sdist` includes useless, possibly generated modules in the package**
Scenario:
- Say I have in my modules in `src/` a module `M` that is generated from `M.x` (alex lexer generator source file).
- I run `alex M.x` in `src`, generating `M.hs` there.
- Now module `M` is formally ambiguous, but `cabal build` will ignore the `M.hs` and use `M.x`.
- However, `sdist` will include `M.hs` in the package.
- I can even put arbitrary garbage into `M.hs` that will ignore in the `build`, but still be shipped with `sdist`.
**Enhancement request:**
- If a module resolves to several source files, only `sdist` those that will actually be used by `build`.
**To Reproduce**
Steps to reproduce the behavior (uses BNFC and PR #7251):
[Without PR #7251, you might have to fix up the generated .cabal file.]
```
bnfc --version || cabal install BNFC
mkdir -p myparser
cd myparser
echo "Foo. Bar ::= Integer" > Foo.cf
bnfc -o src -d -m Foo.cf
make -C src
mv src/Foo/Test.hs Main.hs
cabal init --libandexe --application-dir=.
cabal sdist
find . -name "*.tar.gz" -exec tar tf {} \;
```
Notice the content of the generated archive with the redundant `.hs` files:
```
myparser-0.1.0.0/src/Foo/Lex.hs
myparser-0.1.0.0/src/Foo/Lex.x
myparser-0.1.0.0/src/Foo/Par.hs
myparser-0.1.0.0/src/Foo/Par.y
```
**System information**
- `cabal` 3.5.0.0
- `ghc` 8.10.3
Contributor guide
Assessment
This issue has not been assessed yet.