Skip to content

Combine non-installable and non-upgradable package lists (fixes #8581) #9148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ showFR _ (NewPackageHasUnbuildableRequiredComponent comp dr) = " (" ++ showExpos
showFR _ (PackageRequiresMissingComponent qpn comp) = " (requires " ++ showExposedComponent comp ++ " from " ++ showQPN qpn ++ ", but the component does not exist)"
showFR _ (PackageRequiresPrivateComponent qpn comp) = " (requires " ++ showExposedComponent comp ++ " from " ++ showQPN qpn ++ ", but the component is private)"
showFR _ (PackageRequiresUnbuildableComponent qpn comp) = " (requires " ++ showExposedComponent comp ++ " from " ++ showQPN qpn ++ ", but the component is not buildable in the current environment)"
showFR _ CannotInstall = " (only already installed instances can be used)"
showFR _ CannotReinstall = " (avoiding to reinstall a package with same version but new dependencies)"
showFR _ NotExplicit = " (not a user-provided goal nor mentioned as a constraint, but reject-unconstrained-dependencies was set)"
showFR _ Shadowed = " (shadowed by another installed package with same version)"
Expand Down
13 changes: 0 additions & 13 deletions cabal-install-solver/src/Distribution/Solver/Modular/Preference.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ module Distribution.Solver.Modular.Preference
, preferLinked
, preferPackagePreferences
, preferReallyEasyGoalChoices
, requireInstalled
, onlyConstrained
, sortGoals
, pruneAfterFirstSuccess
Expand Down Expand Up @@ -318,18 +317,6 @@ enforceManualFlags pcs = go
in W.mapWithKey (restrictToggling d flagConstraintValues) ts
go x = x

-- | Require installed packages.
requireInstalled :: (PN -> Bool) -> EndoTreeTrav d c
requireInstalled p = go
where
go (PChoiceF v@(Q _ pn) rdm gr cs)
| p pn = PChoiceF v rdm gr (W.mapWithKey installed cs)
| otherwise = PChoiceF v rdm gr cs
where
installed (POption (I _ (Inst _)) _) x = x
installed _ _ = Fail (varToConflictSet (P v)) CannotInstall
go x = x

-- | Avoid reinstalls.
--
-- This is a tricky strategy. If a package version is installed already and the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ data SolverConfig = SolverConfig {
avoidReinstalls :: AvoidReinstalls,
shadowPkgs :: ShadowPkgs,
strongFlags :: StrongFlags,
allowBootLibInstalls :: AllowBootLibInstalls,
nonInstallablePackages :: [PackageName],
onlyConstrained :: OnlyConstrained,
maxBackjumps :: Maybe Int,
enableBackjumping :: EnableBackjumping,
Expand Down Expand Up @@ -141,9 +139,6 @@ solve sc cinfo idx pkgConfigDB userPrefs userConstraints userGoals =
validateLinking idx .
validateTree cinfo idx pkgConfigDB
prunePhase = (if asBool (avoidReinstalls sc) then P.avoidReinstalls (const True) else id) .
(if asBool (allowBootLibInstalls sc)
then id
else P.requireInstalled (`elem` nonInstallablePackages sc)) .
(case onlyConstrained sc of
OnlyConstrainedAll ->
P.onlyConstrained pkgIsExplicit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ data FailReason = UnsupportedExtension Extension
| PackageRequiresMissingComponent QPN ExposedComponent
| PackageRequiresPrivateComponent QPN ExposedComponent
| PackageRequiresUnbuildableComponent QPN ExposedComponent
| CannotInstall
| CannotReinstall
| NotExplicit
| Shadowed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ data ConstraintSource =
| ConstraintSourceUserTarget

-- | Internal requirement to use installed versions of packages like ghc-prim.
| ConstraintSourceNonUpgradeablePackage
| ConstraintSourceNonReinstallablePackage

-- | Internal constraint used by @cabal freeze@.
| ConstraintSourceFreeze
Expand Down Expand Up @@ -64,8 +64,8 @@ showConstraintSource (ConstraintSourceProjectConfig path) =
showConstraintSource (ConstraintSourceUserConfig path)= "user config " ++ path
showConstraintSource ConstraintSourceCommandlineFlag = "command line flag"
showConstraintSource ConstraintSourceUserTarget = "user target"
showConstraintSource ConstraintSourceNonUpgradeablePackage =
"non-upgradeable package"
showConstraintSource ConstraintSourceNonReinstallablePackage =
"non-reinstallable package"
showConstraintSource ConstraintSourceFreeze = "cabal freeze"
showConstraintSource ConstraintSourceConfigFlagOrTarget =
"config file, command line flag, or user target"
Expand Down
43 changes: 9 additions & 34 deletions cabal-install/src/Distribution/Client/Dependency.hs
Original file line number Diff line number Diff line change
Expand Up @@ -436,26 +436,18 @@ setSolverVerbosity verbosity params =
}

-- | Some packages are specific to a given compiler version and should never be
-- upgraded.
dontUpgradeNonUpgradeablePackages :: DepResolverParams -> DepResolverParams
dontUpgradeNonUpgradeablePackages params =
-- reinstalled.
dontInstallNonReinstallablePackages :: DepResolverParams -> DepResolverParams
dontInstallNonReinstallablePackages params =
addConstraints extraConstraints params
where
extraConstraints =
[ LabeledPackageConstraint
(PackageConstraint (ScopeAnyQualifier pkgname) PackagePropertyInstalled)
ConstraintSourceNonUpgradeablePackage
| Set.notMember (mkPackageName "base") (depResolverTargets params)
, pkgname <- nonUpgradeablePackages
, isInstalled pkgname
ConstraintSourceNonReinstallablePackage
| pkgname <- nonReinstallablePackages
]

isInstalled =
not
. null
. InstalledPackageIndex.lookupPackageName
(depResolverInstalledPkgIndex params)

-- | The set of non-reinstallable packages includes those which cannot be
-- rebuilt using a GHC installation and Hackage-published source distribution.
-- There are a few reasons why this might be true:
Expand All @@ -471,15 +463,8 @@ dontUpgradeNonUpgradeablePackages params =
-- * the package does not have a complete (that is, buildable) source distribution.
-- For instance, some packages provided by GHC rely on files outside of the
-- source tree generated by GHC's build system.
--
-- Note: the list of non-upgradable/non-installable packages used to be
-- respectively in this module and in `Distribution.Solver.Modular.Solver`.
-- Since they were kept synced, they are now combined in the following list.
--
-- See: https://github.com/haskell/cabal/issues/8581 and
-- https://github.com/haskell/cabal/issues/9064.
nonUpgradeablePackages :: [PackageName]
nonUpgradeablePackages =
nonReinstallablePackages :: [PackageName]
nonReinstallablePackages =
[ mkPackageName "base"
, mkPackageName "ghc-bignum"
, mkPackageName "ghc-prim"
Expand Down Expand Up @@ -792,12 +777,6 @@ resolveDependencies
-> Solver
-> DepResolverParams
-> Progress String String SolverInstallPlan
-- TODO: is this needed here? see dontUpgradeNonUpgradeablePackages
resolveDependencies platform comp _pkgConfigDB _solver params
| Set.null (depResolverTargets params) =
return (validateSolverResult platform comp indGoals [])
where
indGoals = depResolverIndependentGoals params
resolveDependencies platform comp pkgConfigDB solver params =
Step (showDepResolverParams finalparams) $
fmap (validateSolverResult platform comp indGoals) $
Expand All @@ -812,10 +791,6 @@ resolveDependencies platform comp pkgConfigDB solver params =
noReinstalls
shadowing
strFlags
allowBootLibs
-- See comment of nonUpgradeablePackages about
-- non-installable and non-upgradable packages.
nonUpgradeablePackages
onlyConstrained_
maxBkjumps
enableBj
Expand Down Expand Up @@ -848,7 +823,7 @@ resolveDependencies platform comp pkgConfigDB solver params =
noReinstalls
shadowing
strFlags
allowBootLibs
_allowBootLibs
onlyConstrained_
maxBkjumps
enableBj
Expand All @@ -858,7 +833,7 @@ resolveDependencies platform comp pkgConfigDB solver params =
) =
if asBool (depResolverAllowBootLibInstalls params)
then params
else dontUpgradeNonUpgradeablePackages params
else dontInstallNonReinstallablePackages params

preferences :: PackageName -> PackagePreferences
preferences = interpretPackagesPreference targets defpref prefs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,17 @@ tests =
, runTest $ mkTest db12 "baseShim6" ["E"] (solverSuccess [("E", 1), ("syb", 2)])
]
, testGroup
"Base and Nonupgradable"
"Base and non-reinstallable"
[ runTest $
mkTest dbBase "Refuse to install base without --allow-boot-library-installs" ["base"] $
solverFailure (isInfixOf "only already installed instances can be used")
solverFailure (isInfixOf "rejecting: base-1.0.0 (constraint from non-reinstallable package requires installed instance)")
, runTest $
allowBootLibInstalls $
mkTest dbBase "Install base with --allow-boot-library-installs" ["base"] $
solverSuccess [("base", 1), ("ghc-prim", 1), ("integer-gmp", 1), ("integer-simple", 1)]
, runTest $
mkTest dbNonupgrade "Refuse to install newer ghc requested by another library" ["A"] $
solverFailure (isInfixOf "rejecting: ghc-2.0.0 (constraint from non-upgradeable package requires installed instance)")
solverFailure (isInfixOf "rejecting: ghc-2.0.0 (constraint from non-reinstallable package requires installed instance)")
]
, testGroup
"reject-unconstrained"
Expand Down