-
Notifications
You must be signed in to change notification settings - Fork 725
Description
Describe the bug
I would like to be able to use else clauses in import-if statements.
Related issue: #5563
Related PR: #5566
To Reproduce
A reasonably short repro is
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
srcto the test stanza'shs-source-dirs - copy over all
build-dependsfromlibtotest(they were transitive dependencies anyway)
The above allows me to run something like
$ ghcid -a -c "cabal repl my-test-stanza -f -O0" --test Main.mainand 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.