haskell / cabal

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

Flags in local config do not override flags in freeze file #10439

Open bgohla opened 1 month ago

bgohla commented 1 month ago

Describe the bug

In my project, I have a project freeze file that has flag settings for local packages set to -some-flag. I expect to be able to override this flag in the local project config, following the precedence order given in the documentation: https://cabal.readthedocs.io/en/stable/cabal-project-description-file.html#project-description-cabal-project-file .

But when trying to build, I get a resolution conflict instead.

To Reproduce Steps to reproduce the behavior:

$ cat cabal-freeze-bug.cabal
cabal-version:      3.0
name:               cabal-freeze-bug
version:            0.1.0.0
synopsis:           n
-- description:
license:            BSD-2-Clause
license-file:       LICENSE
author:             Björn Gohla
maintainer:         bjorn.gohla@scrive.com
-- copyright:
category:           Testing
build-type:         Simple
extra-doc-files:    CHANGELOG.md
-- extra-source-files:

flag some-flag
     description: a flag that does nothing
     default: True

common warnings
    ghc-options: -Wall

executable cabal-freeze-bug
    import:           warnings
    main-is:          Main.hs
    -- other-modules:
    -- other-extensions:
    build-depends:    base ^>=4.18.2.1
    hs-source-dirs:   app
    default-language: Haskell2010
$ cat cabal.project.freeze 
active-repositories: hackage.haskell.org:merge
constraints: any.base ==4.18.2.1,
             cabal-freeze-bug +some-flag,
             any.ghc-bignum ==1.3,
             any.ghc-prim ==0.10.0,
             any.rts ==1.0.2
index-state: hackage.haskell.org 2024-06-14T08:17:16Z
$ cat cabal.project.local 
ignore-project: False
flags: -some-flag
$ cabal  build 
Resolving dependencies...
Error: cabal: Could not resolve dependencies:
[__0] trying: cabal-freeze-bug-0.1.0.0 (user goal)
[__1] rejecting: cabal-freeze-bug:+some-flag (constraint from config file,
command line flag, or user target requires opposite flag selection)
[__1] rejecting: cabal-freeze-bug:-some-flag (constraint from project config
/home/bgohla/src/scratch/cabal-freeze-bug/cabal.project.freeze requires
opposite flag selection)
[__1] fail (backjumping, conflict set: cabal-freeze-bug,
cabal-freeze-bug:some-flag)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: cabal-freeze-bug:some-flag,
cabal-freeze-bug

Expected behavior

I expect the flags specified in the local project config to override the flags in the freeze file.

System information

$ cabal --version
cabal-install version 3.10.3.0
compiled using version 3.10.3.0 of the Cabal library
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 9.6.5
$ uname -smprv
Linux 6.8.9 #1-NixOS SMP PREEMPT_DYNAMIC Thu May  2 14:35:35 UTC 2024 x86_64 unknown
jasagredo commented 1 week ago

Hmm it is true that the documentation says that .local should override .freeze but I don't think that is the case actually. The .freeze file is final wrt versions and flags I think.

My understanding, as I described in the other issue, is that the freeze file must be immutable and enforced, so I think the documentation should be fixed instead of making this a feature.