haskell / haskell/cabal

Repeating build-tool-depends can break the build

Open
#10,758 2 comments 0 reactions 0 assignees View on GitHub
needs triage type: bug
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

**Describe the bug**
Mistakenly adding `build-tool-depends` twice, the first without a version range, the second with one (or both with a version range) leads to a build failure.

**To Reproduce**

Run `cabal init` creating a test-suite and then add these two lines to the test suite:

```
build-tool-depends: hspec-discover:hspec-discover
build-tool-depends: hspec-discover:hspec-discover >=2 && <3
```

```
$ cabal build all --enable-tests
...
Build profile: -w ghc-9.6.6 -O1
In order, the following will be built (use -v for more details):
- build-tool-depends-twice-0.1.0.0 (test:build-tool-depends-twice-test) (configuration changed)
Configuring test suite 'build-tool-depends-twice-test' for build-tool-depends-twice-0.1.0.0...
Error: [Cabal-1008]
The program 'hspec-discover' version >=2 && <3 is required but the version of
/home/.../.local/state/cabal/store/ghc-9.6.6/hspec-discover-2.11.10-e-hspec-discover-46bdc5d621da43233045a4700712e015d472ed9d8d9e8f6ba007136568801492/bin/hspec-discover could not be determined.

Error: [Cabal-7125]
Failed to build test:build-tool-depends-twice-test from build-tool-depends-twice-0.1.0.0. The failure occurred during the configure step.
```

The same failure occurs with:

```
build-tool-depends: hspec-discover:hspec-discover >=2 && <3
build-tool-depends: hspec-discover:hspec-discover >=2 && <3
```

The following repeats build without problem:

```
build-tool-depends: hspec-discover:hspec-discover >=2 && <3
build-tool-depends: hspec-discover:hspec-discover
```

```
build-tool-depends: hspec-discover:hspec-discover
build-tool-depends: hspec-discover:hspec-discover
```

I see the same failure as well with the example from the docs, if repeated:

```
build-tool-depends: markdown-unlit:markdown-unlit >= 0.5.0 && < 0.6
build-tool-depends: markdown-unlit:markdown-unlit >= 0.5.0 && < 0.6
```

Also happens with the latest compiler:

```
$ cabal build all --enable-tests
...
Resolving dependencies...
Build profile: -w ghc-9.12.1 -O1
In order, the following will be built (use -v for more details):
- base-compat-0.14.1 (lib) (requires build)
- markdown-unlit-0.5.1 (lib) (requires build)
- markdown-unlit-0.5.1 (exe:markdown-unlit) (requires build)
- build-tool-depends-twice-0.1.0.0 (test:build-tool-depends-twice-test) (first run)
Starting base-compat-0.14.1 (lib)
Building base-compat-0.14.1 (lib)
Installing base-compat-0.14.1 (lib)
Completed base-compat-0.14.1 (lib)
Starting markdown-unlit-0.5.1 (lib)
Building markdown-unlit-0.5.1 (lib)
Installing markdown-unlit-0.5.1 (lib)
Completed markdown-unlit-0.5.1 (lib)
Starting markdown-unlit-0.5.1 (exe:markdown-unlit)
Building markdown-unlit-0.5.1 (exe:markdown-unlit)
Installing markdown-unlit-0.5.1 (exe:markdown-unlit)
Completed markdown-unlit-0.5.1 (exe:markdown-unlit)
Configuring test suite 'build-tool-depends-twice-test' for build-tool-depends-twice-0.1.0.0...
Error: [Cabal-1008]
The program 'markdown-unlit' version >=0.5.0 && <0.6 is required but the version of /home/.../.local/state/cabal/store/ghc-9.12.1-a75a/markdown-unlit-0.5.1-e-markdown-unlit-0d34e71effbc9fbd30111d61fca43c4ced66a0848c7b70876a029fc5266aa9aa/bin/markdown-unlit could not be determined.

Error: [Cabal-7125]
Failed to build test:build-tool-depends-twice-test from build-tool-depends-twice-0.1.0.0. The failure occurred during the configure step.
```

**Expected behavior**
That `cabal-install-3.14.1.0` is able to build the test suite or it warns about the repeated `build-tool-depends` or both.

Seen on ubuntu 22.04

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.