Skip to content

Commit

Permalink
Fix #6521 Add --[no-]hpack-force flag
Browse files Browse the repository at this point in the history
  • Loading branch information
mpilgrem committed Mar 28, 2024
1 parent 5ad1131 commit 5da72b3
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 8 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ Other enhancements:
* In YAML configuration files, the `global-hints-location` key is introduced to
allow the location of the global hints YAML specification file to be
specified.
* By default, Hpack 0.20.0 or later will decline to overwrite a Cabal file that
was modified manually. In YAML configuration files, the `hpack-force` key is
introduced to allow Hpack to overwrite such a Cabal file. The corresponding
`--hpack-force` flag is also added.

Bug fixes:

Expand Down
2 changes: 1 addition & 1 deletion cabal.config
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ constraints:
, open-browser ==0.2.1.0
, optparse-applicative ==0.18.1.0
, optparse-simple ==0.1.1.4
, pantry ==0.9.3.2
, pantry ==0.10.0
, parsec ==3.1.16.1
, parser-combinators ==1.3.0
, path ==0.9.5
Expand Down
10 changes: 10 additions & 0 deletions doc/global_flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ Pass the option `--ghc-variant <variant>` to specify the relevant GHC variant.
For further information, see the documentation for the corresponding non-project
specific configuration [option](yaml_configuration.md#ghc-variant).

## `--[no-]hpack-force` flag

:octicons-tag-24: UNRELEASED

Default: Disabled

By default, Hpack 0.20.0 or later will decline to overwrite a Cabal file that
has been modified manually. Pass the flag `--hpack-force` to allow Hpack to
overwrite such a Cabal file.

## `--hpack-numeric-version` flag

Pass the flag `--hpack-numeric-version` to cause Stack to report the numeric
Expand Down
13 changes: 13 additions & 0 deletions doc/yaml_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,19 @@ Default: `true`
Strip out the "Loading ..." lines from GHC build output, produced when using
Template Haskell.

### hpack-force

:octicons-tag-24: UNRELEASED

Default: `false`

Command line equivalent (takes precedence):
[`--hpack-force` option](global_flags.md#-no-hpack-force-flag)

Whether or not to allow Hpack to overwrite a Cabal file that has been modified
manually. By default, Hpack 0.20.0 or later will decline to overwrite such a
Cabal file.

### ignore-revision-mismatch

(Removed 1.11)
Expand Down
5 changes: 5 additions & 0 deletions src/Stack/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import Distribution.System
( Arch (..), OS (..), Platform (..), buildPlatform )
import qualified Distribution.Text ( simpleParse )
import Distribution.Version ( simplifyVersionRange )
import qualified Hpack
import GHC.Conc ( getNumProcessors )
import Network.HTTP.StackClient
( httpJSON, parseUrlThrow, getResponseBody )
Expand Down Expand Up @@ -534,6 +535,9 @@ configFromConfigMonoid
let stackDeveloperMode = fromFirst
stackDeveloperModeDefault
configMonoid.stackDeveloperMode
hpackForce = if fromFirstFalse configMonoid.hpackForce
then Hpack.Force
else Hpack.NoForce
casa =
if fromFirstTrue configMonoid.casaOpts.enable
then
Expand All @@ -560,6 +564,7 @@ configFromConfigMonoid
pantryRoot
pic
(maybe HpackBundled HpackCommand $ getFirst configMonoid.overrideHpack)
hpackForce
clConnectionCount
casa
snapLoc
Expand Down
7 changes: 6 additions & 1 deletion src/Stack/Options/ConfigParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ configOptsParser :: FilePath -> GlobalOptsContext -> Parser ConfigMonoid
configOptsParser currentDir hide0 =
( \stackRoot workDir buildOpts dockerOpts nixOpts systemGHC installGHC arch
ghcVariant ghcBuild jobs extraIncludeDirs extraLibDirs
customPreprocessorExts overrideGccPath overrideHpack skipGHCCheck skipMsys
customPreprocessorExts overrideGccPath overrideHpack hpackForce skipGHCCheck skipMsys
localBinPath setupInfoLocations modifyCodePage allowDifferentUser dumpLogs
colorWhen snapshotLocation noRunCompile -> mempty
{ stackRoot
Expand All @@ -55,6 +55,7 @@ configOptsParser currentDir hide0 =
, customPreprocessorExts
, overrideGccPath
, overrideHpack
, hpackForce
, skipMsys
, localBinPath
, setupInfoLocations
Expand Down Expand Up @@ -146,6 +147,10 @@ configOptsParser currentDir hide0 =
<> help "Use HPACK executable (overrides bundled Hpack)."
<> hide
))
<*> firstBoolFlagsFalse
"hpack-force"
"overwriting of Cabal files that have been modified manually."
hide
<*> firstBoolFlagsFalse
"skip-ghc-check"
"skipping the GHC version and architecture check."
Expand Down
9 changes: 8 additions & 1 deletion src/Stack/Types/ConfigMonoid.hs
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,12 @@ data ConfigMonoid = ConfigMonoid
-- ^ See: 'configExtraLibDirs'
, customPreprocessorExts :: ![Text]
-- ^ See: 'configCustomPreprocessorExts'
, overrideGccPath :: !(First (Path Abs File))
, overrideGccPath :: !(First (Path Abs File))
-- ^ Allow users to override the path to gcc
, overrideHpack :: !(First FilePath)
-- ^ Use Hpack executable (overrides bundled Hpack)
, hpackForce :: !FirstFalse
-- ^ Pass --force to Hpack to always overwrite Cabal file
, concurrentTests :: !(First Bool)
-- ^ See: 'configConcurrentTests'
, localBinPath :: !(First FilePath)
Expand Down Expand Up @@ -264,6 +266,7 @@ parseConfigMonoidObject rootDir obj = do
obj ..:? configMonoidCustomPreprocessorExtsName ..!= []
overrideGccPath <- First <$> obj ..:? configMonoidOverrideGccPathName
overrideHpack <- First <$> obj ..:? configMonoidOverrideHpackName
hpackForce <- FirstFalse <$> obj ..:? configMonoidHpackForceName
concurrentTests <- First <$> obj ..:? configMonoidConcurrentTestsName
localBinPath <- First <$> obj ..:? configMonoidLocalBinPathName
templates <- obj ..:? "templates"
Expand Down Expand Up @@ -371,6 +374,7 @@ parseConfigMonoidObject rootDir obj = do
, customPreprocessorExts
, overrideGccPath
, overrideHpack
, hpackForce
, concurrentTests
, localBinPath
, templateParameters
Expand Down Expand Up @@ -490,6 +494,9 @@ configMonoidOverrideGccPathName = "with-gcc"
configMonoidOverrideHpackName :: Text
configMonoidOverrideHpackName = "with-hpack"

configMonoidHpackForceName :: Text
configMonoidHpackForceName = "hpack-force"

configMonoidConcurrentTestsName :: Text
configMonoidConcurrentTestsName = "concurrent-tests"

Expand Down
3 changes: 2 additions & 1 deletion stack-ghc-9.8.1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
snapshot: nightly-2024-02-24

extra-deps:
- pantry-0.9.3.2@sha256:336373d8cbb10505ff16ac6e35cb9d8a7f45293a908de1c00f55c133ee7dde86,7511
- git: https://github.com/commercialhaskell/pantry.git
commit: bd02f9177c3e0aff09236ad09e70ff52db009344

docker:
enable: false
Expand Down
12 changes: 8 additions & 4 deletions stack-ghc-9.8.1.yaml.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@

packages:
- completed:
hackage: pantry-0.9.3.2@sha256:336373d8cbb10505ff16ac6e35cb9d8a7f45293a908de1c00f55c133ee7dde86,7511
commit: bd02f9177c3e0aff09236ad09e70ff52db009344
git: https://github.com/commercialhaskell/pantry.git
name: pantry
pantry-tree:
sha256: 820f4442ca96663fa57405f22385d216fbc1a28b9f49c7c82ad2a391803abe51
size: 2722
sha256: 6c1315699b3f2ec21442c07e7c68dfaa5753b43c7d4df1f60c102b4601f27dc5
size: 3632
version: 0.10.0
original:
hackage: pantry-0.9.3.2@sha256:336373d8cbb10505ff16ac6e35cb9d8a7f45293a908de1c00f55c133ee7dde86,7511
commit: bd02f9177c3e0aff09236ad09e70ff52db009344
git: https://github.com/commercialhaskell/pantry.git
snapshots:
- completed:
sha256: 1d712c7dff52b68376c61a25d9fd642d0bca4498f0d5affb4086f6ea076b3930
Expand Down

0 comments on commit 5da72b3

Please sign in to comment.