diff --git a/Cabal/Distribution/PackageDescription.hs b/Cabal/Distribution/PackageDescription.hs index 4085278e6c7..bd3f8141f97 100644 --- a/Cabal/Distribution/PackageDescription.hs +++ b/Cabal/Distribution/PackageDescription.hs @@ -83,6 +83,8 @@ module Distribution.PackageDescription ( hcStaticOptions, -- ** Supplementary build information + allBuildDepends, + enabledBuildDepends, ComponentName(..), defaultLibName, HookedBuildInfo, diff --git a/Cabal/Distribution/PackageDescription/Check.hs b/Cabal/Distribution/PackageDescription/Check.hs index 1a5964d50e9..7d62188072b 100644 --- a/Cabal/Distribution/PackageDescription/Check.hs +++ b/Cabal/Distribution/PackageDescription/Check.hs @@ -1363,7 +1363,7 @@ checkCabalVersion pkg = _ -> False versionRangeExpressions = - [ dep | dep@(Dependency _ vr) <- buildDepends pkg + [ dep | dep@(Dependency _ vr) <- allBuildDepends pkg , usesNewVersionRangeSyntax vr ] testedWithVersionRangeExpressions = @@ -1391,10 +1391,10 @@ checkCabalVersion pkg = alg (VersionRangeParensF _) = 3 alg _ = 1 :: Int - depsUsingWildcardSyntax = [ dep | dep@(Dependency _ vr) <- buildDepends pkg + depsUsingWildcardSyntax = [ dep | dep@(Dependency _ vr) <- allBuildDepends pkg , usesWildcardSyntax vr ] - depsUsingMajorBoundSyntax = [ dep | dep@(Dependency _ vr) <- buildDepends pkg + depsUsingMajorBoundSyntax = [ dep | dep@(Dependency _ vr) <- allBuildDepends pkg , usesMajorBoundSyntax vr ] usesBackpackIncludes = any (not . null . mixins) (allBuildInfo pkg) @@ -1541,7 +1541,7 @@ checkPackageVersions pkg = foldr intersectVersionRanges anyVersion baseDeps where baseDeps = - [ vr | Dependency pname vr <- buildDepends pkg' + [ vr | Dependency pname vr <- allBuildDepends pkg' , pname == mkPackageName "base" ] -- Just in case finalizePD fails for any reason, diff --git a/Cabal/Distribution/PackageDescription/Configuration.hs b/Cabal/Distribution/PackageDescription/Configuration.hs index 64771037612..e97d9dad04f 100644 --- a/Cabal/Distribution/PackageDescription/Configuration.hs +++ b/Cabal/Distribution/PackageDescription/Configuration.hs @@ -44,8 +44,10 @@ import Distribution.Compiler import Distribution.System import Distribution.Simple.Utils import Distribution.Text +import Distribution.Compat.Lens import Distribution.Compat.ReadP as ReadP hiding ( char ) import qualified Distribution.Compat.ReadP as ReadP ( char ) +import qualified Distribution.Types.BuildInfo.Lens as L import Distribution.Types.ComponentRequestedSpec import Distribution.Types.ForeignLib import Distribution.Types.Component @@ -351,18 +353,18 @@ overallDependencies enabled (TargetSet targets) = mconcat depss -- | Collect up the targets in a TargetSet of tagged targets, storing the -- dependencies as we go. flattenTaggedTargets :: TargetSet PDTagged -> (Maybe Library, [(UnqualComponentName, Component)]) -flattenTaggedTargets (TargetSet targets) = foldr untag (Nothing, []) targets - where - untag (_, Lib _) (Just _, _) = userBug "Only one library expected" - untag (_, Lib l) (Nothing, comps) = (Just l, comps) - untag (_, SubComp n c) (mb_lib, comps) - | any ((== n) . fst) comps = - userBug $ "There exist several components with the same name: '" ++ unUnqualComponentName n ++ "'" - - | otherwise = (mb_lib, (n, c) : comps) - - untag (_, PDNull) x = x -- actually this should not happen, but let's be liberal - +flattenTaggedTargets (TargetSet targets) = foldr untag (Nothing, []) targets where + untag (depMap, pdTagged) accum = case (pdTagged, accum) of + (Lib _, (Just _, _)) -> userBug "Only one library expected" + (Lib l, (Nothing, comps)) -> (Just $ redoBD l, comps) + (SubComp n c, (mb_lib, comps)) + | any ((== n) . fst) comps -> + userBug $ "There exist several components with the same name: '" ++ display n ++ "'" + | otherwise -> (mb_lib, (n, redoBD c) : comps) + (PDNull, x) -> x -- actually this should not happen, but let's be liberal + where + redoBD :: L.HasBuildInfo a => a -> a + redoBD = set L.targetBuildDepends $ fromDepMap depMap ------------------------------------------------------------------------------ -- Convert GenericPackageDescription to PackageDescription @@ -447,7 +449,6 @@ finalizePD userflags enabled satisfyDep , executables = exes' , testSuites = tests' , benchmarks = bms' - , buildDepends = fromDepMap (overallDependencies enabled targetSet) } , flagVals ) where @@ -517,38 +518,25 @@ flattenPackageDescription , executables = reverse exes , testSuites = reverse tests , benchmarks = reverse bms - , buildDepends = ldeps - ++ reverse sub_ldeps - ++ reverse pldeps - ++ reverse edeps - ++ reverse tdeps - ++ reverse bdeps } where - (mlib, ldeps) = case mlib0 of - Just lib -> let (l,ds) = ignoreConditions lib in - (Just ((libFillInDefaults l) { libName = Nothing }), ds) - Nothing -> (Nothing, []) - (sub_libs, sub_ldeps) = foldr flattenLib ([],[]) sub_libs0 - (flibs, pldeps) = foldr flattenFLib ([],[]) flibs0 - (exes, edeps) = foldr flattenExe ([],[]) exes0 - (tests, tdeps) = foldr flattenTst ([],[]) tests0 - (bms, bdeps) = foldr flattenBm ([],[]) bms0 - flattenLib (n, t) (es, ds) = - let (e, ds') = ignoreConditions t in - ( (libFillInDefaults $ e { libName = Just n, libExposed = False }) : es, ds' ++ ds ) - flattenFLib (n, t) (es, ds) = - let (e, ds') = ignoreConditions t in - ( (flibFillInDefaults $ e { foreignLibName = n }) : es, ds' ++ ds ) - flattenExe (n, t) (es, ds) = - let (e, ds') = ignoreConditions t in - ( (exeFillInDefaults $ e { exeName = n }) : es, ds' ++ ds ) - flattenTst (n, t) (es, ds) = - let (e, ds') = ignoreConditions t in - ( (testFillInDefaults $ e { testName = n }) : es, ds' ++ ds ) - flattenBm (n, t) (es, ds) = - let (e, ds') = ignoreConditions t in - ( (benchFillInDefaults $ e { benchmarkName = n }) : es, ds' ++ ds ) + mlib = f <$> mlib0 + where f lib = (libFillInDefaults . fst . ignoreConditions $ lib) { libName = Nothing } + sub_libs = flattenLib <$> sub_libs0 + flibs = flattenFLib <$> flibs0 + exes = flattenExe <$> exes0 + tests = flattenTst <$> tests0 + bms = flattenBm <$> bms0 + flattenLib (n, t) = libFillInDefaults $ (fst $ ignoreConditions t) + { libName = Just n, libExposed = False } + flattenFLib (n, t) = flibFillInDefaults $ (fst $ ignoreConditions t) + { foreignLibName = n } + flattenExe (n, t) = exeFillInDefaults $ (fst $ ignoreConditions t) + { exeName = n } + flattenTst (n, t) = testFillInDefaults $ (fst $ ignoreConditions t) + { testName = n } + flattenBm (n, t) = benchFillInDefaults $ (fst $ ignoreConditions t) + { benchmarkName = n } -- This is in fact rather a hack. The original version just overrode the -- default values, however, when adding conditions we had to switch to a @@ -620,12 +608,10 @@ transformAllBuildDepends f gpd = gpd' where onBI bi = bi { targetBuildDepends = map f $ targetBuildDepends bi } onSBI stp = stp { setupDepends = map f $ setupDepends stp } - onPD pd = pd { buildDepends = map f $ buildDepends pd } - pd' = onPD $ packageDescription gpd gpd' = transformAllCondTrees id id id id (map f) . transformAllBuildInfos onBI onSBI - $ gpd { packageDescription = pd' } + $ gpd -- | Walk all 'CondTree's inside a 'GenericPackageDescription' and apply -- appropriate transformations to all nodes. Helper function used by diff --git a/Cabal/Distribution/PackageDescription/FieldGrammar.hs b/Cabal/Distribution/PackageDescription/FieldGrammar.hs index 0032d59f1b5..a6251a114ec 100644 --- a/Cabal/Distribution/PackageDescription/FieldGrammar.hs +++ b/Cabal/Distribution/PackageDescription/FieldGrammar.hs @@ -87,7 +87,6 @@ packageDescriptionFieldGrammar = PackageDescription <*> optionalFieldDefAla "description" FreeText L.description "" <*> optionalFieldDefAla "category" FreeText L.category "" <*> prefixedFields "x-" L.customFieldsPD - <*> pure [] -- build-depends <*> optionalField "build-type" L.buildTypeRaw <*> pure Nothing -- custom-setup -- components diff --git a/Cabal/Distribution/Simple/Build.hs b/Cabal/Distribution/Simple/Build.hs index 2521243551e..cbe766d315a 100644 --- a/Cabal/Distribution/Simple/Build.hs +++ b/Cabal/Distribution/Simple/Build.hs @@ -481,7 +481,6 @@ testSuiteLibV09AsLibAndExe pkg_descr } pkg = pkg_descr { package = (package pkg_descr) { pkgName = mkPackageName $ unMungedPackageName compat_name } - , buildDepends = targetBuildDepends $ testBuildInfo test , executables = [] , testSuites = [] , subLibraries = [lib] diff --git a/Cabal/Distribution/Simple/Configure.hs b/Cabal/Distribution/Simple/Configure.hs index 6b5bbb24170..8bb879949da 100644 --- a/Cabal/Distribution/Simple/Configure.hs +++ b/Cabal/Distribution/Simple/Configure.hs @@ -470,15 +470,6 @@ configure (pkg_descr0, pbi) cfg = do debug verbosity $ "Finalized package description:\n" ++ showPackageDescription pkg_descr - -- NB: showPackageDescription does not display the AWFUL HACK GLOBAL - -- buildDepends, so we have to display it separately. See #2066 - -- Some day, we should eliminate this, so that - -- configureFinalizedPackage returns the set of overall dependencies - -- separately. Then 'configureDependencies' and - -- 'Distribution.PackageDescription.Check' need to be adjusted - -- accordingly. - debug verbosity $ "Finalized build-depends: " - ++ intercalate ", " (map display (buildDepends pkg_descr)) checkCompilerProblems verbosity comp pkg_descr enabled checkPackageProblems verbosity pkg_descr0 @@ -513,6 +504,7 @@ configure (pkg_descr0, pbi) cfg = do installedPackageSet requiredDepsMap pkg_descr + enabled -- Compute installation directory templates, based on user -- configuration. @@ -1017,14 +1009,15 @@ configureDependencies -> InstalledPackageIndex -- ^ installed packages -> Map PackageName InstalledPackageInfo -- ^ required deps -> PackageDescription + -> ComponentRequestedSpec -> IO [PreExistingComponent] configureDependencies verbosity use_external_internal_deps - internalPackageSet installedPackageSet requiredDepsMap pkg_descr = do + internalPackageSet installedPackageSet requiredDepsMap pkg_descr enableSpec = do let failedDeps :: [FailedDependency] allPkgDeps :: [ResolvedDependency] (failedDeps, allPkgDeps) = partitionEithers [ (\s -> (dep, s)) <$> status - | dep <- buildDepends pkg_descr + | dep <- enabledBuildDepends pkg_descr enableSpec , let status = selectDependency (package pkg_descr) internalPackageSet installedPackageSet requiredDepsMap use_external_internal_deps dep ] diff --git a/Cabal/Distribution/Types/BuildInfo.hs b/Cabal/Distribution/Types/BuildInfo.hs index 92d2021f7cc..7685270d77f 100644 --- a/Cabal/Distribution/Types/BuildInfo.hs +++ b/Cabal/Distribution/Types/BuildInfo.hs @@ -150,7 +150,7 @@ instance Monoid BuildInfo where staticOptions = [], customFieldsBI = [], targetBuildDepends = [], - mixins = [] + mixins = [] } mappend = (<>) @@ -196,7 +196,7 @@ instance Semigroup BuildInfo where staticOptions = combine staticOptions, customFieldsBI = combine customFieldsBI, targetBuildDepends = combineNub targetBuildDepends, - mixins = combine mixins + mixins = combine mixins } where combine field = field a `mappend` field b diff --git a/Cabal/Distribution/Types/PackageDescription.hs b/Cabal/Distribution/Types/PackageDescription.hs index b9dd51735c6..482093bfdba 100644 --- a/Cabal/Distribution/Types/PackageDescription.hs +++ b/Cabal/Distribution/Types/PackageDescription.hs @@ -49,6 +49,8 @@ module Distribution.Types.PackageDescription ( withForeignLib, allBuildInfo, enabledBuildInfos, + allBuildDepends, + enabledBuildDepends, updatePackageDescription, pkgComponents, pkgBuildableComponents, @@ -60,6 +62,8 @@ module Distribution.Types.PackageDescription ( import Prelude () import Distribution.Compat.Prelude +import Control.Monad ((<=<)) + import Distribution.Types.Library import Distribution.Types.TestSuite import Distribution.Types.Executable @@ -124,18 +128,6 @@ data PackageDescription -- with x-, stored in a -- simple assoc-list. - -- | YOU PROBABLY DON'T WANT TO USE THIS FIELD. This field is - -- special! Depending on how far along processing the - -- PackageDescription we are, the contents of this field are - -- either nonsense, or the collected dependencies of *all* the - -- components in this package. buildDepends is initialized by - -- 'finalizePD' and 'flattenPackageDescription'; - -- prior to that, dependency info is stored in the 'CondTree' - -- built around a 'GenericPackageDescription'. When this - -- resolution is done, dependency info is written to the inner - -- 'BuildInfo' and this field. This is all horrible, and #2066 - -- tracks progress to get rid of this field. - buildDepends :: [Dependency], -- | The original @build-type@ value as parsed from the -- @.cabal@ file without defaulting. See also 'buildType'. -- @@ -247,7 +239,6 @@ emptyPackageDescription author = "", stability = "", testedWith = [], - buildDepends = [], homepage = "", pkgUrl = "", bugReports = "", @@ -392,6 +383,16 @@ enabledBuildInfos pkg enabled = -- * Utils -- ------------------------------------------------------------ +-- | Get the combined build-depends entries of all components. +allBuildDepends :: PackageDescription -> [Dependency] +allBuildDepends = targetBuildDepends <=< allBuildInfo + +-- | Get the combined build-depends entries of all enabled components, per the +-- given request spec. +enabledBuildDepends :: PackageDescription -> ComponentRequestedSpec -> [Dependency] +enabledBuildDepends spec pd = targetBuildDepends =<< enabledBuildInfos spec pd + + updatePackageDescription :: HookedBuildInfo -> PackageDescription -> PackageDescription updatePackageDescription (mb_lib_bi, exe_bi) p = p{ executables = updateExecutables exe_bi (executables p) diff --git a/Cabal/Distribution/Types/PackageDescription/Lens.hs b/Cabal/Distribution/Types/PackageDescription/Lens.hs index 6594b995337..e08dbc45848 100644 --- a/Cabal/Distribution/Types/PackageDescription/Lens.hs +++ b/Cabal/Distribution/Types/PackageDescription/Lens.hs @@ -11,7 +11,6 @@ import Distribution.Compiler (CompilerFlavor) import Distribution.License (License) import Distribution.Types.Benchmark (Benchmark) import Distribution.Types.BuildType (BuildType) -import Distribution.Types.Dependency (Dependency) import Distribution.Types.Executable (Executable) import Distribution.Types.ForeignLib (ForeignLib) import Distribution.Types.Library (Library) @@ -89,10 +88,6 @@ customFieldsPD :: Lens' PackageDescription [(String,String)] customFieldsPD f s = fmap (\x -> s { T.customFieldsPD = x }) (f (T.customFieldsPD s)) {-# INLINE customFieldsPD #-} -buildDepends :: Lens' PackageDescription [Dependency] -buildDepends f s = fmap (\x -> s { T.buildDepends = x }) (f (T.buildDepends s)) -{-# INLINE buildDepends #-} - specVersionRaw :: Lens' PackageDescription (Either Version VersionRange) specVersionRaw f s = fmap (\x -> s { T.specVersionRaw = x }) (f (T.specVersionRaw s)) {-# INLINE specVersionRaw #-} diff --git a/Cabal/tests/ParserTests/regressions/Octree-0.5.expr b/Cabal/tests/ParserTests/regressions/Octree-0.5.expr index 1591c75da33..7c3b45ceb6d 100644 --- a/Cabal/tests/ParserTests/regressions/Octree-0.5.expr +++ b/Cabal/tests/ParserTests/regressions/Octree-0.5.expr @@ -244,7 +244,6 @@ GenericPackageDescription {author = "Michal J. Gajda", benchmarks = [], bugReports = "mailto:mjgajda@googlemail.com", - buildDepends = [], buildTypeRaw = Just Simple, category = "Data", copyright = "Copyright by Michal J. Gajda '2012", diff --git a/Cabal/tests/ParserTests/regressions/common.expr b/Cabal/tests/ParserTests/regressions/common.expr index 9341df23fd1..01b7ad3662d 100644 --- a/Cabal/tests/ParserTests/regressions/common.expr +++ b/Cabal/tests/ParserTests/regressions/common.expr @@ -117,7 +117,6 @@ GenericPackageDescription {author = "", benchmarks = [], bugReports = "", - buildDepends = [], buildTypeRaw = Just Simple, category = "", copyright = "", diff --git a/Cabal/tests/ParserTests/regressions/common2.expr b/Cabal/tests/ParserTests/regressions/common2.expr index bb88b428704..d8fe2546acd 100644 --- a/Cabal/tests/ParserTests/regressions/common2.expr +++ b/Cabal/tests/ParserTests/regressions/common2.expr @@ -373,7 +373,6 @@ GenericPackageDescription {author = "", benchmarks = [], bugReports = "", - buildDepends = [], buildTypeRaw = Just Simple, category = "", copyright = "", diff --git a/Cabal/tests/ParserTests/regressions/elif.expr b/Cabal/tests/ParserTests/regressions/elif.expr index 09e8d6f7049..ae39c7d3e0d 100644 --- a/Cabal/tests/ParserTests/regressions/elif.expr +++ b/Cabal/tests/ParserTests/regressions/elif.expr @@ -118,7 +118,6 @@ GenericPackageDescription {author = "", benchmarks = [], bugReports = "", - buildDepends = [], buildTypeRaw = Just Simple, category = "", copyright = "", diff --git a/Cabal/tests/ParserTests/regressions/elif2.expr b/Cabal/tests/ParserTests/regressions/elif2.expr index a76f5cf3d6b..19511897387 100644 --- a/Cabal/tests/ParserTests/regressions/elif2.expr +++ b/Cabal/tests/ParserTests/regressions/elif2.expr @@ -277,7 +277,6 @@ GenericPackageDescription {author = "", benchmarks = [], bugReports = "", - buildDepends = [], buildTypeRaw = Just Simple, category = "", copyright = "", diff --git a/Cabal/tests/ParserTests/regressions/encoding-0.8.expr b/Cabal/tests/ParserTests/regressions/encoding-0.8.expr index 76fe659803a..889650974a3 100644 --- a/Cabal/tests/ParserTests/regressions/encoding-0.8.expr +++ b/Cabal/tests/ParserTests/regressions/encoding-0.8.expr @@ -79,7 +79,6 @@ GenericPackageDescription {author = "", benchmarks = [], bugReports = "", - buildDepends = [], buildTypeRaw = Nothing, category = "", copyright = "", diff --git a/Cabal/tests/ParserTests/regressions/generics-sop.expr b/Cabal/tests/ParserTests/regressions/generics-sop.expr index a26d2bfbe5c..f99eaedd497 100644 --- a/Cabal/tests/ParserTests/regressions/generics-sop.expr +++ b/Cabal/tests/ParserTests/regressions/generics-sop.expr @@ -554,7 +554,6 @@ GenericPackageDescription {author = "Edsko de Vries , Andres L\246h ", benchmarks = [], bugReports = "", - buildDepends = [], buildTypeRaw = Just Custom, category = "Generics", copyright = "", diff --git a/Cabal/tests/ParserTests/regressions/haddock-api-2.18.1-check.check b/Cabal/tests/ParserTests/regressions/haddock-api-2.18.1-check.check index b9d2e11cbcb..c95a5ebc74a 100644 --- a/Cabal/tests/ParserTests/regressions/haddock-api-2.18.1-check.check +++ b/Cabal/tests/ParserTests/regressions/haddock-api-2.18.1-check.check @@ -1,2 +1,2 @@ 'ghc-options: -O2' is rarely needed. Check that it is giving a real benefit and not just imposing longer compile times on your users. -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 +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 diff --git a/Cabal/tests/ParserTests/regressions/issue-5055.expr b/Cabal/tests/ParserTests/regressions/issue-5055.expr index a1e234adc4e..c7ce614e390 100644 --- a/Cabal/tests/ParserTests/regressions/issue-5055.expr +++ b/Cabal/tests/ParserTests/regressions/issue-5055.expr @@ -183,7 +183,6 @@ GenericPackageDescription {author = "", benchmarks = [], bugReports = "", - buildDepends = [], buildTypeRaw = Just Simple, category = "Test", copyright = "", diff --git a/Cabal/tests/ParserTests/regressions/issue-774.expr b/Cabal/tests/ParserTests/regressions/issue-774.expr index 29380faadb4..5cda458c27c 100644 --- a/Cabal/tests/ParserTests/regressions/issue-774.expr +++ b/Cabal/tests/ParserTests/regressions/issue-774.expr @@ -66,7 +66,6 @@ GenericPackageDescription {author = "", benchmarks = [], bugReports = "", - buildDepends = [], buildTypeRaw = Just Simple, category = "", copyright = "", diff --git a/Cabal/tests/ParserTests/regressions/leading-comma.expr b/Cabal/tests/ParserTests/regressions/leading-comma.expr index 71644e8cd67..4b9b892a420 100644 --- a/Cabal/tests/ParserTests/regressions/leading-comma.expr +++ b/Cabal/tests/ParserTests/regressions/leading-comma.expr @@ -83,7 +83,6 @@ GenericPackageDescription {author = "", benchmarks = [], bugReports = "", - buildDepends = [], buildTypeRaw = Just Simple, category = "", copyright = "", diff --git a/Cabal/tests/ParserTests/regressions/nothing-unicode.expr b/Cabal/tests/ParserTests/regressions/nothing-unicode.expr index 6a544a5dcf8..3fd9b4820df 100644 --- a/Cabal/tests/ParserTests/regressions/nothing-unicode.expr +++ b/Cabal/tests/ParserTests/regressions/nothing-unicode.expr @@ -118,7 +118,6 @@ GenericPackageDescription {author = "", benchmarks = [], bugReports = "", - buildDepends = [], buildTypeRaw = Just Simple, category = "", copyright = "", diff --git a/Cabal/tests/ParserTests/regressions/shake.expr b/Cabal/tests/ParserTests/regressions/shake.expr index b0927b70025..a3efa683b6e 100644 --- a/Cabal/tests/ParserTests/regressions/shake.expr +++ b/Cabal/tests/ParserTests/regressions/shake.expr @@ -1630,7 +1630,6 @@ GenericPackageDescription {author = "Neil Mitchell ", benchmarks = [], bugReports = "https://github.com/ndmitchell/shake/issues", - buildDepends = [], buildTypeRaw = Just Simple, category = "Development, Shake", copyright = "Neil Mitchell 2011-2017", diff --git a/Cabal/tests/ParserTests/regressions/th-lift-instances.expr b/Cabal/tests/ParserTests/regressions/th-lift-instances.expr index 273ad24bea8..0621e9c3ef0 100644 --- a/Cabal/tests/ParserTests/regressions/th-lift-instances.expr +++ b/Cabal/tests/ParserTests/regressions/th-lift-instances.expr @@ -386,7 +386,6 @@ GenericPackageDescription {author = "Benno F\252nfst\252ck", benchmarks = [], bugReports = "http://github.com/bennofs/th-lift-instances/issues", - buildDepends = [], buildTypeRaw = Just Custom, category = "Template Haskell", copyright = "Copyright (C) 2013-2014 Benno F\252nfst\252ck", diff --git a/Cabal/tests/ParserTests/regressions/wl-pprint-indef.expr b/Cabal/tests/ParserTests/regressions/wl-pprint-indef.expr index 37199283959..021191dcc38 100644 --- a/Cabal/tests/ParserTests/regressions/wl-pprint-indef.expr +++ b/Cabal/tests/ParserTests/regressions/wl-pprint-indef.expr @@ -140,7 +140,6 @@ GenericPackageDescription {author = "Daan Leijen", benchmarks = [], bugReports = "", - buildDepends = [], buildTypeRaw = Just Simple, category = "Text", copyright = "", diff --git a/cabal-install/Distribution/Client/Dependency.hs b/cabal-install/Distribution/Client/Dependency.hs index 8506849a446..69f48ba88ef 100644 --- a/cabal-install/Distribution/Client/Dependency.hs +++ b/cabal-install/Distribution/Client/Dependency.hs @@ -930,24 +930,24 @@ configuredPackageProblems platform cinfo (sortNubOn dependencyName required) (sortNubOn packageName specified) + compSpec = enableStanzas stanzas -- TODO: It would be nicer to use ComponentDeps here so we can be more - -- precise in our checks. That's a bit tricky though, as this currently - -- relies on the 'buildDepends' field of 'PackageDescription'. (OTOH, that - -- field is deprecated and should be removed anyway.) As long as we _do_ - -- use a flat list here, we have to allow for duplicates when we fold - -- specifiedDeps; once we have proper ComponentDeps here we should get rid - -- of the `nubOn` in `mergeDeps`. + -- precise in our checks. In fact, this no longer relies on buildDepends and + -- thus should be easier to fix. As long as we _do_ use a flat list here, we + -- have to allow for duplicates when we fold specifiedDeps; once we have + -- proper ComponentDeps here we should get rid of the `nubOn` in + -- `mergeDeps`. requiredDeps :: [Dependency] requiredDeps = --TODO: use something lower level than finalizePD case finalizePD specifiedFlags - (enableStanzas stanzas) + compSpec (const True) platform cinfo [] (packageDescription pkg) of Right (resolvedPkg, _) -> - externalBuildDepends resolvedPkg + externalBuildDepends resolvedPkg compSpec ++ maybe [] PD.setupDepends (PD.setupBuildInfo resolvedPkg) Left _ -> error "configuredPackageInvalidDeps internal error" diff --git a/cabal-install/Distribution/Client/GenBounds.hs b/cabal-install/Distribution/Client/GenBounds.hs index 139e05b9dae..0f2727ad2fc 100644 --- a/cabal-install/Distribution/Client/GenBounds.hs +++ b/cabal-install/Distribution/Client/GenBounds.hs @@ -29,7 +29,7 @@ import Distribution.Client.Setup import Distribution.Package ( Package(..), unPackageName, packageName, packageVersion ) import Distribution.PackageDescription - ( buildDepends ) + ( enabledBuildDepends ) import Distribution.PackageDescription.Configuration ( finalizePD ) import Distribution.PackageDescription.Parsec @@ -122,7 +122,7 @@ genBounds verbosity packageDBs repoCtxt comp platform progdb mSandboxPkgInfo Left _ -> putStrLn "finalizePD failed" Right (pd,_) -> do let needBounds = filter (not . hasUpperBound . depVersion) $ - buildDepends pd + enabledBuildDepends pd defaultComponentRequestedSpec if (null needBounds) then putStrLn diff --git a/cabal-install/Distribution/Client/List.hs b/cabal-install/Distribution/Client/List.hs index 65d43b6522c..5a72ce7a709 100644 --- a/cabal-install/Distribution/Client/List.hs +++ b/cabal-install/Distribution/Client/List.hs @@ -470,7 +470,7 @@ mergePackageInfo versionPref installedPkgs sourcePkgs selectedPkg showVer = source, dependencies = combine (map (SourceDependency . simplifyDependency) - . Source.buildDepends) source + . Source.allBuildDepends) source (map InstalledDependency . Installed.depends) installed, haddockHtml = fromMaybe "" . join . fmap (listToMaybe . Installed.haddockHTMLs) diff --git a/cabal-install/Distribution/Client/Outdated.hs b/cabal-install/Distribution/Client/Outdated.hs index 9f0bcc0f2ff..8ec0d63bea9 100644 --- a/cabal-install/Distribution/Client/Outdated.hs +++ b/cabal-install/Distribution/Client/Outdated.hs @@ -27,9 +27,8 @@ import Distribution.Solver.Types.PackageConstraint import Distribution.Solver.Types.PackageIndex import Distribution.Client.Sandbox.PackageEnvironment -import Distribution.Package (PackageName - ,packageVersion) -import Distribution.PackageDescription (buildDepends) +import Distribution.Package (PackageName, packageVersion) +import Distribution.PackageDescription (allBuildDepends) import Distribution.PackageDescription.Configuration (finalizePD) import Distribution.Simple.Compiler (Compiler, compilerInfo) import Distribution.Simple.Setup (fromFlagOrDefault) @@ -152,7 +151,7 @@ depsFromPkgDesc verbosity comp platform = do case epd of Left _ -> die' verbosity "finalizePD failed" Right (pd, _) -> do - let bd = buildDepends pd + let bd = allBuildDepends pd debug verbosity "Reading the list of dependencies from the package description" return bd diff --git a/cabal-install/Distribution/Client/PackageUtils.hs b/cabal-install/Distribution/Client/PackageUtils.hs index 4f460997386..b1236fb38b1 100644 --- a/cabal-install/Distribution/Client/PackageUtils.hs +++ b/cabal-install/Distribution/Client/PackageUtils.hs @@ -16,18 +16,20 @@ module Distribution.Client.PackageUtils ( import Distribution.Package ( packageVersion, packageName ) +import Distribution.Types.ComponentRequestedSpec + ( ComponentRequestedSpec ) import Distribution.Types.Dependency import Distribution.Types.UnqualComponentName import Distribution.PackageDescription - ( PackageDescription(..), libName ) + ( PackageDescription(..), libName, enabledBuildDepends ) import Distribution.Version ( withinRange, isAnyVersion ) -- | The list of dependencies that refer to external packages -- rather than internal package components. -- -externalBuildDepends :: PackageDescription -> [Dependency] -externalBuildDepends pkg = filter (not . internal) (buildDepends pkg) +externalBuildDepends :: PackageDescription -> ComponentRequestedSpec -> [Dependency] +externalBuildDepends pkg spec = filter (not . internal) (enabledBuildDepends pkg spec) where -- True if this dependency is an internal one (depends on a library -- defined in the same package). diff --git a/cabal-testsuite/PackageTests/Backpack/Includes2/cabal-internal.out b/cabal-testsuite/PackageTests/Backpack/Includes2/cabal-internal.out index 412950ed677..36f513582b2 100644 --- a/cabal-testsuite/PackageTests/Backpack/Includes2/cabal-internal.out +++ b/cabal-testsuite/PackageTests/Backpack/Includes2/cabal-internal.out @@ -34,9 +34,11 @@ Building library 'mylib' instantiated with Database = Includes2-0.1.0.0-inplace-postgresql:Database.PostgreSQL for Includes2-0.1.0.0.. Configuring library for Includes2-0.1.0.0.. +Warning: The package has an extraneous version range for a dependency on an internal library: Includes2 -any && ==0.1.0.0 && ==0.1.0.0 && ==0.1.0.0. This version range includes the current package but isn't needed as the current package's library will always be used. Preprocessing library for Includes2-0.1.0.0.. Building library for Includes2-0.1.0.0.. Configuring executable 'exe' for Includes2-0.1.0.0.. +Warning: The package has an extraneous version range for a dependency on an internal library: Includes2 -any && ==0.1.0.0. This version range includes the current package but isn't needed as the current package's library will always be used. Preprocessing executable 'exe' for Includes2-0.1.0.0.. Building executable 'exe' for Includes2-0.1.0.0.. # Includes2 exe diff --git a/cabal-testsuite/PackageTests/BuildTools/Internal/cabal.out b/cabal-testsuite/PackageTests/BuildTools/Internal/cabal.out index 4486c7aab9b..90464eb31d8 100644 --- a/cabal-testsuite/PackageTests/BuildTools/Internal/cabal.out +++ b/cabal-testsuite/PackageTests/BuildTools/Internal/cabal.out @@ -12,5 +12,6 @@ Configuring library for foo-0.1.0.0.. Preprocessing library for foo-0.1.0.0.. Building library for foo-0.1.0.0.. Configuring executable 'hello-world' for foo-0.1.0.0.. +Warning: The package has an extraneous version range for a dependency on an internal library: foo -any && ==0.1.0.0. This version range includes the current package but isn't needed as the current package's library will always be used. Preprocessing executable 'hello-world' for foo-0.1.0.0.. Building executable 'hello-world' for foo-0.1.0.0.. diff --git a/cabal-testsuite/PackageTests/TestSuiteTests/ExeV10/cabal.out b/cabal-testsuite/PackageTests/TestSuiteTests/ExeV10/cabal.out index a8318f25d53..b1ccd8f66fc 100644 --- a/cabal-testsuite/PackageTests/TestSuiteTests/ExeV10/cabal.out +++ b/cabal-testsuite/PackageTests/TestSuiteTests/ExeV10/cabal.out @@ -9,6 +9,7 @@ Configuring library for my-0.1.. Preprocessing library for my-0.1.. Building library for my-0.1.. Configuring test suite 'test-Short' for my-0.1.. +Warning: The package has an extraneous version range for a dependency on an internal library: my -any && ==0.1, my -any && ==0.1. This version range includes the current package but isn't needed as the current package's library will always be used. Preprocessing test suite 'test-Short' for my-0.1.. Building test suite 'test-Short' for my-0.1.. Running 1 test suites... @@ -17,6 +18,7 @@ Test suite test-Short: PASS Test suite logged to: /cabal.dist/work/./dist/build//ghc-/my-0.1/t/test-Short/test/my-0.1-test-Short.log 1 of 1 test suites (1 of 1 test cases) passed. Configuring test suite 'test-Foo' for my-0.1.. +Warning: The package has an extraneous version range for a dependency on an internal library: my -any && ==0.1, my -any && ==0.1. This version range includes the current package but isn't needed as the current package's library will always be used. Preprocessing test suite 'test-Foo' for my-0.1.. Building test suite 'test-Foo' for my-0.1.. Running 1 test suites...