Skip to content

Commit e99edf2

Browse files
committed
Make Cabal check fail on private deps
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
1 parent ed80172 commit e99edf2

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module Distribution.Types.PackageDescription
3434
, buildType
3535
, emptyPackageDescription
3636
, hasPublicLib
37+
, hasPrivateDependencies
3738
, hasLibs
3839
, allLibraries
3940
, withLib
@@ -59,6 +60,7 @@ module Distribution.Types.PackageDescription
5960

6061
import Distribution.Compat.Prelude
6162
import Prelude ()
63+
import qualified Data.List
6264

6365
-- lens
6466

@@ -366,6 +368,11 @@ allBuildDepends pd = do
366368
[(Public, d) | d <- targetBuildDepends bi]
367369
++ [(Private p, d) | PrivateDependency p ds <- targetPrivateBuildDepends bi, d <- ds]
368370

371+
-- | Does this package have any private dependencies? At the moment, cabal
372+
-- check will reject any packages that do.
373+
hasPrivateDependencies :: PackageDescription -> Bool
374+
hasPrivateDependencies pd = not $ Data.List.all (Data.List.null . targetPrivateBuildDepends) $ allBuildInfo pd
375+
369376
-- | Get the combined build-depends entries of all enabled components, per the
370377
-- given request spec.
371378
enabledBuildDepends :: PackageDescription -> ComponentRequestedSpec -> [(IsPrivate, Dependency)]

Cabal/src/Distribution/PackageDescription/Check.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@ checkPackageDescription
428428
(PackageBuildImpossible $ IllegalLibraryName pn)
429429

430430
-- § Fields check.
431+
checkP (hasPrivateDependencies pkg)
432+
(PackageDistInexcusable HasPrivateDependencies)
431433
checkNull
432434
category_
433435
(PackageDistSuspicious MissingFieldCategory)

Cabal/src/Distribution/PackageDescription/Check/Warning.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ data CheckExplanation
279279
| MissingSourceControl
280280
| MissingExpectedDocFiles Bool [FilePath]
281281
| WrongFieldForExpectedDocFiles Bool String [FilePath]
282+
| HasPrivateDependencies
282283
deriving (Eq, Ord, Show)
283284

284285
-- TODO Some checks have a constructor in list form
@@ -441,6 +442,7 @@ data CheckExplanationID
441442
| CIMissingSourceControl
442443
| CIMissingExpectedDocFiles
443444
| CIWrongFieldForExpectedDocFiles
445+
| CIHasPrivateDependencies
444446
deriving (Eq, Ord, Show, Enum, Bounded)
445447

446448
checkExplanationId :: CheckExplanation -> CheckExplanationID
@@ -582,6 +584,7 @@ checkExplanationId (UnknownDirectory{}) = CIUnknownDirectory
582584
checkExplanationId (MissingSourceControl{}) = CIMissingSourceControl
583585
checkExplanationId (MissingExpectedDocFiles{}) = CIMissingExpectedDocFiles
584586
checkExplanationId (WrongFieldForExpectedDocFiles{}) = CIWrongFieldForExpectedDocFiles
587+
checkExplanationId (HasPrivateDependencies{}) = CIHasPrivateDependencies
585588

586589
type CheckExplanationIDString = String
587590

@@ -728,6 +731,7 @@ ppCheckExplanationId CIUnknownDirectory = "unknown-directory"
728731
ppCheckExplanationId CIMissingSourceControl = "no-repository"
729732
ppCheckExplanationId CIMissingExpectedDocFiles = "no-docs"
730733
ppCheckExplanationId CIWrongFieldForExpectedDocFiles = "doc-place"
734+
ppCheckExplanationId CIHasPrivateDependencies = "has-private-deps"
731735

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

14641477
-- * Formatting utilities
14651478

0 commit comments

Comments
 (0)