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

Fix/build tool depends repeats 10758 #10764

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

philderbeast
Copy link
Collaborator

Fixes #10758.


QA Notes

Use cabal init to create a package with components of your choosing and then add a build-tool-depends stanza that builds. The one from the docs is markdown-unlit:markdown-unlit >= 0.5.0 && < 0.6. When repeated, there should be a message asking that each build tool dependency is specified only once. The package should still build unless the effective intersection of version ranges is impossible to satisfy.

$ cabal build all --enable-tests --enable-benchmarks
...
Resolving dependencies...
...
As the build tool 'markdown-unlit' was specified more than once:
  - >0.5.0 && <=0.6
  - >=0 (any version)
We'll use the effective intersection of these 2 version ranges:
  - >0.5.0 && <=0.6
Please specify build tool dependencies only once.
...

- report the duplicate versions
- intersect the version ranges
@philderbeast philderbeast force-pushed the fix/build-tool-depends-repeats-10758 branch from c096235 to e854972 Compare January 20, 2025 01:31
@philderbeast philderbeast marked this pull request as draft January 20, 2025 01:34
where
mergeVersions :: [VersionRange] -> VersionRange
mergeVersions [] = anyVersion
mergeVersions (v : vs) = foldr intersectVersionRanges v vs
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

foldx intersectVersionRanges seems a common pattern, maybe this version should be in Cabal-syntax?

See: cabal-install/src/Distribution/Client/List.hs,Cabal/src/Distribution/PackageDescription/Check/Target.hs.

Copy link
Collaborator Author

@philderbeast philderbeast Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather do that on a separate pull request if you think it is worth making it a maintenance task.

$ find . -type f -name '*.hs' | grep -v -E 'dist-|cabal-testsuite|IntegrationTests2' \
| xargs grep -Po 'intersectVersionRanges' | wc -l
57

@philderbeast
Copy link
Collaborator Author

I'll have to find where the solver is being called before configurePackage in Cabal/src/Distribution/Simple/Configure.hs. With the following setup that has impossible to satisfy constraints, configurePackage is not called:

...
common warnings
    ghc-options: -Wall

test-suite build-tool-depends-twice-test
    import:           warnings
    default-language: Haskell2010
    type:             exitcode-stdio-1.0
    hs-source-dirs:   test
    main-is:          Main.hs
    build-depends:    base >=4 && <5
    build-tool-depends: markdown-unlit:markdown-unlit > 0.5.0 && <= 0.6
    build-tool-depends: markdown-unlit:markdown-unlit <0
$ cabal build all --enable-tests --enable-benchmarks
...
Error: [Cabal-7107]
Could not resolve dependencies:
[__0] trying: build-tool-depends-twice-0.1.0.0 (user goal)
[__1] trying: build-tool-depends-twice:*test
[__2] next goal: build-tool-depends-twice:markdown-unlit:exe.markdown-unlit (dependency of build-tool-depends-twice *test)
[__2] rejecting: build-tool-depends-twice:markdown-unlit:exe.markdown-unlit; 0.6.0, 0.5.1, 0.5.0, 0.4.1, 0.4.0, 0.3.1, 0.2.0.1, 0.2.0, 0.1.0, 0.3.0 (conflict: build-tool-depends-twice *test => build-tool-depends-twice:markdown-unlit:exe.markdown-unlit (exe markdown-unlit)<0 && >0.5.0 && <=0.6)
[__2] fail (backjumping, conflict set: build-tool-depends-twice, build-tool-depends-twice:markdown-unlit:exe.markdown-unlit, build-tool-depends-twice:test)
After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: build-tool-depends-twice, build-tool-depends-twice:test, build-tool-depends-twice:markdown-unlit:exe.markdown-unlit

I've not seen the exe. prefix before from build-tool-depends-twice:markdown-unlit:exe.markdown-unlit. Seems odd to use . as the separator here when we use : everywhere else.

$ cabal target all:exes
...
Fully qualified target forms:
 - buildinfo-reference-generator:exe:buildinfo-reference-generator
 - cabal-install:exe:cabal
 - cabal-testsuite:exe:cabal-tests
 - cabal-testsuite:exe:setup
 - cabal-testsuite:exe:test-runtime-deps
 - cabal-validate:exe:cabal-validate
 - solver-benchmarks:exe:hackage-benchmark
Found 5 targets matching all:exes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Repeating build-tool-depends can break the build
2 participants