Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import in if #5563

Closed
ekmett opened this issue Sep 4, 2018 · 7 comments
Closed

import in if #5563

ekmett opened this issue Sep 4, 2018 · 7 comments
Labels
re: conditional About conditional declarations in cabal files(`if`) re: import About importing stanzas in a .cabal file (`import`)

Comments

@ekmett
Copy link
Member

ekmett commented Sep 4, 2018

It'd be useful to be able to place an import statement inside of an if to factor out repetitive logic.

e.g. in the common idiom of

if !flag(test-whatever)
  buildable: False
else
  ...
@phadej
Copy link
Collaborator

phadej commented Sep 4, 2018 via email

@ekmett
Copy link
Member Author

ekmett commented Sep 4, 2018

Putting the conditional into a common stanza doesn't work for this idiom where the test is particular to the test suite in question.

@hvr
Copy link
Member

hvr commented Sep 4, 2018

Fwiw, this is strongly correlated with #5564 regarding the underlying technical limitation

@ekmett
Copy link
Member Author

ekmett commented Sep 4, 2018

I've started using common blocks and imports rather than build-depends so I only have to state my version ranges once in some otherwise massive cabal configurations.

e.g.

common bifunctors
  build-depends: bifunctors >= 5 && < 6

common bytestring
  build-depends: bytestring ^>= 0.10.8
...
library lsp
  import: aeson, base, bytestring, data-default, filepath, hashable, lens,
          lens-aeson, template-haskell, text, unordered-containers, uri-encode
  hs-source-dirs: src/lsp

but this breaks with the idiom of doing

test-suite test-tasty
  ...
  if !flag(test-tasty)
    buildable: False
  else
    build-depends: ...

I currently bury my dependencies down under the if to avoid incurring them unnecessarily when that particular test target isn't being built. (Is this still needed these days?) So, I currently repeat my version bounds, messily, in my test suites.

@phadej
Copy link
Collaborator

phadej commented Sep 4, 2018

@ekmett I see.

Would #5566 work for you? There we still have a limitation that import: common should be on top, but it can be on top of conditional section (see added test-file in the PR).

EDIT: it will require cabal-version: 2.6 (or whatever the next one will be)

@ekmett
Copy link
Member Author

ekmett commented Sep 4, 2018

That'd probably work for me.

@phadej
Copy link
Collaborator

phadej commented Nov 12, 2020

This is possible with cabal-version: 3.0

@phadej phadej closed this as completed Nov 12, 2020
@andreasabel andreasabel added re: conditional About conditional declarations in cabal files(`if`) re: import About importing stanzas in a .cabal file (`import`) labels Oct 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
re: conditional About conditional declarations in cabal files(`if`) re: import About importing stanzas in a .cabal file (`import`)
Projects
None yet
Development

No branches or pull requests

4 participants