Skip to content

Commit d6831f7

Browse files
committed
Revert "Merge pull request #4383 from Ericson2314/no-legacy-build-depends"
This reverts commit ea75854, reversing changes made to 602dfdc. See #5119 for the reason for reverting this.
1 parent ccb3350 commit d6831f7

33 files changed

+116
-87
lines changed

Cabal/Distribution/PackageDescription.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ module Distribution.PackageDescription (
8383
hcStaticOptions,
8484

8585
-- ** Supplementary build information
86-
allBuildDepends,
87-
enabledBuildDepends,
8886
ComponentName(..),
8987
defaultLibName,
9088
HookedBuildInfo,

Cabal/Distribution/PackageDescription/Check.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,7 @@ checkCabalVersion pkg =
13631363
_ -> False
13641364

13651365
versionRangeExpressions =
1366-
[ dep | dep@(Dependency _ vr) <- allBuildDepends pkg
1366+
[ dep | dep@(Dependency _ vr) <- buildDepends pkg
13671367
, usesNewVersionRangeSyntax vr ]
13681368

13691369
testedWithVersionRangeExpressions =
@@ -1391,10 +1391,10 @@ checkCabalVersion pkg =
13911391
alg (VersionRangeParensF _) = 3
13921392
alg _ = 1 :: Int
13931393

1394-
depsUsingWildcardSyntax = [ dep | dep@(Dependency _ vr) <- allBuildDepends pkg
1394+
depsUsingWildcardSyntax = [ dep | dep@(Dependency _ vr) <- buildDepends pkg
13951395
, usesWildcardSyntax vr ]
13961396

1397-
depsUsingMajorBoundSyntax = [ dep | dep@(Dependency _ vr) <- allBuildDepends pkg
1397+
depsUsingMajorBoundSyntax = [ dep | dep@(Dependency _ vr) <- buildDepends pkg
13981398
, usesMajorBoundSyntax vr ]
13991399

14001400
usesBackpackIncludes = any (not . null . mixins) (allBuildInfo pkg)
@@ -1541,7 +1541,7 @@ checkPackageVersions pkg =
15411541
foldr intersectVersionRanges anyVersion baseDeps
15421542
where
15431543
baseDeps =
1544-
[ vr | Dependency pname vr <- allBuildDepends pkg'
1544+
[ vr | Dependency pname vr <- buildDepends pkg'
15451545
, pname == mkPackageName "base" ]
15461546

15471547
-- Just in case finalizePD fails for any reason,

Cabal/Distribution/PackageDescription/Configuration.hs

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@ import Distribution.Compiler
4444
import Distribution.System
4545
import Distribution.Simple.Utils
4646
import Distribution.Text
47-
import Distribution.Compat.Lens
4847
import Distribution.Compat.ReadP as ReadP hiding ( char )
4948
import qualified Distribution.Compat.ReadP as ReadP ( char )
50-
import qualified Distribution.Types.BuildInfo.Lens as L
5149
import Distribution.Types.ComponentRequestedSpec
5250
import Distribution.Types.ForeignLib
5351
import Distribution.Types.Component
@@ -353,18 +351,18 @@ overallDependencies enabled (TargetSet targets) = mconcat depss
353351
-- | Collect up the targets in a TargetSet of tagged targets, storing the
354352
-- dependencies as we go.
355353
flattenTaggedTargets :: TargetSet PDTagged -> (Maybe Library, [(UnqualComponentName, Component)])
356-
flattenTaggedTargets (TargetSet targets) = foldr untag (Nothing, []) targets where
357-
untag (depMap, pdTagged) accum = case (pdTagged, accum) of
358-
(Lib _, (Just _, _)) -> userBug "Only one library expected"
359-
(Lib l, (Nothing, comps)) -> (Just $ redoBD l, comps)
360-
(SubComp n c, (mb_lib, comps))
361-
| any ((== n) . fst) comps ->
362-
userBug $ "There exist several components with the same name: '" ++ display n ++ "'"
363-
| otherwise -> (mb_lib, (n, redoBD c) : comps)
364-
(PDNull, x) -> x -- actually this should not happen, but let's be liberal
365-
where
366-
redoBD :: L.HasBuildInfo a => a -> a
367-
redoBD = set L.targetBuildDepends $ fromDepMap depMap
354+
flattenTaggedTargets (TargetSet targets) = foldr untag (Nothing, []) targets
355+
where
356+
untag (_, Lib _) (Just _, _) = userBug "Only one library expected"
357+
untag (_, Lib l) (Nothing, comps) = (Just l, comps)
358+
untag (_, SubComp n c) (mb_lib, comps)
359+
| any ((== n) . fst) comps =
360+
userBug $ "There exist several components with the same name: '" ++ unUnqualComponentName n ++ "'"
361+
362+
| otherwise = (mb_lib, (n, c) : comps)
363+
364+
untag (_, PDNull) x = x -- actually this should not happen, but let's be liberal
365+
368366

369367
------------------------------------------------------------------------------
370368
-- Convert GenericPackageDescription to PackageDescription
@@ -449,6 +447,7 @@ finalizePD userflags enabled satisfyDep
449447
, executables = exes'
450448
, testSuites = tests'
451449
, benchmarks = bms'
450+
, buildDepends = fromDepMap (overallDependencies enabled targetSet)
452451
}
453452
, flagVals )
454453
where
@@ -518,25 +517,38 @@ flattenPackageDescription
518517
, executables = reverse exes
519518
, testSuites = reverse tests
520519
, benchmarks = reverse bms
520+
, buildDepends = ldeps
521+
++ reverse sub_ldeps
522+
++ reverse pldeps
523+
++ reverse edeps
524+
++ reverse tdeps
525+
++ reverse bdeps
521526
}
522527
where
523-
mlib = f <$> mlib0
524-
where f lib = (libFillInDefaults . fst . ignoreConditions $ lib) { libName = Nothing }
525-
sub_libs = flattenLib <$> sub_libs0
526-
flibs = flattenFLib <$> flibs0
527-
exes = flattenExe <$> exes0
528-
tests = flattenTst <$> tests0
529-
bms = flattenBm <$> bms0
530-
flattenLib (n, t) = libFillInDefaults $ (fst $ ignoreConditions t)
531-
{ libName = Just n, libExposed = False }
532-
flattenFLib (n, t) = flibFillInDefaults $ (fst $ ignoreConditions t)
533-
{ foreignLibName = n }
534-
flattenExe (n, t) = exeFillInDefaults $ (fst $ ignoreConditions t)
535-
{ exeName = n }
536-
flattenTst (n, t) = testFillInDefaults $ (fst $ ignoreConditions t)
537-
{ testName = n }
538-
flattenBm (n, t) = benchFillInDefaults $ (fst $ ignoreConditions t)
539-
{ benchmarkName = n }
528+
(mlib, ldeps) = case mlib0 of
529+
Just lib -> let (l,ds) = ignoreConditions lib in
530+
(Just ((libFillInDefaults l) { libName = Nothing }), ds)
531+
Nothing -> (Nothing, [])
532+
(sub_libs, sub_ldeps) = foldr flattenLib ([],[]) sub_libs0
533+
(flibs, pldeps) = foldr flattenFLib ([],[]) flibs0
534+
(exes, edeps) = foldr flattenExe ([],[]) exes0
535+
(tests, tdeps) = foldr flattenTst ([],[]) tests0
536+
(bms, bdeps) = foldr flattenBm ([],[]) bms0
537+
flattenLib (n, t) (es, ds) =
538+
let (e, ds') = ignoreConditions t in
539+
( (libFillInDefaults $ e { libName = Just n, libExposed = False }) : es, ds' ++ ds )
540+
flattenFLib (n, t) (es, ds) =
541+
let (e, ds') = ignoreConditions t in
542+
( (flibFillInDefaults $ e { foreignLibName = n }) : es, ds' ++ ds )
543+
flattenExe (n, t) (es, ds) =
544+
let (e, ds') = ignoreConditions t in
545+
( (exeFillInDefaults $ e { exeName = n }) : es, ds' ++ ds )
546+
flattenTst (n, t) (es, ds) =
547+
let (e, ds') = ignoreConditions t in
548+
( (testFillInDefaults $ e { testName = n }) : es, ds' ++ ds )
549+
flattenBm (n, t) (es, ds) =
550+
let (e, ds') = ignoreConditions t in
551+
( (benchFillInDefaults $ e { benchmarkName = n }) : es, ds' ++ ds )
540552

541553
-- This is in fact rather a hack. The original version just overrode the
542554
-- default values, however, when adding conditions we had to switch to a
@@ -608,10 +620,12 @@ transformAllBuildDepends f gpd = gpd'
608620
where
609621
onBI bi = bi { targetBuildDepends = map f $ targetBuildDepends bi }
610622
onSBI stp = stp { setupDepends = map f $ setupDepends stp }
623+
onPD pd = pd { buildDepends = map f $ buildDepends pd }
611624

625+
pd' = onPD $ packageDescription gpd
612626
gpd' = transformAllCondTrees id id id id (map f)
613627
. transformAllBuildInfos onBI onSBI
614-
$ gpd
628+
$ gpd { packageDescription = pd' }
615629

616630
-- | Walk all 'CondTree's inside a 'GenericPackageDescription' and apply
617631
-- appropriate transformations to all nodes. Helper function used by

Cabal/Distribution/PackageDescription/FieldGrammar.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ packageDescriptionFieldGrammar = PackageDescription
8787
<*> optionalFieldDefAla "description" FreeText L.description ""
8888
<*> optionalFieldDefAla "category" FreeText L.category ""
8989
<*> prefixedFields "x-" L.customFieldsPD
90+
<*> pure [] -- build-depends
9091
<*> optionalField "build-type" L.buildTypeRaw
9192
<*> pure Nothing -- custom-setup
9293
-- components

Cabal/Distribution/Simple/Build.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ testSuiteLibV09AsLibAndExe pkg_descr
481481
}
482482
pkg = pkg_descr {
483483
package = (package pkg_descr) { pkgName = mkPackageName $ unMungedPackageName compat_name }
484+
, buildDepends = targetBuildDepends $ testBuildInfo test
484485
, executables = []
485486
, testSuites = []
486487
, subLibraries = [lib]

Cabal/Distribution/Simple/Configure.hs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,15 @@ configure (pkg_descr0, pbi) cfg = do
474474

475475
debug verbosity $ "Finalized package description:\n"
476476
++ showPackageDescription pkg_descr
477+
-- NB: showPackageDescription does not display the AWFUL HACK GLOBAL
478+
-- buildDepends, so we have to display it separately. See #2066
479+
-- Some day, we should eliminate this, so that
480+
-- configureFinalizedPackage returns the set of overall dependencies
481+
-- separately. Then 'configureDependencies' and
482+
-- 'Distribution.PackageDescription.Check' need to be adjusted
483+
-- accordingly.
484+
debug verbosity $ "Finalized build-depends: "
485+
++ intercalate ", " (map display (buildDepends pkg_descr))
477486

478487
checkCompilerProblems verbosity comp pkg_descr enabled
479488
checkPackageProblems verbosity pkg_descr0
@@ -508,7 +517,6 @@ configure (pkg_descr0, pbi) cfg = do
508517
installedPackageSet
509518
requiredDepsMap
510519
pkg_descr
511-
enabled
512520

513521
-- Compute installation directory templates, based on user
514522
-- configuration.
@@ -1014,15 +1022,14 @@ configureDependencies
10141022
-> InstalledPackageIndex -- ^ installed packages
10151023
-> Map PackageName InstalledPackageInfo -- ^ required deps
10161024
-> PackageDescription
1017-
-> ComponentRequestedSpec
10181025
-> IO [PreExistingComponent]
10191026
configureDependencies verbosity use_external_internal_deps
1020-
internalPackageSet installedPackageSet requiredDepsMap pkg_descr enableSpec = do
1027+
internalPackageSet installedPackageSet requiredDepsMap pkg_descr = do
10211028
let failedDeps :: [FailedDependency]
10221029
allPkgDeps :: [ResolvedDependency]
10231030
(failedDeps, allPkgDeps) = partitionEithers
10241031
[ (\s -> (dep, s)) <$> status
1025-
| dep <- enabledBuildDepends pkg_descr enableSpec
1032+
| dep <- buildDepends pkg_descr
10261033
, let status = selectDependency (package pkg_descr)
10271034
internalPackageSet installedPackageSet
10281035
requiredDepsMap use_external_internal_deps dep ]

Cabal/Distribution/Types/BuildInfo.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ instance Monoid BuildInfo where
150150
staticOptions = [],
151151
customFieldsBI = [],
152152
targetBuildDepends = [],
153-
mixins = []
153+
mixins = []
154154
}
155155
mappend = (<>)
156156

@@ -196,7 +196,7 @@ instance Semigroup BuildInfo where
196196
staticOptions = combine staticOptions,
197197
customFieldsBI = combine customFieldsBI,
198198
targetBuildDepends = combineNub targetBuildDepends,
199-
mixins = combine mixins
199+
mixins = combine mixins
200200
}
201201
where
202202
combine field = field a `mappend` field b

Cabal/Distribution/Types/PackageDescription.hs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ module Distribution.Types.PackageDescription (
4949
withForeignLib,
5050
allBuildInfo,
5151
enabledBuildInfos,
52-
allBuildDepends,
53-
enabledBuildDepends,
5452
updatePackageDescription,
5553
pkgComponents,
5654
pkgBuildableComponents,
@@ -62,8 +60,6 @@ module Distribution.Types.PackageDescription (
6260
import Prelude ()
6361
import Distribution.Compat.Prelude
6462

65-
import Control.Monad ((<=<))
66-
6763
import Distribution.Types.Library
6864
import Distribution.Types.TestSuite
6965
import Distribution.Types.Executable
@@ -128,6 +124,18 @@ data PackageDescription
128124
-- with x-, stored in a
129125
-- simple assoc-list.
130126

127+
-- | YOU PROBABLY DON'T WANT TO USE THIS FIELD. This field is
128+
-- special! Depending on how far along processing the
129+
-- PackageDescription we are, the contents of this field are
130+
-- either nonsense, or the collected dependencies of *all* the
131+
-- components in this package. buildDepends is initialized by
132+
-- 'finalizePD' and 'flattenPackageDescription';
133+
-- prior to that, dependency info is stored in the 'CondTree'
134+
-- built around a 'GenericPackageDescription'. When this
135+
-- resolution is done, dependency info is written to the inner
136+
-- 'BuildInfo' and this field. This is all horrible, and #2066
137+
-- tracks progress to get rid of this field.
138+
buildDepends :: [Dependency],
131139
-- | The original @build-type@ value as parsed from the
132140
-- @.cabal@ file without defaulting. See also 'buildType'.
133141
--
@@ -239,6 +247,7 @@ emptyPackageDescription
239247
author = "",
240248
stability = "",
241249
testedWith = [],
250+
buildDepends = [],
242251
homepage = "",
243252
pkgUrl = "",
244253
bugReports = "",
@@ -383,16 +392,6 @@ enabledBuildInfos pkg enabled =
383392
-- * Utils
384393
-- ------------------------------------------------------------
385394

386-
-- | Get the combined build-depends entries of all components.
387-
allBuildDepends :: PackageDescription -> [Dependency]
388-
allBuildDepends = targetBuildDepends <=< allBuildInfo
389-
390-
-- | Get the combined build-depends entries of all enabled components, per the
391-
-- given request spec.
392-
enabledBuildDepends :: PackageDescription -> ComponentRequestedSpec -> [Dependency]
393-
enabledBuildDepends spec pd = targetBuildDepends =<< enabledBuildInfos spec pd
394-
395-
396395
updatePackageDescription :: HookedBuildInfo -> PackageDescription -> PackageDescription
397396
updatePackageDescription (mb_lib_bi, exe_bi) p
398397
= p{ executables = updateExecutables exe_bi (executables p)

Cabal/Distribution/Types/PackageDescription/Lens.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Distribution.Compiler (CompilerFlavor)
1111
import Distribution.License (License)
1212
import Distribution.Types.Benchmark (Benchmark)
1313
import Distribution.Types.BuildType (BuildType)
14+
import Distribution.Types.Dependency (Dependency)
1415
import Distribution.Types.Executable (Executable)
1516
import Distribution.Types.ForeignLib (ForeignLib)
1617
import Distribution.Types.Library (Library)
@@ -88,6 +89,10 @@ customFieldsPD :: Lens' PackageDescription [(String,String)]
8889
customFieldsPD f s = fmap (\x -> s { T.customFieldsPD = x }) (f (T.customFieldsPD s))
8990
{-# INLINE customFieldsPD #-}
9091

92+
buildDepends :: Lens' PackageDescription [Dependency]
93+
buildDepends f s = fmap (\x -> s { T.buildDepends = x }) (f (T.buildDepends s))
94+
{-# INLINE buildDepends #-}
95+
9196
specVersionRaw :: Lens' PackageDescription (Either Version VersionRange)
9297
specVersionRaw f s = fmap (\x -> s { T.specVersionRaw = x }) (f (T.specVersionRaw s))
9398
{-# INLINE specVersionRaw #-}

Cabal/changelog

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@
5252
* Pretty-printing of .cabal files is slightly different due to
5353
parser changes. For an example, see
5454
https://mail.haskell.org/pipermail/cabal-devel/2017-December/010414.html.
55-
* `buildDepends` is removed from `PackageDescription`. It had long been
56-
uselessly hanging about as top-level build-depends already got put
57-
into per-component condition trees anyway. Now it's finally been put
58-
out of its misery.
5955
* `--hyperlink-source` now uses Haddock's hyperlinker backend when
6056
Haddock is new enough, falling back to HsColour otherwise.
6157
* `D.S.defaultHookedPackageDesc` has been deprecated in favour of

Cabal/tests/ParserTests/regressions/Octree-0.5.expr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ GenericPackageDescription
244244
{author = "Michal J. Gajda",
245245
benchmarks = [],
246246
bugReports = "mailto:[email protected]",
247+
buildDepends = [],
247248
buildTypeRaw = Just Simple,
248249
category = "Data",
249250
copyright = "Copyright by Michal J. Gajda '2012",

Cabal/tests/ParserTests/regressions/common.expr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ GenericPackageDescription
117117
{author = "",
118118
benchmarks = [],
119119
bugReports = "",
120+
buildDepends = [],
120121
buildTypeRaw = Just Simple,
121122
category = "",
122123
copyright = "",

Cabal/tests/ParserTests/regressions/common2.expr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ GenericPackageDescription
373373
{author = "",
374374
benchmarks = [],
375375
bugReports = "",
376+
buildDepends = [],
376377
buildTypeRaw = Just Simple,
377378
category = "",
378379
copyright = "",

Cabal/tests/ParserTests/regressions/elif.expr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ GenericPackageDescription
118118
{author = "",
119119
benchmarks = [],
120120
bugReports = "",
121+
buildDepends = [],
121122
buildTypeRaw = Just Simple,
122123
category = "",
123124
copyright = "",

Cabal/tests/ParserTests/regressions/elif2.expr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ GenericPackageDescription
277277
{author = "",
278278
benchmarks = [],
279279
bugReports = "",
280+
buildDepends = [],
280281
buildTypeRaw = Just Simple,
281282
category = "",
282283
copyright = "",

Cabal/tests/ParserTests/regressions/encoding-0.8.expr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ GenericPackageDescription
7979
{author = "",
8080
benchmarks = [],
8181
bugReports = "",
82+
buildDepends = [],
8283
buildTypeRaw = Nothing,
8384
category = "",
8485
copyright = "",

Cabal/tests/ParserTests/regressions/generics-sop.expr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ GenericPackageDescription
554554
{author = "Edsko de Vries <[email protected]>, Andres L\246h <[email protected]>",
555555
benchmarks = [],
556556
bugReports = "",
557+
buildDepends = [],
557558
buildTypeRaw = Just Custom,
558559
category = "Generics",
559560
copyright = "",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
'ghc-options: -O2' is rarely needed. Check that it is giving a real benefit and not just imposing longer compile times on your users.
2-
The package uses major bounded version syntax in the 'build-depends' field: base ^>=4.10.0, Cabal ^>=2.0.0, ghc ^>=8.2, ghc-paths ^>=0.1.0.9, xhtml ^>=3000.2.2, ghc ^>=8.2, hspec ^>=2.4.4, QuickCheck ^>=2.10. To use this new syntax the package need to specify at least 'cabal-version: >= 2.0'. Alternatively, if broader compatibility is important then use: base >=4.10.0 && <4.11, Cabal >=2.0.0 && <2.1, ghc >=8.2 && <8.3, ghc-paths >=0.1.0.9 && <0.2, xhtml >=3000.2.2 && <3000.3, ghc >=8.2 && <8.3, hspec >=2.4.4 && <2.5, QuickCheck >=2.10 && <2.11
2+
The package uses major bounded version syntax in the 'build-depends' field: base ^>=4.10.0, Cabal ^>=2.0.0, ghc ^>=8.2, ghc-paths ^>=0.1.0.9, xhtml ^>=3000.2.2, QuickCheck ^>=2.10, hspec ^>=2.4.4, ghc ^>=8.2. To use this new syntax the package need to specify at least 'cabal-version: >= 2.0'. Alternatively, if broader compatibility is important then use: base >=4.10.0 && <4.11, Cabal >=2.0.0 && <2.1, ghc >=8.2 && <8.3, ghc-paths >=0.1.0.9 && <0.2, xhtml >=3000.2.2 && <3000.3, QuickCheck >=2.10 && <2.11, hspec >=2.4.4 && <2.5, ghc >=8.2 && <8.3

Cabal/tests/ParserTests/regressions/issue-5055.expr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ GenericPackageDescription
183183
{author = "",
184184
benchmarks = [],
185185
bugReports = "",
186+
buildDepends = [],
186187
buildTypeRaw = Just Simple,
187188
category = "Test",
188189
copyright = "",

0 commit comments

Comments
 (0)