Skip to content

Commit

Permalink
Use default-package-bounds in solver and in finalizePD
Browse files Browse the repository at this point in the history
  • Loading branch information
jasagredo committed Jun 26, 2024
1 parent 7e5be40 commit de41943
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
37 changes: 29 additions & 8 deletions Cabal-syntax/src/Distribution/PackageDescription/Configuration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module Distribution.PackageDescription.Configuration
, transformAllBuildInfos
, transformAllBuildDepends
, transformAllBuildDependsN
, transformDefaultBuildDepends
, simplifyWithSysParams
) where

Expand All @@ -40,6 +41,7 @@ import Prelude ()

-- lens
import qualified Distribution.Types.BuildInfo.Lens as L
import qualified Distribution.Types.DefaultBounds.Lens as L
import qualified Distribution.Types.GenericPackageDescription.Lens as L
import qualified Distribution.Types.PackageDescription.Lens as L
import qualified Distribution.Types.SetupBuildInfo.Lens as L
Expand Down Expand Up @@ -476,7 +478,7 @@ finalizePD
(Platform arch os)
impl
constraints
(GenericPackageDescription pkg _ver flags mb_lib0 sub_libs0 flibs0 exes0 tests0 bms0) = do
(GenericPackageDescription pkg _ver flags defBounds mb_lib0 sub_libs0 flibs0 exes0 tests0 bms0) = do
(targetSet, flagVals) <-
resolveWithFlags flagChoices enabled os arch impl constraints condTrees check
let
Expand Down Expand Up @@ -509,14 +511,25 @@ finalizePD
, flagVals
)
where
appBounds :: L.HasBuildInfo a => a -> a
appBounds = maybe id applyDefaultBoundsToBuildInfo defBounds

appBoundsConstrs
:: [CondTree v [Dependency] a]
-> [CondTree v [Dependency] a]
appBoundsConstrs = case defBounds of
Nothing -> id
Just db -> map (mapTreeConstrs (applyDefaultBoundsToDependencies db))

-- Combine lib, exes, and tests into one list of @CondTree@s with tagged data
condTrees =
maybeToList (fmap (mapTreeData Lib) mb_lib0)
++ map (\(name, tree) -> mapTreeData (SubComp name . CLib) tree) sub_libs0
++ map (\(name, tree) -> mapTreeData (SubComp name . CFLib) tree) flibs0
++ map (\(name, tree) -> mapTreeData (SubComp name . CExe) tree) exes0
++ map (\(name, tree) -> mapTreeData (SubComp name . CTest) tree) tests0
++ map (\(name, tree) -> mapTreeData (SubComp name . CBench) tree) bms0
appBoundsConstrs $
maybeToList (fmap (mapTreeData (Lib . appBounds)) mb_lib0)
++ map (\(name, tree) -> mapTreeData (SubComp name . CLib . appBounds) tree) sub_libs0
++ map (\(name, tree) -> mapTreeData (SubComp name . CFLib . appBounds) tree) flibs0
++ map (\(name, tree) -> mapTreeData (SubComp name . CExe . appBounds) tree) exes0
++ map (\(name, tree) -> mapTreeData (SubComp name . CTest . appBounds) tree) tests0
++ map (\(name, tree) -> mapTreeData (SubComp name . CBench . appBounds) tree) bms0

