haskell / cabal

Official upstream development repository for Cabal and cabal-install
https://haskell.org/cabal
Other
1.63k stars 695 forks source link

Document constraint syntax better (was Can I constrain a build-tool on the command line?) #7804

Closed andreasabel closed 2 years ago

andreasabel commented 3 years ago

I am trying

$ cabal install -w ghc-7.10.3 --program-suffix=-2.8 --constraint='alex<3.1.4' BNFC-2.8

The constraint alex<3.1.4 seems to be accepted (no error), but ignored: No attempts to build an alex < 3.1.4, and the generated lexer fails (likely due to a too new version of alex):

[17 of 97] Compiling LexBNF           ( dist/build/bnfc/bnfc-tmp/LexBNF.hs, dist/build/bnfc/bnfc-tmp/LexBNF.o )

src/LexBNF.x:164:38:
    Not in scope: ‘ord’

Trying qualification, like either of

$ cabal install -w ghc-7.10.3 --program-suffix=-2.8 --constraint='alex:alex<3.1.4' BNFC-2.8
$ cabal install -w ghc-7.10.3 --program-suffix=-2.8 --constraint='alex:exe:alex<3.1.4' BNFC-2.8

gives a syntax error:

Error: cabal: invalid argument to option `--constraint': expected a (possibly
qualified) package name followed by a constraint, which is either a version
range, 'installed', 'source', 'test', 'bench', or flags. "<eitherParsec>"
(line 1, column 6):
unexpected ...
expecting "setup."

I found the following in the changelog of 2.0.0.0:

  • Added qualified constraints for setup dependencies. For example, --constraint="setup.bar == 1.0" constrains all setup dependencies on bar, and --constraint="foo:setup.bar == 1.0" constrains foo's setup dependency on bar (part of #3502).
  • Non-qualified constraints, such as --constraint="bar == 1.0", now only apply to top-level dependencies. They don't constrain setup or build-tool dependencies. The new syntax --constraint="any.bar == 1.0" constrains all uses of bar.

But I don't know whether this is the last state of affairs, the documentation is not explicit about it. (See also #7535.)

Mikolaj commented 3 years ago

Possibly distantly related: #7787.

Edit: oh, you've already seen it.

phadej commented 3 years ago
% cabal install -w ghc-7.10.3 --program-suffix=-2.8 --constraint='any.alex<3.1.4' BNFC-2.8
Warning: The package list for 'hackage.haskell.org' is 23 days old.
Run 'cabal update' to get the latest list of available packages.
Warning: The package list for 'hackage.haskell.org' is 23 days old.
Run 'cabal update' to get the latest list of available packages.
Resolving dependencies...
cabal: Could not resolve dependencies:
[__0] next goal: BNFC (user goal)
[__0] rejecting: BNFC-2.9.3, BNFC-2.9.2, BNFC-2.9.1, BNFC-2.9.0, BNFC-2.8.4,
BNFC-2.8.3, BNFC-2.8.2, BNFC-2.8.1 (constraint from user target requires
==2.8)
[__0] trying: BNFC-2.8
[__1] next goal: BNFC:alex:exe.alex (dependency of BNFC)
[__1] rejecting: BNFC:alex:exe.alex-3.2.6, BNFC:alex:exe.alex-3.2.5,
BNFC:alex:exe.alex-3.2.4, BNFC:alex:exe.alex-3.2.3, BNFC:alex:exe.alex-3.2.2,
BNFC:alex:exe.alex-3.2.1, BNFC:alex:exe.alex-3.2.0, BNFC:alex:exe.alex-3.1.7,
BNFC:alex:exe.alex-3.1.6, BNFC:alex:exe.alex-3.1.5, BNFC:alex:exe.alex-3.1.4
(constraint from command line flag requires <3.1.4)
[__1] trying: BNFC:alex:exe.alex-3.1.3
[__2] next goal: BNFC:alex:exe.base (dependency of BNFC:alex:exe.alex
+/-small_base)
[__2] rejecting:
BNFC:alex:exe.base-4.8.2.0/installed-0d6d1084fbc041e1cded9228e80e264d
(conflict: BNFC:alex:exe.alex +/-small_base => BNFC:alex:exe.base>=1.0 &&
<4.8)
[__2] rejecting: BNFC:alex:exe.base-4.15.0.0, BNFC:alex:exe.base-4.14.3.0,
BNFC:alex:exe.base-4.14.2.0, BNFC:alex:exe.base-4.14.1.0,
BNFC:alex:exe.base-4.14.0.0, BNFC:alex:exe.base-4.13.0.0,
BNFC:alex:exe.base-4.12.0.0, BNFC:alex:exe.base-4.11.1.0,
BNFC:alex:exe.base-4.11.0.0, BNFC:alex:exe.base-4.10.1.0,
BNFC:alex:exe.base-4.10.0.0, BNFC:alex:exe.base-4.9.1.0,
BNFC:alex:exe.base-4.9.0.0, BNFC:alex:exe.base-4.8.2.0,
BNFC:alex:exe.base-4.8.1.0, BNFC:alex:exe.base-4.8.0.0,
BNFC:alex:exe.base-4.7.0.2, BNFC:alex:exe.base-4.7.0.1,
BNFC:alex:exe.base-4.7.0.0, BNFC:alex:exe.base-4.6.0.1,
BNFC:alex:exe.base-4.6.0.0, BNFC:alex:exe.base-4.5.1.0,
BNFC:alex:exe.base-4.5.0.0, BNFC:alex:exe.base-4.4.1.0,
BNFC:alex:exe.base-4.4.0.0, BNFC:alex:exe.base-4.3.1.0,
BNFC:alex:exe.base-4.3.0.0, BNFC:alex:exe.base-4.2.0.2,
BNFC:alex:exe.base-4.2.0.1, BNFC:alex:exe.base-4.2.0.0,
BNFC:alex:exe.base-4.1.0.0, BNFC:alex:exe.base-4.0.0.0,
BNFC:alex:exe.base-3.0.3.2, BNFC:alex:exe.base-3.0.3.1 (constraint from
non-upgradeable package requires installed instance)
[__2] fail (backjumping, conflict set: BNFC:alex:exe.alex, BNFC:alex:exe.base)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: BNFC:alex:exe.base,
BNFC:alex:exe.alex, base, BNFC
Try running with --minimize-conflict-set to improve the error message.

which seems correct, as alex-3.1.3 and older have base <4.8 bound.

TL:DR --constraint="any.alex <version range>"

andreasabel commented 3 years ago

Thanks @phadej, this worked! (Although I ran into the more severe problem that GHC <= 7.6 doesn't work on macOS due to SIP.)

TODO left: document constraint syntax better.

jneira commented 2 years ago

last actionable would be duplicate of #5373