Skip to content

Commit c8b468d

Browse files
committed
refactor: fix some TODOs
Implement hideInstalledPackagesSpecificBySourcePackageId using constraints. Remove InstalledPackageIndex from DepResolverParams since it is not needed anymore by the DSL.
1 parent b494c66 commit c8b468d

File tree

8 files changed

+44
-55
lines changed

8 files changed

+44
-55
lines changed

cabal-install/src/Distribution/Client/Configure.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,14 +463,13 @@ planLocalPackage
463463
. setSolveExecutables (SolveExecutables False)
464464
. setSolverVerbosity verbosity
465465
$ standardInstallPolicy
466-
installedPkgIndex
467466
-- NB: We pass in an *empty* source package database,
468467
-- because cabal configure assumes that all dependencies
469468
-- have already been installed
470469
(SourcePackageDb mempty packagePrefs)
471470
[SpecificSourcePackage localPkg]
472471

473-
return (resolveDependencies platform (compilerInfo comp) pkgConfigDb resolverParams)
472+
return (resolveDependencies platform (compilerInfo comp) pkgConfigDb installedPkgIndex resolverParams)
474473

475474
-- | Call an installer for an 'SourcePackage' but override the configure
476475
-- flags with the ones given by the 'ReadyPackage'. In particular the

cabal-install/src/Distribution/Client/Dependency.hs

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ data DepResolverParams = DepResolverParams
177177
, depResolverConstraints :: [LabeledPackageConstraint]
178178
, depResolverPreferences :: [PackagePreference]
179179
, depResolverPreferenceDefault :: PackagesPreferenceDefault
180-
, depResolverInstalledPkgIndex :: InstalledPackageIndex
181180
, depResolverSourcePkgIndex :: PackageIndex.PackageIndex UnresolvedSourcePackage
182181
, depResolverReorderGoals :: ReorderGoals
183182
, depResolverCountConflicts :: CountConflicts
@@ -270,16 +269,14 @@ showPackagePreference (PackageStanzasPreference pn st) =
270269
prettyShow pn ++ " " ++ show st
271270

272271
basicDepResolverParams
273-
:: InstalledPackageIndex
274-
-> PackageIndex.PackageIndex UnresolvedSourcePackage
272+
:: PackageIndex.PackageIndex UnresolvedSourcePackage
275273
-> DepResolverParams
276-
basicDepResolverParams installedPkgIndex sourcePkgIndex =
274+
basicDepResolverParams sourcePkgIndex =
277275
DepResolverParams
278276
{ depResolverTargets = Set.empty
279277
, depResolverConstraints = []
280278
, depResolverPreferences = []
281279
, depResolverPreferenceDefault = PreferLatestForSelected
282-
, depResolverInstalledPkgIndex = installedPkgIndex
283280
, depResolverSourcePkgIndex = sourcePkgIndex
284281
, depResolverReorderGoals = ReorderGoals False
285282
, depResolverCountConflicts = CountConflicts True
@@ -477,33 +474,20 @@ addSourcePackages pkgs params =
477474
pkgs
478475
}
479476

477+
-- FIXME this actually works by package name, not by package id
480478
hideInstalledPackagesSpecificBySourcePackageId
481479
:: [PackageId]
482480
-> DepResolverParams
483481
-> DepResolverParams
484-
hideInstalledPackagesSpecificBySourcePackageId pkgids params =
485-
-- TODO: this should work using exclude constraints instead
486-
params
487-
{ depResolverInstalledPkgIndex =
488-
foldl'
489-
(flip InstalledPackageIndex.deleteSourcePackageId)
490-
(depResolverInstalledPkgIndex params)
491-
pkgids
492-
}
493-
494-
hideInstalledPackagesAllVersions
495-
:: [PackageName]
496-
-> DepResolverParams
497-
-> DepResolverParams
498-
hideInstalledPackagesAllVersions pkgnames params =
499-
-- TODO: this should work using exclude constraints instead
500-
params
501-
{ depResolverInstalledPkgIndex =
502-
foldl'
503-
(flip InstalledPackageIndex.deletePackageName)
504-
(depResolverInstalledPkgIndex params)
505-
pkgnames
506-
}
482+
hideInstalledPackagesSpecificBySourcePackageId pkgids =
483+
addConstraints
484+
[ LabeledPackageConstraint
485+
(PackageConstraint (ScopeAnyQualifier name) PackagePropertySource)
486+
-- FIXME
487+
ConstraintSourceUnknown
488+
| pkgId <- pkgids
489+
, let name = packageName pkgId
490+
]
507491

508492
-- | Remove upper bounds in dependencies using the policy specified by the
509493
-- 'AllowNewer' argument (all/some/none).
@@ -685,17 +669,24 @@ upgradeDependencies = setPreferenceDefault PreferAllLatest
685669

