commercialhaskell / stack

The Haskell Tool Stack
http://haskellstack.org
BSD 3-Clause "New" or "Revised" License
3.98k stars 842 forks source link

Allow Hpack used by Stack to overwrite a Cabal file it considers has been modified manually #6521

Closed evan0greenup closed 6 months ago

evan0greenup commented 6 months ago

Make sure that you are using the latest release (currently Stack 2.15.3). See the upgrade instructions to upgrade.

If there is <package_name>.cabal existed in the root directory of package, stack will automatically ignore package.yaml. when build, stack will convert package.yaml into <package_name>.cabal via hpack.

When update package.yaml, the developer has to manually delete <project_name>.cabal. This is very inconvenient. It would be nice to make the generated cabal file as <project_name>.generated.cabal. So if there is only <project_name>.generated.cabal, stack will automatically overwrite <project_name>.generated.cabal from package.yaml.

This feature can make developer completely forget about the cabal stuff, if he/her workflow is completely depend on stack.

mpilgrem commented 6 months ago

Hpack added --force in Hpack 0.20.0 (16 November 2017) because the original behaviour was to overwrite Cabal files and some Stack users found that confusing:

However, it seems to me reasonable to have a Stack flag --[no-]hpack-force (configuration option hpack-force: true) that enables --force (disabled by default).

mpilgrem commented 6 months ago

@evan0greenup, if you are not using GHCup to manage versions of Stack, the above feature can be tested in stack upgrade --source-only --git --git-branch fix6521.

It can be used at the command line with stack --hpack-force <command> but the primary intention is that Stack would be configured in YAML files with hpack-force: true. I have kept the default as hpack-force: false, given the history discussed above.