Skip to content

Commit 2f4d975

Browse files
authored
Merge pull request commercialhaskell#6624 from commercialhaskell/fix6501
Fix commercialhaskell#6501 Add `stack build --[no-]allow-newer`
2 parents 173f2ac + d0637a3 commit 2f4d975

10 files changed

+52
-10
lines changed

ChangeLog.md

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ Behavior changes:
1212

1313
Other enhancements:
1414

15+
* Add flag `--[no-]allow-newer` to Stack's `build` command, which takes
16+
precedence over the existing `allow-newer` configuration option.
17+
1518
Bug fixes:
1619

1720
* Fix a regression, introduced in Stack 2.15.7, that caused GHC 8.10.7 or

doc/build_command.md

+15
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,21 @@ of the Cabal build process (for further information, see the documentation for
216216
the [configure-options](yaml_configuration.md#configure-options) configuration
217217
option).
218218

219+
### `--[no-]allow-newer` flag
220+
221+
:octicons-tag-24: UNRELEASED
222+
223+
Overrides: [`allow-newer`](yaml_configuration.md#allow-newer) non-project
224+
specific configuration option
225+
226+
Pass the flag to enable or disable the ignoring of lower and upper version
227+
bounds in Cabal files.
228+
229+
!!! info
230+
231+
The name `allow-newer` was chosen to match a commonly-used Cabal option
232+
which ignored only upper version bounds.
233+
219234
### `--bench` flag
220235

221236
Pass the flag to add benchmark components to the targets, if specific components

doc/yaml_configuration.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,15 @@ process.
498498

499499
Default: `false`
500500

501-
Whether to ignore version bounds in Cabal files. This also ignores lower bounds.
502-
The name `allow-newer` is chosen to match the commonly-used Cabal option.
501+
Command line equivalent (takes precedence):
502+
[`stack build --[no-]allow-newer`](build_command.md#-allow-newer-flag) flag
503+
504+
Whether to ignore lower and upper version bounds in Cabal files.
505+
506+
!!! info
503507

508+
The name `allow-newer` was chosen to match a commonly-used Cabal option
509+
which ignored only upper bounds.
504510

505511
~~~yaml
506512
allow-newer: true

src/Stack/Build/ConstructPlan.hs

+5-2
Original file line numberDiff line numberDiff line change
@@ -896,8 +896,11 @@ adrInRange ::
896896
adrInRange pkgId name range adr = if adrVersion adr `withinRange` range
897897
then pure True
898898
else do
899-
allowNewer <- view $ configL . to (.allowNewer)
900-
allowNewerDeps <- view $ configL . to (.allowNewerDeps)
899+
config <- view configL
900+
allowNewerCLI <- view $ envConfigL . to (.buildOptsCLI) . to (.allowNewer)
901+
let allowNewerConfig = config.allowNewer
902+
allowNewer = fromFirst False $ allowNewerCLI <> allowNewerConfig
903+
allowNewerDeps = config.allowNewerDeps
901904
if allowNewer
902905
then case allowNewerDeps of
903906
Nothing -> do

src/Stack/Config.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ configFromConfigMonoid
420420
fromFirst AGOLocals configMonoid.applyGhcOptions
421421
applyProgOptions =
422422
fromFirst APOLocals configMonoid.applyProgOptions
423-
allowNewer = fromFirst False configMonoid.allowNewer
423+
allowNewer = configMonoid.allowNewer
424424
allowNewerDeps = coerce configMonoid.allowNewerDeps
425425
defaultInitSnapshot <- do
426426
root <- getCurrentDir

src/Stack/Options/BuildParser.hs

+7-1
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ import Options.Applicative
1515
, metavar, option, strOption, switch, value
1616
)
1717
import Options.Applicative.Args ( cmdOption )
18-
import Options.Applicative.Builder.Extra ( textArgument, textOption )
18+
import Options.Applicative.Builder.Extra
19+
( firstBoolFlagsNoDefault, textArgument, textOption )
1920
import Stack.Options.Completion
2021
( flagCompleter, ghcOptsCompleter, targetCompleter )
2122
import Stack.Options.PackageParser ( readFlag )
23+
import Stack.Options.Utils ( hideMods )
2224
import Stack.Prelude
2325
import Stack.Types.BuildOptsCLI
2426
( ApplyCLIFlag, BuildCommand, BuildOptsCLI (..)
@@ -61,6 +63,10 @@ buildOptsParser cmd = BuildOptsCLI
6163
)
6264
<*> progsOptionsParser
6365
<*> flagsParser
66+
<*> firstBoolFlagsNoDefault
67+
"allow-newer"
68+
"ignoring of lower and upper version bounds in Cabal files."
69+
(hideMods False)
6470
<*> ( flag' BSOnlyDependencies
6571
( long "dependencies-only"
6672
<> help "A synonym for --only-dependencies."

src/Stack/Types/Build/Exception.hs

+3-1
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,9 @@ pprintExceptions exceptions configFile stackRoot isImplicitGlobal parentMap want
541541
then ["also"]
542542
else
543543
[ fillSep
544-
$ [ "in"
544+
$ [ "pass"
545+
, style Shell "--allow-newer" <> ","
546+
, flow "or, in"
545547
, pretty (defaultUserConfigPath stackRoot)
546548
, flow
547549
( "(global configuration)"

src/Stack/Types/BuildOptsCLI.hs

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ import qualified Data.Map.Strict as Map
1919
import qualified Data.Text as T
2020
import Stack.Prelude
2121

22-
-- | Build options that may only be specified from the CLI
22+
-- | Build options that are specified from the CLI and not specified as
23+
-- non-project specific configuration options under the build key.
2324
data BuildOptsCLI = BuildOptsCLI
2425
{ targetsCLI :: ![Text]
2526
, dryrun :: !Bool
2627
, ghcOptions :: ![Text]
2728
, progsOptions :: ![(Text, [Text])]
2829
, flags :: !(Map ApplyCLIFlag (Map FlagName Bool))
30+
, allowNewer :: !(First Bool)
2931
, buildSubset :: !BuildSubset
3032
, fileWatch :: !FileWatchOpts
3133
, watchAll :: !Bool
@@ -41,6 +43,7 @@ defaultBuildOptsCLI = BuildOptsCLI
4143
{ targetsCLI = []
4244
, dryrun = False
4345
, flags = Map.empty
46+
, allowNewer = mempty
4447
, ghcOptions = []
4548
, progsOptions = []
4649
, buildSubset = BSAll

src/Stack/Types/BuildOptsMonoid.hs

+5-1
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@ import Generics.Deriving.Monoid ( mappenddefault, memptydefault )
3333
import Stack.Prelude hiding ( trace )
3434
import Stack.Types.ComponentUtils ( StackUnqualCompName )
3535

36-
-- | Build options that may be specified in the stack.yaml or from the CLI
36+
-- | Build options that may be specified as non-project specific configuration
37+
-- options under the build key (with certain exceptions) or from the CLI.
3738
data BuildOptsMonoid = BuildOptsMonoid
3839
{ trace :: !Any
40+
-- ^ Cannot be specified under the build key
3941
, profile :: !Any
42+
-- ^ Cannot be specified under the build key
4043
, noStrip :: !Any
44+
-- ^ Cannot be specified under the build key
4145
, libProfile :: !FirstFalse
4246
, exeProfile :: !FirstFalse
4347
, libStrip :: !FirstTrue

src/Stack/Types/Config.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ data Config = Config
153153
, applyProgOptions :: !ApplyProgOptions
154154
-- ^ Which packages do all and any --PROG-option options on the command line
155155
-- apply to?
156-
, allowNewer :: !Bool
156+
, allowNewer :: !(First Bool)
157157
-- ^ Ignore version ranges in .cabal files. Funny naming chosen to
158158
-- match cabal.
159159
, allowNewerDeps :: !(Maybe [PackageName])

0 commit comments

Comments
 (0)