686670
reinstallTargets :: DepResolverParams -> DepResolverParams
687671
reinstallTargets params =
688-
hideInstalledPackagesAllVersions (Set.toList $ depResolverTargets params) params
672+
addConstraints
673+
[ LabeledPackageConstraint
674+
( PackageConstraint
675+
(ScopeAnyQualifier pkgName)
676+
PackagePropertySource
677+
)
678+
ConstraintSourceProfiledDynamic
679+
| pkgName <- Set.toList (depResolverTargets params)
680+
]
681+
params
689682

690683
-- | A basic solver policy on which all others are built.
691684
basicInstallPolicy
692-
:: InstalledPackageIndex
693-
-> SourcePackageDb
685+
:: SourcePackageDb
694686
-> [PackageSpecifier UnresolvedSourcePackage]
695687
-> DepResolverParams
696688
basicInstallPolicy
697-
installedPkgIndex
698-
(SourcePackageDb sourcePkgIndex sourcePkgPrefs)
689+
(SourcePackageDb sourcePkgIndex sourcePkgPrefs)
699690
pkgSpecifiers =
700691
addPreferences
701692
[ PackageVersionPreference name ver
@@ -710,22 +701,19 @@ basicInstallPolicy
710701
. addSourcePackages
711702
[pkg | SpecificSourcePackage pkg <- pkgSpecifiers]
712703
$ basicDepResolverParams
713-
installedPkgIndex
714704
sourcePkgIndex
715705

716706
-- | The policy used by all the standard commands, install, fetch, freeze etc
717707
-- (but not the v2-build and related commands).
718708
--
719709
-- It extends the 'basicInstallPolicy' with a policy on setup deps.
720710
standardInstallPolicy
721-
:: InstalledPackageIndex
722-
-> SourcePackageDb
711+
:: SourcePackageDb
723712
-> [PackageSpecifier UnresolvedSourcePackage]
724713
-> DepResolverParams
725-
standardInstallPolicy installedPkgIndex sourcePkgDb pkgSpecifiers =
714+
standardInstallPolicy sourcePkgDb pkgSpecifiers =
726715
addDefaultSetupDependencies mkDefaultSetupDeps $
727716
basicInstallPolicy
728-
installedPkgIndex
729717
sourcePkgDb
730718
pkgSpecifiers
731719
where
@@ -774,9 +762,10 @@ resolveDependencies
774762
:: Platform
775763
-> CompilerInfo
776764
-> Maybe PkgConfigDb
765+
-> InstalledPackageIndex
777766
-> DepResolverParams
778767
-> Progress String String SolverInstallPlan
779-
resolveDependencies platform comp pkgConfigDB params =
768+
resolveDependencies platform comp pkgConfigDB installedPkgIndex params =
780769
Step (showDepResolverParams finalparams) $
781770
fmap (validateSolverResult platform comp) $
782771
runSolver
@@ -810,7 +799,6 @@ resolveDependencies platform comp pkgConfigDB params =
810799
constraints
811800
prefs
812801
defpref
813-
installedPkgIndex
814802
sourcePkgIndex
815803
reordGoals
816804
cntConflicts
@@ -1122,14 +1110,14 @@ configuredPackageProblems
11221110
-- It simply means preferences for installed packages will be ignored.
11231111
resolveWithoutDependencies
11241112
:: DepResolverParams
1113+
-> InstalledPackageIndex
11251114
-> Either [ResolveNoDepsError] [UnresolvedSourcePackage]
11261115
resolveWithoutDependencies
11271116
( DepResolverParams
11281117
targets
11291118
constraints
11301119
prefs
11311120
defpref
1132-
installedPkgIndex
11331121
sourcePkgIndex
11341122
_reorderGoals
11351123
_countConflicts
@@ -1145,7 +1133,7 @@ resolveWithoutDependencies
11451133
_onlyConstrained
11461134
_order
11471135
_verbosity
1148-
) =
1136+
) installedPkgIndex =
11491137
collectEithers $ map selectPackage (Set.toList targets)
11501138
where
11511139
selectPackage :: PackageName -> Either ResolveNoDepsError UnresolvedSourcePackage

cabal-install/src/Distribution/Client/Fetch.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ planPackages
177177
platform
178178
(compilerInfo comp)
179179
pkgConfigDb
180+
installedPkgIndex
180181
resolverParams
181182

182183
-- The packages we want to fetch are those packages the 'InstallPlan'
@@ -188,7 +189,7 @@ planPackages
188189
]
189190
| otherwise =
190191
either (dieWithException verbosity . PlanPackages . unlines . map show) return $
191-
resolveWithoutDependencies resolverParams
192+
resolveWithoutDependencies resolverParams installedPkgIndex
192193
where
193194
resolverParams :: DepResolverParams
194195
resolverParams =
@@ -219,7 +220,7 @@ planPackages
219220
-- already installed. Since we want to get the source packages of
220221
-- things we might have installed (but not have the sources for).
221222
. reinstallTargets
222-
$ standardInstallPolicy installedPkgIndex sourcePkgDb pkgSpecifiers
223+
$ standardInstallPolicy sourcePkgDb pkgSpecifiers
223224

