Skip to content

Commit e140b3a

Browse files
authored
Merge pull request #6051 from commercialhaskell/fix6050
Fix #6050 Drop Cabal versions before 1.22.
2 parents c09fd4f + 51f3a94 commit e140b3a

File tree

4 files changed

+32
-57
lines changed

4 files changed

+32
-57
lines changed

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Major changes:
1010

1111
Behavior changes:
1212

13+
* Drop support for `Cabal` versions before 1.22 and, consequently, GHC versions
14+
before 7.10.
1315
* `stack ghci` and `stack repl` now take into account the values of
1416
`default-language` keys in Cabal files, like they take into account the values
1517
of `default-extensions` keys.

doc/maintainers/stack_errors.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
In connection with considering Stack's support of the
66
[Haskell Error Index](https://errors.haskell.org/) initiative, this page seeks
77
to take stock of the errors that Stack itself can raise, by reference to the
8-
`master` branch of the Stack repository. Last updated: 2023-01-21.
8+
`master` branch of the Stack repository. Last updated: 2023-02-02.
99

1010
* `Main.main`: catches exceptions from action `commandLineHandler`.
1111

@@ -60,11 +60,10 @@ to take stock of the errors that Stack itself can raise, by reference to the
6060
[S-1711] | CannotApplySelector Value [Text]
6161
~~~
6262

63-
- `Stack.Build.CabalVersionException`
63+
- `Stack.Build.CabalVersionPrettyException`
6464

6565
~~~haskell
66-
[S-8503] = AllowNewerNotSupported Version
67-
[S-5973] | CabalVersionNotSupported Version
66+
[S-5973] = CabalVersionNotSupported Version
6867
~~~
6968

7069
- `Stack.Build.ConstructPlan.NotOnlyLocal`

src/Stack/Build.hs

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ module Stack.Build
1111
, mkBaseConfigOpts
1212
, queryBuildInfo
1313
, splitObjsWarning
14-
, CabalVersionException (..)
1514
) where
1615

1716
import Data.Aeson ( Value (Object, Array), (.=), object )
@@ -62,27 +61,26 @@ import Stack.Types.SourceMap
6261
, SourceMap (..), Target (..) )
6362
import System.Terminal ( fixCodePage )
6463

65-
data CabalVersionException
66-
= AllowNewerNotSupported Version
67-
| CabalVersionNotSupported Version
64+
newtype CabalVersionPrettyException
65+
= CabalVersionNotSupported Version
6866
deriving (Show, Typeable)
6967

70-
instance Exception CabalVersionException where
71-
displayException (AllowNewerNotSupported cabalVer) = concat
72-
[ "Error: [S-8503]\n"
73-
, "'--allow-newer' requires Cabal version 1.22 or greater, but "
74-
, "version "
75-
, versionString cabalVer
76-
, " was found."
77-
]
78-
displayException (CabalVersionNotSupported cabalVer) = concat
79-
[ "Error: [S-5973]\n"
80-
, "Stack no longer supports Cabal versions before 1.19.2, "
81-
, "but version "
82-
, versionString cabalVer
83-
, " was found. To fix this, consider updating the resolver to lts-3.0 "
84-
, "or later or to nightly-2015-05-05 or later."
85-
]
68+
instance Pretty CabalVersionPrettyException where
69+
pretty (CabalVersionNotSupported cabalVer) =
70+
"[S-5973]"
71+
<> line
72+
<> fillSep
73+
[ flow "Stack does not support Cabal versions before 1.22, but \
74+
\version"
75+
, fromString $ versionString cabalVer
76+
, flow "was found. To fix this, consider updating the snapshot to"
77+
, style Shell "lts-3.0"
78+
, flow "or later or to"
79+
, style Shell "nightly-2015-05-05"
80+
, flow "or later."
81+
]
82+
83+
instance Exception CabalVersionPrettyException
8684

8785
data QueryException
8886
= SelectorNotFound [Text]
@@ -193,17 +191,9 @@ justLocals =
193191

