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

Repeating build-tool-depends can break the build #10758

Open
philderbeast opened this issue Jan 18, 2025 · 2 comments · May be fixed by #10764
Open

Repeating build-tool-depends can break the build #10758

philderbeast opened this issue Jan 18, 2025 · 2 comments · May be fixed by #10764

Comments

@philderbeast
Copy link
Collaborator

philderbeast commented Jan 18, 2025

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

@philderbeast
Copy link
Collaborator Author

philderbeast commented Jan 18, 2025

Looking at the code I can see why but I do think the error message could be better. Also if the build is installing the tool at a path with the version encoded into the path, why can't its version be determined? Seems odd that from store/ghc-9.12.1-a75a/markdown-unlit-0.5.1-etc the version can't be determined to be markdown-unlit-0.5.1.

@philderbeast
Copy link
Collaborator Author

let externBuildToolDeps =
[ LegacyExeDependency (unUnqualComponentName eName) versionRange
| buildTool@(ExeDependency _ eName versionRange) <-
getAllToolDependencies pkg_descr0 bi
, not $ isInternal pkg_descr0 buildTool
]

A possible fix would be to find the duplicates, issue a warning and combine their version ranges:

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

This would be then the same as markdown-unlit:markdown-unlit >0 && > 0.5.0 && <= 0.6

@philderbeast philderbeast linked a pull request Jan 20, 2025 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant