Import if/ELSE
- Dominant language
- Haskell
- Stars
- 1.7k
- Forks
- 750
- Avg merge
- 4d 3h
- Merged PRs (30d)
- 28
Description
**Describe the bug**
I would like to be able to use `else` clauses in `import-if` statements.
Related issue: https://github.com/haskell/cabal/issues/5563
Related PR: https://github.com/haskell/cabal/pull/5566
**To Reproduce**
A reasonably short repro is
```cabal
cabal-version: 2.4
name: cabal-import-if
version: 0.1.0.0
flag some-flag
description:
default: False
manual: True
common common-1
build-depends: aeson
common common-2
build-depends: aeson-lens
executable cabal-import-if
if flag(some-flag)
import: common-1
else
import: common-1, common-2
main-is: Main.hs
build-depends: base ^>=4.14.3.0
hs-source-dirs: app
default-language: Haskell2010
```
**Expected behavior**
Just having the `if` works, but adding the `else` results in a warning and ignoring the imports altogether.
**System information**
- cabal 3.6.2.0
**Additional context**
For context, I am trying to work around the no multiple home units limitation. I am doing this because I want to be able to quickly run unit tests while editing both my lib and test units, i.e.:
- reload/recompile fast when I make changes to lib
- reload/recompile fast when I make changes to test
- run unit tests by reloading the test Main file and running it
I was able to accomplish this by:
- adding `src` to the test stanza's `hs-source-dirs`
- copy over all `build-depends` from `lib` to `test` (they were transitive dependencies anyway)
The above allows me to run something like
```sh
$ ghcid -a -c "cabal repl my-test-stanza -f -O0" --test Main.main
```
and accomplish all I needed (i.e., fast reloads, run tests).
The problem now becomes, I would like to clean this up:
- I dislike repeating the `build-depends`
- I would rather have a flag that does the above and the addition to the tests' `hs-source-dirs`
So the way I tried was:
- create a common stanza with the lib's `build-depends`
- create a new flag
- use that flag in test
The only problem is, the `test` stanza already has some common imports, so I can't merge them. I also can't move the if/else to the stanza, because I specifically need it to be always imported in `lib` but only when `flag` is set to `test.
Contributor guide
Research direction
Start with the minimal Cabal configuration in the issue and reproduce the warning using cabal 3.6.2.0; then read related issue #5563 and PR #5566 for prior context. Done means an import-if statement accepts an else clause, applies the selected imports, and no longer ignores them with a warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100