Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix repl discarding --build-depends after allow-newer/older #8732

Merged
merged 5 commits into from
Feb 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Distribution.Types.GenericPackageDescription (
Expand Down Expand Up @@ -86,15 +85,14 @@ instance L.HasBuildInfos GenericPackageDescription where
<*> (traverse . L._2 . traverseCondTreeBuildInfo) f x4
<*> (traverse . L._2 . traverseCondTreeBuildInfo) f x5
<*> (traverse . L._2 . traverseCondTreeBuildInfo) f x6
where

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

node (CondNode comp _ branches) = mkCondNode
<$> L.buildInfo g comp
Expand Down
9 changes: 7 additions & 2 deletions cabal-install/src/Distribution/Client/CmdRepl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ import Distribution.Types.BuildInfo
import Distribution.Types.ComponentName
( componentNameString )
import Distribution.Types.CondTree
( CondTree(..), traverseCondTreeC )
( CondTree(..) )
import Distribution.Types.Dependency
( Dependency(..), mainLibSet )
import Distribution.Types.Library
Expand Down Expand Up @@ -338,7 +338,12 @@ addDepsToProjectTarget deps pkgId ctx =
| packageId pkg /= pkgId = SpecificSourcePackage pkg
| SourcePackage{..} <- pkg =
SpecificSourcePackage $ pkg { srcpkgDescription =
srcpkgDescription & (\f -> L.allCondTrees $ traverseCondTreeC f)
-- New dependencies are added to the original ones found in the
-- `targetBuildDepends` field.
-- `traverseBuildInfos` is used in order to update _all_ the
-- occurrences of the field `targetBuildDepends`. It ensures that
-- fields depending on the latter are also consistently updated.
srcpkgDescription & (L.traverseBuildInfos . L.targetBuildDepends)
%~ (deps ++)
}
addDeps spec = spec
Expand Down
4 changes: 4 additions & 0 deletions cabal-testsuite/PackageTests/ReplBuildDepends/Foo.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Foo where

a :: Int
a = 42
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# cabal clean
# cabal repl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# cabal clean
# cabal repl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# cabal clean
# cabal repl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
19 changes: 19 additions & 0 deletions cabal-testsuite/PackageTests/ReplBuildDepends/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Test.Cabal.Prelude

-- Test “repl --build-depends”
main = do
testWithByteString "normal" []
-- See https://github.com/haskell/cabal/issues/6859
testWithByteString "allow-newer" ["--allow-newer"]
-- See https://github.com/haskell/cabal/issues/6859
testWithByteString "allow-older" ["--allow-older"]
where
testWithByteString label extraArgs = cabalTest' label $ do
cabal' "clean" []
res <- cabalWithStdin
"repl"
("-v2" : "--build-depends" : "bytestring" : extraArgs)
"import qualified Data.ByteString as BS"
assertOutputContains "Ok, one module loaded." res
-- Ensure we can load ‘bytestring’
assertOutputDoesNotContain "Could not load" res
7 changes: 7 additions & 0 deletions cabal-testsuite/PackageTests/ReplBuildDepends/pkg.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cabal-version: 2.4
name: pkg
version: 0.1.0.0
library
exposed-modules: Foo
build-depends: base
default-language: Haskell2010
10 changes: 10 additions & 0 deletions changelog.d/pr-8732
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
synopsis: Fix repl discarding --build-depends
packages: cabal-install
prs: #8732
issues: #6859 #7081

description: {

- Fix `repl` command discarding `--build-depends` argument when using
`allow-newer` or `allow-older`.
}