haskell / haskell/cabal

Allow executable sections to imply flags

Open
#9,251 4 comments 0 reactions 0 assignees View on GitHub
cabal-install: cmd/check type: enhancement
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

## Motivation
I maintain a small package (https://hackage.haskell.org/package/tasty-coverage) which I have to preprocess before I can upload it to Hackage. The problematic part of the cabal file looks like this:
```
executable tasty-coverage-example
main-is: Main.hs
hs-source-dirs: example
ghc-options: -Wall -fhpc
build-depends: ...

test-suite tasty-coverage-test
main-is: Main.hs
build-tool-depends: tasty-coverage:tasty-coverage-example
hs-source-dirs: test
build-depends: ...
```
The testsuite tests whether the binary `tasty-coverage-example` behaves correctly: The correct behaviour is that upon executing it, it generates the correct .tix files. But this obviously requires that `tasty-coverage-example` is compiled with the `-fhpc` flag.
Unfortunately, `cabal check` thinks that we should never specify `-fhpc` in the cabal file, and Hackage refuses to upload this package. (I remove the entire section of the cabal file before invoking `cabal sdist` to work around this)

## Proposed Solution

My idea to solve this problem contains two parts:
- Guard the `-fhpc` option of the executable behind a flag. (This requires that the re-implementation of `cabal check` in #8427 is merged, and that `cabal check` doesn't complain about the `-fhpc` option if it is guarded behind a flag.
- Allow that the testsuite somehow implies a flag.

Here is how this might look like:
```
Flag coverage {
Description: Enable coverage
Default: False
Manual: True
}

executable tasty-coverage-example
main-is: Main.hs
hs-source-dirs: example
ghc-options: -Wall
if flag(coverage):
ghc-options: -fhpc
build-depends: ...

test-suite tasty-coverage-test
main-is: Main.hs
build-tool-depends: tasty-coverage:tasty-coverage-example
imply-flag: coverage
hs-source-dirs: test
build-depends: ...
```

That is, the `imply-flag` field (the bikeshed could of course also have a different color) means that the test-suite can only be built if the `coverage` flag is set to true, and running `cabal run tasty-coverage-test` has the effect of running `cabal run tasty-coverage-test -f coverage`. I can imagine that this could be useful for other executables as well, for example for specifying a single-platform executable.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing existing package-flag handling and how test-suite targets are built and run. Done means an agreed syntax and semantics for a test suite to imply a flag, with validation that the implied flag affects executable compilation and invocation as described.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.