224225
includeDependencies = fromFlag (fetchDeps fetchFlags)
225226
logMsg message rest = debug verbosity message >> rest

cabal-install/src/Distribution/Client/Freeze.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ planPackages
215215
platform
216216
(compilerInfo comp)
217217
pkgConfigDb
218+
installedPkgIndex
218219
resolverParams
219220

220221
return $ pruneInstallPlan installPlan pkgSpecifiers
@@ -244,7 +245,7 @@ planPackages
244245
in LabeledPackageConstraint pc ConstraintSourceFreeze
245246
| pkgSpecifier <- pkgSpecifiers
246247
]
247-
$ standardInstallPolicy installedPkgIndex sourcePkgDb pkgSpecifiers
248+
$ standardInstallPolicy sourcePkgDb pkgSpecifiers
248249

249250
logMsg message rest = debug verbosity message >> rest
250251

cabal-install/src/Distribution/Client/Get.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ get verbosity repoCtxt globalFlags getFlags userTargets = do
128128
pkgs <-
129129
either (dieWithException verbosity . PkgSpecifierException . map show) return $
130130
resolveWithoutDependencies
131-
(resolverParams sourcePkgDb pkgSpecifiers)
131+
(resolverParams sourcePkgDb pkgSpecifiers) mempty
132132

133133
unless (null prefix) $
134134
createDirectoryIfMissing True prefix
@@ -148,7 +148,7 @@ get verbosity repoCtxt globalFlags getFlags userTargets = do
148148
resolverParams :: SourcePackageDb -> [PackageSpecifier UnresolvedSourcePackage] -> DepResolverParams
149149
resolverParams sourcePkgDb pkgSpecifiers =
150150
-- TODO: add command-line constraint and preference args for unpack
151-
standardInstallPolicy mempty sourcePkgDb pkgSpecifiers
151+
standardInstallPolicy sourcePkgDb pkgSpecifiers
152152

153153
onlyPkgDescr = fromFlagOrDefault False (getOnlyPkgDescr getFlags)
154154

cabal-install/src/Distribution/Client/Install.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ planPackages
588588
platform
589589
(compilerInfo comp)
590590
pkgConfigDb
591+
installedPkgIndex
591592
resolverParams
592593
>>= if onlyDeps then pruneInstallPlan pkgSpecifiers else return
593594
where
@@ -649,7 +650,6 @@ planPackages
649650
-- doesn't understand how to install them
650651
. setSolveExecutables (SolveExecutables False)
651652
$ standardInstallPolicy
652-
installedPkgIndex
653653
sourcePkgDb
654654
pkgSpecifiers
655655

cabal-install/src/Distribution/Client/ProjectPlanning.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,7 @@ planPackages
12691269
platform
12701270
(compilerInfo comp)
12711271
pkgConfigDB
1272+
installedPkgIndex
12721273
resolverParams
12731274
where
12741275
-- TODO: [nice to have] disable multiple instances restriction in
@@ -1387,7 +1388,6 @@ planPackages
13871388
-- Note: we don't use the standardInstallPolicy here, since that uses
13881389
-- its own addDefaultSetupDependencies that is not appropriate for us.
13891390
basicInstallPolicy
1390-
installedPkgIndex
13911391
sourcePkgDb
13921392
localPackages
13931393

cabal-install/src/Distribution/Client/Types/PackageSpecifier.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Distribution.Client.Types.PackageSpecifier
1111
import Distribution.Client.Compat.Prelude
1212
import Prelude ()
1313

14-
import Distribution.Package (Package (..), PackageIdentifier (..), packageName, packageVersion)
14+
import Distribution.Package (Package (..), PackageIdentifier (..), packageName)
1515
import Distribution.Types.PackageName (PackageName)
1616
import Distribution.Version (nullVersion, thisVersion)
1717

@@ -48,12 +48,12 @@ pkgSpecifierConstraints (NamedPackage name props) = map toLpc props
4848
(PackageConstraint (scopeToplevel name) prop)
4949
ConstraintSourceUserTarget
5050
pkgSpecifierConstraints (SpecificSourcePackage pkg) =
51-
[LabeledPackageConstraint pc ConstraintSourceUserTarget]
51+
[LabeledPackageConstraint sourceConstraint ConstraintSourceUserTarget]
5252
where
53-
pc =
53+
sourceConstraint =
5454
PackageConstraint
5555
(ScopeTarget $ packageName pkg)
56-
(PackagePropertyVersion $ thisVersion (packageVersion pkg))
56+
PackagePropertySource
5757

5858
mkNamedPackage :: PackageIdentifier -> PackageSpecifier pkg
5959
mkNamedPackage pkgId =

0 commit comments

Comments
 (0)