Skip to content

Commit

Permalink
Make Cabal check fail on private deps
Browse files Browse the repository at this point in the history
Hackage is not yet ready for private dependencies, so we mustn't allow
packages with private deps to be uploaded just yet.

Hackage already rejects packages using too-recent cabal versions,
however, private dependencies is a special case which must be guarded
against until more extensive benchmarks regarding the performance of
solving private dependencies mixed in with a lot of backtracking.

See haskell#9743
  • Loading branch information
alt-romes committed Jul 1, 2024
1 parent ed80172 commit 672719a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Cabal-syntax/src/Distribution/Types/PackageDescription.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module Distribution.Types.PackageDescription
, buildType
, emptyPackageDescription
, hasPublicLib
, hasPrivateDependencies
, hasLibs
, allLibraries
, withLib
Expand All @@ -59,6 +60,7 @@ module Distribution.Types.PackageDescription

import Distribution.Compat.Prelude
import Prelude ()
import qualified Data.List

-- lens

Expand Down Expand Up @@ -366,6 +368,12 @@ allBuildDepends pd = do
[(Public, d) | d <- targetBuildDepends bi]
++ [(Private p, d) | PrivateDependency p ds <- targetPrivateBuildDepends bi, d <- ds]

-- | Does this package have any private dependencies? At the moment, cabal
-- check will reject any packages that do.
hasPrivateDependencies :: PackageDescription -> Bool
hasPrivateDependencies pd = not . Data.List.null $

Check warning on line 374 in Cabal-syntax/src/Distribution/Types/PackageDescription.hs

View workflow job for this annotation

GitHub Actions / hlint

Warning in hasPrivateDependencies in module Distribution.Types.PackageDescription: Use all ▫︎ Found: "not . Data.List.null\n $ concatMap targetPrivateBuildDepends (allBuildInfo pd)" ▫︎ Perhaps: "Data.List.not\n (Data.List.all\n (Data.List.null Data.List.. targetPrivateBuildDepends)\n (allBuildInfo pd))"
concatMap targetPrivateBuildDepends (allBuildInfo pd)

-- | Get the combined build-depends entries of all enabled components, per the
-- given request spec.
enabledBuildDepends :: PackageDescription -> ComponentRequestedSpec -> [(IsPrivate, Dependency)]
Expand Down
2 changes: 2 additions & 0 deletions Cabal/src/Distribution/PackageDescription/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ checkPackageDescription
(PackageBuildImpossible $ IllegalLibraryName pn)

-- § Fields check.
checkP (hasPrivateDependencies pkg)
(PackageDistInexcusable HasPrivateDependencies)
checkNull
category_
(PackageDistSuspicious MissingFieldCategory)
Expand Down
13 changes: 13 additions & 0 deletions Cabal/src/Distribution/PackageDescription/Check/Warning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ data CheckExplanation
| MissingSourceControl
| MissingExpectedDocFiles Bool [FilePath]
| WrongFieldForExpectedDocFiles Bool String [FilePath]
| HasPrivateDependencies
deriving (Eq, Ord, Show)

-- TODO Some checks have a constructor in list form
Expand Down Expand Up @@ -441,6 +442,7 @@ data CheckExplanationID
| CIMissingSourceControl
| CIMissingExpectedDocFiles
| CIWrongFieldForExpectedDocFiles
| CIHasPrivateDependencies
deriving (Eq, Ord, Show, Enum, Bounded)

checkExplanationId :: CheckExplanation -> CheckExplanationID
Expand Down Expand Up @@ -582,6 +584,7 @@ checkExplanationId (UnknownDirectory{}) = CIUnknownDirectory
checkExplanationId (MissingSourceControl{}) = CIMissingSourceControl
checkExplanationId (MissingExpectedDocFiles{}) = CIMissingExpectedDocFiles
checkExplanationId (WrongFieldForExpectedDocFiles{}) = CIWrongFieldForExpectedDocFiles
checkExplanationId (HasPrivateDependencies{}) = CIHasPrivateDependencies

type CheckExplanationIDString = String

Expand Down Expand Up @@ -728,6 +731,7 @@ ppCheckExplanationId CIUnknownDirectory = "unknown-directory"
ppCheckExplanationId CIMissingSourceControl = "no-repository"
ppCheckExplanationId CIMissingExpectedDocFiles = "no-docs"
ppCheckExplanationId CIWrongFieldForExpectedDocFiles = "doc-place"
ppCheckExplanationId CIHasPrivateDependencies = "has-private-deps"

-- String: the unrecognised 'CheckExplanationIDString' itself.
readExplanationID
Expand Down Expand Up @@ -1460,6 +1464,15 @@ ppExplanation (WrongFieldForExpectedDocFiles extraDocFileSupport field paths) =
if extraDocFileSupport
then "extra-doc-files"
else "extra-source-files"
-- Private dependencies are a special case which must be guarded
-- against until more extensive benchmarks regarding the performance of
-- solving private dependencies mixed in with a lot of backtracking.
-- See https://github.com/haskell/cabal/pull/9743
ppExplanation HasPrivateDependencies =
"Private dependencies are in a feature-preview state, "
++ "therefore packages using them cannot be uploaded to hackage.\n"
++ "For instance, how would hackage display the private dependencies of the package?"


-- * Formatting utilities

Expand Down

0 comments on commit 672719a

Please sign in to comment.