diff --git a/Cabal-syntax/src/Distribution/Types/GenericPackageDescription.hs b/Cabal-syntax/src/Distribution/Types/GenericPackageDescription.hs index 24b2c4d0f08..ee8f9d5284b 100644 --- a/Cabal-syntax/src/Distribution/Types/GenericPackageDescription.hs +++ b/Cabal-syntax/src/Distribution/Types/GenericPackageDescription.hs @@ -1,7 +1,6 @@ {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE ScopedTypeVariables #-} module Distribution.Types.GenericPackageDescription ( @@ -86,7 +85,6 @@ 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 @@ -94,7 +92,7 @@ traverseCondTreeBuildInfo => 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 diff --git a/cabal-install/src/Distribution/Client/CmdRepl.hs b/cabal-install/src/Distribution/Client/CmdRepl.hs index be129b042f4..dcf659f036a 100644 --- a/cabal-install/src/Distribution/Client/CmdRepl.hs +++ b/cabal-install/src/Distribution/Client/CmdRepl.hs @@ -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 @@ -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 diff --git a/cabal-testsuite/PackageTests/ReplBuildDepends/Foo.hs b/cabal-testsuite/PackageTests/ReplBuildDepends/Foo.hs new file mode 100644 index 00000000000..8a39fe134cf --- /dev/null +++ b/cabal-testsuite/PackageTests/ReplBuildDepends/Foo.hs @@ -0,0 +1,4 @@ +module Foo where + +a :: Int +a = 42 diff --git a/cabal-testsuite/PackageTests/ReplBuildDepends/cabal.allow-newer.out b/cabal-testsuite/PackageTests/ReplBuildDepends/cabal.allow-newer.out new file mode 100644 index 00000000000..f7fe5f202cf --- /dev/null +++ b/cabal-testsuite/PackageTests/ReplBuildDepends/cabal.allow-newer.out @@ -0,0 +1,2 @@ +# cabal clean +# cabal repl diff --git a/cabal-testsuite/PackageTests/ReplBuildDepends/cabal.allow-older.out b/cabal-testsuite/PackageTests/ReplBuildDepends/cabal.allow-older.out new file mode 100644 index 00000000000..f7fe5f202cf --- /dev/null +++ b/cabal-testsuite/PackageTests/ReplBuildDepends/cabal.allow-older.out @@ -0,0 +1,2 @@ +# cabal clean +# cabal repl diff --git a/cabal-testsuite/PackageTests/ReplBuildDepends/cabal.normal.out b/cabal-testsuite/PackageTests/ReplBuildDepends/cabal.normal.out new file mode 100644 index 00000000000..f7fe5f202cf --- /dev/null +++ b/cabal-testsuite/PackageTests/ReplBuildDepends/cabal.normal.out @@ -0,0 +1,2 @@ +# cabal clean +# cabal repl diff --git a/cabal-testsuite/PackageTests/ReplBuildDepends/cabal.project b/cabal-testsuite/PackageTests/ReplBuildDepends/cabal.project new file mode 100644 index 00000000000..e6fdbadb439 --- /dev/null +++ b/cabal-testsuite/PackageTests/ReplBuildDepends/cabal.project @@ -0,0 +1 @@ +packages: . diff --git a/cabal-testsuite/PackageTests/ReplBuildDepends/cabal.test.hs b/cabal-testsuite/PackageTests/ReplBuildDepends/cabal.test.hs new file mode 100644 index 00000000000..e5b63af3dae --- /dev/null +++ b/cabal-testsuite/PackageTests/ReplBuildDepends/cabal.test.hs @@ -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 diff --git a/cabal-testsuite/PackageTests/ReplBuildDepends/pkg.cabal b/cabal-testsuite/PackageTests/ReplBuildDepends/pkg.cabal new file mode 100644 index 00000000000..c6cc87f1117 --- /dev/null +++ b/cabal-testsuite/PackageTests/ReplBuildDepends/pkg.cabal @@ -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 diff --git a/changelog.d/pr-8732 b/changelog.d/pr-8732 new file mode 100644 index 00000000000..2417885d15b --- /dev/null +++ b/changelog.d/pr-8732 @@ -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`. +} \ No newline at end of file