Skip to content

Commit 05b0630

Browse files
authored
Merge pull request #8762 from haskell/mergify/bp/3.10/pr-8732
Fix repl discarding --build-depends (backport #8732)
2 parents ec5cb9a + 7a619e6 commit 05b0630

File tree

10 files changed

+55
-5
lines changed

10 files changed

+55
-5
lines changed

Cabal-syntax/src/Distribution/Types/GenericPackageDescription.hs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{-# LANGUAGE DeriveDataTypeable #-}
22
{-# LANGUAGE DeriveGeneric #-}
33
{-# LANGUAGE FlexibleContexts #-}
4-
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
54
{-# LANGUAGE ScopedTypeVariables #-}
65

76
module Distribution.Types.GenericPackageDescription (
@@ -86,15 +85,14 @@ instance L.HasBuildInfos GenericPackageDescription where
8685
<*> (traverse . L._2 . traverseCondTreeBuildInfo) f x4
8786
<*> (traverse . L._2 . traverseCondTreeBuildInfo) f x5
8887
<*> (traverse . L._2 . traverseCondTreeBuildInfo) f x6
89-
where
9088

9189
-- We use this traversal to keep [Dependency] field in CondTree up to date.
9290
traverseCondTreeBuildInfo
9391
:: forall f comp v. (Applicative f, L.HasBuildInfo comp)
9492
=> LensLike' f (CondTree v [Dependency] comp) L.BuildInfo
9593
traverseCondTreeBuildInfo g = node where
9694
mkCondNode :: comp -> [CondBranch v [Dependency] comp] -> CondTree v [Dependency] comp
97-
mkCondNode comp branches = CondNode comp (view L.targetBuildDepends comp) branches
95+
mkCondNode comp = CondNode comp (view L.targetBuildDepends comp)
9896

9997
node (CondNode comp _ branches) = mkCondNode
10098
<$> L.buildInfo g comp

cabal-install/src/Distribution/Client/CmdRepl.hs

+7-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ import Distribution.Types.BuildInfo
7575
import Distribution.Types.ComponentName
7676
( componentNameString )
7777
import Distribution.Types.CondTree
78-
( CondTree(..), traverseCondTreeC )
78+
( CondTree(..) )
7979
import Distribution.Types.Dependency
8080
( Dependency(..), mainLibSet )
8181
import Distribution.Types.Library
@@ -338,7 +338,12 @@ addDepsToProjectTarget deps pkgId ctx =
338338
| packageId pkg /= pkgId = SpecificSourcePackage pkg
339339
| SourcePackage{..} <- pkg =
340340
SpecificSourcePackage $ pkg { srcpkgDescription =
341-
srcpkgDescription & (\f -> L.allCondTrees $ traverseCondTreeC f)
341+
-- New dependencies are added to the original ones found in the
342+
-- `targetBuildDepends` field.
343+
-- `traverseBuildInfos` is used in order to update _all_ the
344+
-- occurrences of the field `targetBuildDepends`. It ensures that
345+
-- fields depending on the latter are also consistently updated.
346+
srcpkgDescription & (L.traverseBuildInfos . L.targetBuildDepends)
342347
%~ (deps ++)
343348
}
344349
addDeps spec = spec
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Foo where
2+
3+
a :: Int
4+
a = 42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# cabal clean
2+
# cabal repl
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# cabal clean
2+
# cabal repl
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# cabal clean
2+
# cabal repl
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: .
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Test.Cabal.Prelude
2+
3+
-- Test “repl --build-depends”
4+
main = do
5+
testWithByteString "normal" []
6+
-- See https://github.com/haskell/cabal/issues/6859
7+
testWithByteString "allow-newer" ["--allow-newer"]
8+
-- See https://github.com/haskell/cabal/issues/6859
9+
testWithByteString "allow-older" ["--allow-older"]
10+
where
11+
testWithByteString label extraArgs = cabalTest' label $ do
12+
cabal' "clean" []
13+
res <- cabalWithStdin
14+
"repl"
15+
("-v2" : "--build-depends" : "bytestring" : extraArgs)
16+
"import qualified Data.ByteString as BS"
17+
assertOutputContains "Ok, one module loaded." res
18+
-- Ensure we can load ‘bytestring’
19+
assertOutputDoesNotContain "Could not load" res
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cabal-version: 2.4
2+
name: pkg
3+
version: 0.1.0.0
4+
library
5+
exposed-modules: Foo
6+
build-depends: base
7+
default-language: Haskell2010

changelog.d/pr-8732

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
synopsis: Fix repl discarding --build-depends
2+
packages: cabal-install
3+
prs: #8732
4+
issues: #6859 #7081
5+
6+
description: {
7+
8+
- Fix `repl` command discarding `--build-depends` argument when using
9+
`allow-newer` or `allow-older`.
10+
}

0 commit comments

Comments
 (0)