194192
checkCabalVersion :: HasEnvConfig env => RIO env ()
195193
checkCabalVersion = do
196-
allowNewer <- view $ configL.to configAllowNewer
197194
cabalVer <- view cabalVersionL
198-
-- https://github.com/haskell/cabal/issues/2023
199-
when (allowNewer && cabalVer < mkVersion [1, 22]) $ throwM $
200-
AllowNewerNotSupported cabalVer
201-
-- Since --exact-configuration is always passed, some old cabal
202-
-- versions can no longer be used. See the following link for why
203-
-- it's 1.19.2:
204-
-- https://github.com/haskell/cabal/blob/580fe6b6bf4e1648b2f66c1cb9da9f1f1378492c/cabal-install/Distribution/Client/Setup.hs#L592
205-
when (cabalVer < mkVersion [1, 19, 2]) $ throwM $
206-
CabalVersionNotSupported cabalVer
195+
when (cabalVer < mkVersion [1, 22]) $
196+
prettyThrowM $ CabalVersionNotSupported cabalVer
207197

208198
-- | See https://github.com/commercialhaskell/stack/issues/1198.
209199
warnIfExecutablesWithSameNameCouldBeOverwritten ::

src/Stack/Types/Build.hs

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ import Stack.Types.Config
8282
( BenchmarkOpts (..), BuildOpts (..), BuildOptsCLI
8383
, BuildSubset (..), Config (..), DumpPackage, EnvConfig
8484
, FileWatchOpts (..), GHCVariant, HasConfig (..)
85-
, TestOpts (..), actualCompilerVersionL, cabalVersionL
86-
, defaultBuildOpts, ghcVariantSuffix
85+
, TestOpts (..), actualCompilerVersionL, defaultBuildOpts
86+
, ghcVariantSuffix
8787
)
8888
import Stack.Types.GhcPkgId ( GhcPkgId, ghcPkgIdString )
8989
import Stack.Types.NamedComponent
@@ -1136,13 +1136,10 @@ configureOptsNoDir :: EnvConfig
11361136
-> [String]
11371137
configureOptsNoDir econfig bco deps isLocal package = concat
11381138
[ depOptions
1139-
, ["--enable-library-profiling" | boptsLibProfile bopts || boptsExeProfile bopts]
1140-
-- Cabal < 1.21.1 does not support --enable-profiling, use
1141-
-- --enable-executable-profiling instead
1142-
, let profFlag = "--enable-"
1143-
<> concat ["executable-" | not newerCabal]
1144-
<> "profiling"
1145-
in [ profFlag | boptsExeProfile bopts && isLocal]
1139+
, [ "--enable-library-profiling"
1140+
| boptsLibProfile bopts || boptsExeProfile bopts
1141+
]
1142+
, ["--enable-profiling" | boptsExeProfile bopts && isLocal]
11461143
, ["--enable-split-objs" | boptsSplitObjs bopts]
11471144
, [ "--disable-library-stripping"
11481145
| not $ boptsLibStrip bopts || boptsExeStrip bopts
@@ -1206,32 +1203,19 @@ configureOptsNoDir econfig bco deps isLocal package = concat
12061203
config = view configL econfig
12071204
bopts = bcoBuildOpts bco
12081205

1209-
newerCabal = view cabalVersionL econfig >= C.mkVersion [1, 22]
1210-
12111206
-- Unioning atop defaults is needed so that all flags are specified with
12121207
-- --exact-configuration.
12131208
flags = packageFlags package `Map.union` packageDefaultFlags package
12141209

12151210
depOptions = map (uncurry toDepOption) $ Map.toList deps
1216-
where
1217-
toDepOption = if newerCabal then toDepOption1_22 else toDepOption1_18
12181211

1219-
toDepOption1_22 (PackageIdentifier name _) gid = concat
1212+
toDepOption (PackageIdentifier name _) gid = concat
12201213
[ "--dependency="
12211214
, packageNameString name
12221215
, "="
12231216
, ghcPkgIdString gid
12241217
]
12251218

1226-
toDepOption1_18 ident _gid = concat
1227-
[ "--constraint="
1228-
, packageNameString name
1229-
, "=="
1230-
, versionString version'
1231-
]
1232-
where
1233-
PackageIdentifier name version' = ident
1234-
12351219
-- | Get set of wanted package names from locals.
12361220
wantedLocalPackages :: [LocalPackage] -> Set PackageName
12371221
wantedLocalPackages =

0 commit comments

Comments
 (0)