haskell / cabal

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

Command line flags should override freeze file flags. #10441

Open bgohla opened 1 month ago

bgohla commented 1 month ago

Describe the feature request A simple description of what you would like to be added to Cabal.

Given a project as follows:

$ 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

running

cabal build -f-some-flag

should build the cabal-freeze-bug package with the flag turned off, instead of failing with a resolution conflict.

(Likewise for cabal build -c"cabal-freeze-bug -some-flag")

Additional context Related to https://github.com/haskell/cabal/issues/10439

jasagredo commented 2 weeks ago

I don't see a reason why this should be the case.

The freeze file specifies an exact build plan that must not be altered, but you want to alter it via the flags (which could use different dependency versions or remove/add dependencies), then what is the point of having a cabal freeze file?

I think (although I don't think it should be done) I would at least require a flag like --override-freeze-file to be passed so that you declare "I know for sure that I will break my freeze file declaration and I'm ok with it", but I think what you propose should not by any means be the default.

bgohla commented 1 week ago

I mean i guess it would be acceptable to pass an extra flag. But isn't it commonly understood that command line flags override configuration in files?

I want to be able to do this, because I have a code base, which I need to be able to compile with different flag settings.