flagChoices = map (\(MkPackageFlag n _ d manual) -> (n, d2c manual n d)) flags
d2c manual n b = case lookupFlagAssignment n userflags of
Expand Down Expand Up @@ -556,7 +569,7 @@ resolveWithFlags [] Distribution.System.Linux Distribution.System.I386 (Distribu
-- function.
flattenPackageDescription :: GenericPackageDescription -> PackageDescription
flattenPackageDescription
(GenericPackageDescription pkg _ _ mlib0 sub_libs0 flibs0 exes0 tests0 bms0) =
(GenericPackageDescription pkg _ _ _ mlib0 sub_libs0 flibs0 exes0 tests0 bms0) =
pkg
{ library = mlib
, subLibraries = reverse sub_libs
Expand Down Expand Up @@ -668,3 +681,11 @@ transformAllBuildDependsN f =
. over (L.packageDescription . L.setupBuildInfo . traverse . L.setupDepends) f
-- cannot be point-free as normal because of higher rank
. over (\f' -> L.allCondTrees $ traverseCondTreeC f') f

-- | Apply @f@ to the default bounds in the 'PackageDescription'.
transformDefaultBuildDepends
:: (Dependency -> Dependency)
-> GenericPackageDescription
-> GenericPackageDescription
transformDefaultBuildDepends f =
over (L.genDefaultPackageBounds . traverse . L.defaultTargetBuildDepends . traverse) f
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import qualified Distribution.InstalledPackageInfo as IPI
import Distribution.Compiler
import Distribution.Package -- from Cabal
import Distribution.Simple.BuildToolDepends -- from Cabal
import Distribution.Types.BuildInfo.Lens (HasBuildInfo)
import Distribution.Types.ExeDependency -- from Cabal
import Distribution.Types.PkgconfigDependency -- from Cabal
import Distribution.Types.ComponentName -- from Cabal
Expand Down Expand Up @@ -176,10 +177,13 @@ convGPD :: OS -> Arch -> CompilerInfo -> [LabeledPackageConstraint]
-> StrongFlags -> SolveExecutables -> PN -> GenericPackageDescription
-> PInfo
convGPD os arch cinfo constraints strfl solveExes pn
(GenericPackageDescription pkg scannedVersion flags mlib sub_libs flibs exes tests benchs) =
(GenericPackageDescription pkg scannedVersion flags defBounds mlib sub_libs flibs exes tests benchs) =
let
fds = flagInfo strfl flags

appBounds :: HasBuildInfo a => CondTree cv [Dependency] a
-> CondTree cv [Dependency] a
appBounds = maybe id applyDefaultBoundsToCondTree defBounds

conv :: Monoid a => Component -> (a -> BuildInfo) -> DependencyReason PN ->
CondTree ConfVar [Dependency] a -> FlaggedDeps PN
Expand All @@ -190,15 +194,15 @@ convGPD os arch cinfo constraints strfl solveExes pn
initDR = DependencyReason pn M.empty S.empty

flagged_deps
= concatMap (\ds -> conv ComponentLib libBuildInfo initDR ds) (maybeToList mlib)
++ concatMap (\(nm, ds) -> conv (ComponentSubLib nm) libBuildInfo initDR ds) sub_libs
++ concatMap (\(nm, ds) -> conv (ComponentFLib nm) foreignLibBuildInfo initDR ds) flibs
++ concatMap (\(nm, ds) -> conv (ComponentExe nm) buildInfo initDR ds) exes
= concatMap (\ds -> conv ComponentLib libBuildInfo initDR (appBounds ds)) (maybeToList mlib)
++ concatMap (\(nm, ds) -> conv (ComponentSubLib nm) libBuildInfo initDR (appBounds ds)) sub_libs
++ concatMap (\(nm, ds) -> conv (ComponentFLib nm) foreignLibBuildInfo initDR (appBounds ds)) flibs
++ concatMap (\(nm, ds) -> conv (ComponentExe nm) buildInfo initDR (appBounds ds)) exes
++ prefix (Stanza (SN pn TestStanzas))
(L.map (\(nm, ds) -> conv (ComponentTest nm) testBuildInfo (addStanza TestStanzas initDR) ds)
(L.map (\(nm, ds) -> conv (ComponentTest nm) testBuildInfo (addStanza TestStanzas initDR) (appBounds ds))
tests)
++ prefix (Stanza (SN pn BenchStanzas))
(L.map (\(nm, ds) -> conv (ComponentBench nm) benchmarkBuildInfo (addStanza BenchStanzas initDR) ds)
(L.map (\(nm, ds) -> conv (ComponentBench nm) benchmarkBuildInfo (addStanza BenchStanzas initDR) (appBounds ds))
benchs)
++ maybe [] (convSetupBuildInfo pn) (setupBuildInfo pkg)

Expand Down Expand Up @@ -340,7 +344,6 @@ convCondTree flags dr pkg os arch cinfo pn fds comp getInfo solveExes@(SolveExec
[ D.Simple singleDep comp
| dep <- ds
, singleDep <- convLibDeps dr dep ] -- unconditional package dependencies

++ L.map (\e -> D.Simple (LDep dr (Ext e)) comp) (allExtensions bi) -- unconditional extension dependencies
++ L.map (\l -> D.Simple (LDep dr (Lang l)) comp) (allLanguages bi) -- unconditional language dependencies
++ L.map (\(PkgconfigDependency pkn vr) -> D.Simple (LDep dr (Pkg pkn vr)) comp) (pkgconfigDepends bi) -- unconditional pkg-config dependencies
Expand Down

0 comments on commit de41943

Please sign in to comment.