Commit 70098ef0 authored by bardur.arantsson's avatar bardur.arantsson Committed by GitHub
Browse files

Merge pull request #3779 from grayjay/deduplicate-targets

Deduplicate build targets by storing them in a set.
parents 0786c4b5 401ee671
......@@ -144,7 +144,7 @@ import Control.Exception
-- implemented in terms of adjustments to the parameters.
--
data DepResolverParams = DepResolverParams {
depResolverTargets :: [PackageName],
depResolverTargets :: Set PackageName,
depResolverConstraints :: [LabeledPackageConstraint],
depResolverPreferences :: [PackagePreference],
depResolverPreferenceDefault :: PackagesPreferenceDefault,
......@@ -165,7 +165,7 @@ data DepResolverParams = DepResolverParams {
showDepResolverParams :: DepResolverParams -> String
showDepResolverParams p =
"targets: " ++ intercalate ", " (map display (depResolverTargets p))
"targets: " ++ intercalate ", " (map display $ Set.toList (depResolverTargets p))
++ "\nconstraints: "
++ concatMap (("\n " ++) . showLabeledConstraint)
(depResolverConstraints p)
......@@ -221,7 +221,7 @@ basicDepResolverParams :: InstalledPackageIndex
-> DepResolverParams
basicDepResolverParams installedPkgIndex sourcePkgIndex =
DepResolverParams {
depResolverTargets = [],
depResolverTargets = Set.empty,
depResolverConstraints = [],
depResolverPreferences = [],
depResolverPreferenceDefault = PreferLatestForSelected,
......@@ -242,7 +242,7 @@ addTargets :: [PackageName]
-> DepResolverParams -> DepResolverParams
addTargets extraTargets params =
params {
depResolverTargets = extraTargets ++ depResolverTargets params
depResolverTargets = Set.fromList extraTargets `Set.union` depResolverTargets params
}
addConstraints :: [LabeledPackageConstraint]
......@@ -334,7 +334,7 @@ dontUpgradeNonUpgradeablePackages params =
[ LabeledPackageConstraint
(PackageConstraintInstalled pkgname)
ConstraintSourceNonUpgradeablePackage
| notElem (PackageName "base") (depResolverTargets params)
| Set.notMember (PackageName "base") (depResolverTargets params)
, pkgname <- map PackageName [ "base", "ghc-prim", "integer-gmp"
, "integer-simple" ]
, isInstalled pkgname ]
......@@ -454,7 +454,7 @@ upgradeDependencies = setPreferenceDefault PreferAllLatest
reinstallTargets :: DepResolverParams -> DepResolverParams
reinstallTargets params =
hideInstalledPackagesAllVersions (depResolverTargets params) params
hideInstalledPackagesAllVersions (Set.toList $ depResolverTargets params) params
-- | A basic solver policy on which all others are built.
......@@ -598,7 +598,7 @@ resolveDependencies :: Platform
--TODO: is this needed here? see dontUpgradeNonUpgradeablePackages
resolveDependencies platform comp _pkgConfigDB _solver params
| null (depResolverTargets params)
| Set.null (depResolverTargets params)
= return (validateSolverResult platform comp indGoals [])
where
indGoals = depResolverIndependentGoals params
......@@ -629,8 +629,7 @@ resolveDependencies platform comp pkgConfigDB solver params =
enableBj
order) = dontUpgradeNonUpgradeablePackages params
preferences = interpretPackagesPreference
(Set.fromList targets) defpref prefs
preferences = interpretPackagesPreference targets defpref prefs
-- | Give an interpretation to the global 'PackagesPreference' as
......@@ -854,7 +853,7 @@ resolveWithoutDependencies (DepResolverParams targets constraints
prefs defpref installedPkgIndex sourcePkgIndex
_reorderGoals _countConflicts _indGoals _avoidReinstalls
_shadowing _strFlags _maxBjumps _enableBj _order) =
collectEithers (map selectPackage targets)
collectEithers $ map selectPackage (Set.toList targets)
where
selectPackage :: PackageName -> Either ResolveNoDepsError UnresolvedSourcePackage
selectPackage pkgname
......@@ -892,8 +891,7 @@ resolveWithoutDependencies (DepResolverParams targets constraints
| PackageConstraintVersion name range <- pcs ]
packagePreferences :: PackageName -> PackagePreferences
packagePreferences = interpretPackagesPreference
(Set.fromList targets) defpref prefs
packagePreferences = interpretPackagesPreference targets defpref prefs
collectEithers :: [Either a b] -> Either [a] [b]
......
......@@ -10,6 +10,7 @@ module Distribution.Solver.Modular.Solver
import Data.Map as M
import Data.List as L
import Data.Set as S
import Data.Version
import Distribution.Compiler (CompilerInfo)
......@@ -93,7 +94,7 @@ solve :: SolverConfig -- ^ solver parameters
-> PkgConfigDb -- ^ available pkg-config pkgs
-> (PN -> PackagePreferences) -- ^ preferences
-> Map PN [LabeledPackageConstraint] -- ^ global constraints
-> [PN] -- ^ global goals
-> Set PN -- ^ global goals
-> Log Message (Assignment, RevDepMap)
solve sc cinfo idx pkgConfigDB userPrefs userConstraints userGoals =
explorePhase $
......@@ -134,7 +135,7 @@ solve sc cinfo idx pkgConfigDB userPrefs userConstraints userGoals =
])
buildPhase = traceTree "build.json" id
$ addLinking
$ buildTree idx (independentGoals sc) userGoals
$ buildTree idx (independentGoals sc) (S.toList userGoals)
-- Counting conflicts and reordering goals interferes, as both are strategies to
-- change the order of goals.
......
......@@ -2,6 +2,8 @@ module Distribution.Solver.Types.DependencyResolver
( DependencyResolver
) where
import Data.Set (Set)
import Distribution.Solver.Types.LabeledPackageConstraint
import Distribution.Solver.Types.PkgConfigDb ( PkgConfigDb )
import Distribution.Solver.Types.PackagePreferences
......@@ -30,5 +32,5 @@ type DependencyResolver loc = Platform
-> PkgConfigDb
-> (PackageName -> PackagePreferences)
-> [LabeledPackageConstraint]
-> [PackageName]
-> Set PackageName
-> Progress String String [ResolverPackage loc]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment