Skip to content

Commit

Permalink
Do not check PVP on internal targets (#9004)
Browse files Browse the repository at this point in the history
* Do not check PVP on internal targets

Internal targets: test-suites or benchmarks.
See #8361 for rationale.

Note that this patch is quite ugly (duplicating allBuildInfo, using
list comprehensions, etc.) but we don’t care as everything will be
overwritten by a much more sensible reimplementation in #8427.

* Add changelog for #9004

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
ffaf1 and mergify[bot] authored Jun 11, 2023
1 parent 14a0103 commit 1cb92a3
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Cabal/src/Distribution/PackageDescription/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import System.FilePath
, (</>)
)

import qualified Control.Monad as CM
import qualified Data.ByteString.Lazy as BS
import qualified Data.Map as Map
import qualified Distribution.Compat.DList as DList
Expand Down Expand Up @@ -2109,7 +2110,7 @@ checkPackageVersions pkg =
else baseErrors
where
baseErrors = PackageDistInexcusable BaseNoUpperBounds <$ bases
deps = toDependencyVersionsMap allBuildDepends pkg
deps = toDependencyVersionsMap allNonInternalBuildDepends pkg
-- base gets special treatment (it's more critical)
(bases, others) =
partition (("base" ==) . unPackageName) $
Expand All @@ -2118,6 +2119,16 @@ checkPackageVersions pkg =
, not (hasUpperBound vr)
]

-- Get the combined build-depends entries of all components.
allNonInternalBuildDepends :: PackageDescription -> [Dependency]
allNonInternalBuildDepends = targetBuildDepends CM.<=< allNonInternalBuildInfo

allNonInternalBuildInfo :: PackageDescription -> [BuildInfo]
allNonInternalBuildInfo pkg_descr =
[bi | lib <- allLibraries pkg_descr, let bi = libBuildInfo lib]
++ [bi | flib <- foreignLibs pkg_descr, let bi = foreignLibBuildInfo flib]
++ [bi | exe <- executables pkg_descr, let bi = buildInfo exe]

checkConditionals :: GenericPackageDescription -> [PackageCheck]
checkConditionals pkg =
catMaybes
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# cabal check
No errors or warnings could be found in the package.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Test.Cabal.Prelude

-- Internal targets (tests, benchmarks) should not be checked.
main = cabalTest $
cabal "check" []
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cabal-version: 3.0
name: pkg
synopsis: synopsis
description: description
version: 0
category: example
maintainer: none@example.com
license: GPL-3.0-or-later

library
exposed-modules: Foo
default-language: Haskell2010
build-depends: base == 2.2.*

test-suite test
type: exitcode-stdio-1.0
main-is: Test.hs
default-language: Haskell2010
build-depends: base == 2.2.*,
criterion

11 changes: 11 additions & 0 deletions changelog.d/pr-9004
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
synopsis: Do not check PVP on internal targets
packages: cabal-install
prs: #9004
issues: #8361

description: {

- `cabal check` will not check for dependencies upper bounds in internal
targets (i.e. test-suites and benchmarks)

}

0 comments on commit 1cb92a3

Please sign in to comment.