diff --git a/cabal-install-solver/cabal-install-solver.cabal b/cabal-install-solver/cabal-install-solver.cabal index fe440a78963..a3df740ea97 100644 --- a/cabal-install-solver/cabal-install-solver.cabal +++ b/cabal-install-solver/cabal-install-solver.cabal @@ -77,7 +77,6 @@ library Distribution.Solver.Modular.Version Distribution.Solver.Modular.WeightedPSQ Distribution.Solver.Types.ComponentDeps - Distribution.Solver.Types.ConstraintSource Distribution.Solver.Types.DependencyResolver Distribution.Solver.Types.Flag Distribution.Solver.Types.InstalledPreference diff --git a/cabal-install-solver/src/Distribution/Solver/Modular.hs b/cabal-install-solver/src/Distribution/Solver/Modular.hs index 2aac240318f..b3440219e0b 100644 --- a/cabal-install-solver/src/Distribution/Solver/Modular.hs +++ b/cabal-install-solver/src/Distribution/Solver/Modular.hs @@ -58,7 +58,7 @@ import Distribution.Verbosity -- | Ties the two worlds together: classic cabal-install vs. the modular -- solver. Performs the necessary translations before and after. -modularResolver :: SolverConfig -> DependencyResolver loc +modularResolver :: (Typeable cs, Show cs, Eq cs) => SolverConfig -> DependencyResolver loc cs modularResolver sc (Platform arch os) cinfo iidx sidx pkgConfigDB pprefs pcs pns = uncurry postprocess <$> -- convert install plan solve' sc cinfo idx pkgConfigDB pprefs gcs pns @@ -113,12 +113,13 @@ modularResolver sc (Platform arch os) cinfo iidx sidx pkgConfigDB pprefs pcs pns -- Using the full log from a rerun of the solver ensures that the log is -- complete, i.e., it shows the whole chain of dependencies from the user -- targets to the conflicting packages. -solve' :: SolverConfig +solve' :: (Typeable cs, Eq cs, Show cs) + => SolverConfig -> CompilerInfo -> Index -> PkgConfigDb -> (PN -> PackagePreferences) - -> Map PN [LabeledPackageConstraint] + -> Map PN [LabeledPackageConstraint cs] -> Set PN -> Progress String String (Assignment, RevDepMap) solve' sc cinfo idx pkgConfigDB pprefs gcs pns = diff --git a/cabal-install-solver/src/Distribution/Solver/Modular/IndexConversion.hs b/cabal-install-solver/src/Distribution/Solver/Modular/IndexConversion.hs index 72d0b8193e3..cabb0fe8863 100644 --- a/cabal-install-solver/src/Distribution/Solver/Modular/IndexConversion.hs +++ b/cabal-install-solver/src/Distribution/Solver/Modular/IndexConversion.hs @@ -53,7 +53,7 @@ import Distribution.Solver.Modular.Version -- resolving these situations. However, the right thing to do is to -- fix the problem there, so for now, shadowing is only activated if -- explicitly requested. -convPIs :: OS -> Arch -> CompilerInfo -> Map PN [LabeledPackageConstraint] +convPIs :: OS -> Arch -> CompilerInfo -> Map PN [LabeledPackageConstraint cs] -> ShadowPkgs -> StrongFlags -> SolveExecutables -> SI.InstalledPackageIndex -> CI.PackageIndex (SourcePackage loc) -> Index @@ -153,14 +153,14 @@ convIPId dr comp idx ipid = -- | Convert a cabal-install source package index to the simpler, -- more uniform index format of the solver. -convSPI' :: OS -> Arch -> CompilerInfo -> Map PN [LabeledPackageConstraint] +convSPI' :: OS -> Arch -> CompilerInfo -> Map PN [LabeledPackageConstraint cs] -> StrongFlags -> SolveExecutables -> CI.PackageIndex (SourcePackage loc) -> [(PN, I, PInfo)] convSPI' os arch cinfo constraints strfl solveExes = L.map (convSP os arch cinfo constraints strfl solveExes) . CI.allPackages -- | Convert a single source package into the solver-specific format. -convSP :: OS -> Arch -> CompilerInfo -> Map PN [LabeledPackageConstraint] +convSP :: OS -> Arch -> CompilerInfo -> Map PN [LabeledPackageConstraint cs] -> StrongFlags -> SolveExecutables -> SourcePackage loc -> (PN, I, PInfo) convSP os arch cinfo constraints strfl solveExes (SourcePackage (PackageIdentifier pn pv) gpd _ _pl) = let i = I pv InRepo @@ -172,7 +172,7 @@ convSP os arch cinfo constraints strfl solveExes (SourcePackage (PackageIdentifi -- want to keep the condition tree, but simplify much of the test. -- | Convert a generic package description to a solver-specific 'PInfo'. -convGPD :: OS -> Arch -> CompilerInfo -> [LabeledPackageConstraint] +convGPD :: OS -> Arch -> CompilerInfo -> [LabeledPackageConstraint cs] -> StrongFlags -> SolveExecutables -> PN -> GenericPackageDescription -> PInfo convGPD os arch cinfo constraints strfl solveExes pn @@ -249,7 +249,7 @@ convGPD os arch cinfo constraints strfl solveExes pn testConditionForComponent :: OS -> Arch -> CompilerInfo - -> [LabeledPackageConstraint] + -> [LabeledPackageConstraint cs] -> (a -> Bool) -> CondTree ConfVar [Dependency] a -> Maybe Bool diff --git a/cabal-install-solver/src/Distribution/Solver/Modular/Message.hs b/cabal-install-solver/src/Distribution/Solver/Modular/Message.hs index 11fa7ca874d..c40910c9d29 100644 --- a/cabal-install-solver/src/Distribution/Solver/Modular/Message.hs +++ b/cabal-install-solver/src/Distribution/Solver/Modular/Message.hs @@ -28,7 +28,6 @@ import Distribution.Solver.Modular.Package import Distribution.Solver.Modular.Tree ( FailReason(..), POption(..), ConflictingDep(..) ) import Distribution.Solver.Modular.Version -import Distribution.Solver.Types.ConstraintSource import Distribution.Solver.Types.PackagePath import Distribution.Solver.Types.Progress import Distribution.Types.LibraryName @@ -311,10 +310,10 @@ showFR _ NotExplicit = " (not a user-provided goal nor ment showFR _ Shadowed = " (shadowed by another installed package with same version)" showFR _ (Broken u) = " (package is broken, missing dependency " ++ prettyShow u ++ ")" showFR _ UnknownPackage = " (unknown package)" -showFR _ (GlobalConstraintVersion vr src) = " (" ++ constraintSource src ++ " requires " ++ prettyShow vr ++ ")" -showFR _ (GlobalConstraintInstalled src) = " (" ++ constraintSource src ++ " requires installed instance)" -showFR _ (GlobalConstraintSource src) = " (" ++ constraintSource src ++ " requires source instance)" -showFR _ (GlobalConstraintFlag src) = " (" ++ constraintSource src ++ " requires opposite flag selection)" +showFR _ (GlobalConstraintVersion vr src) = " (constraint from " ++ show src ++ " requires " ++ prettyShow vr ++ ")" +showFR _ (GlobalConstraintInstalled src) = " (constraint from " ++ show src ++ " requires installed instance)" +showFR _ (GlobalConstraintSource src) = " (constraint from " ++ show src ++ " requires source instance)" +showFR _ (GlobalConstraintFlag src) = " (constraint from " ++ show src ++ " requires opposite flag selection)" showFR _ ManualFlag = " (manual flag can only be changed explicitly)" showFR c Backjump = " (backjumping, conflict set: " ++ showConflictSet c ++ ")" showFR _ MultipleInstances = " (multiple instances)" @@ -333,9 +332,6 @@ showExposedComponent (ExposedLib LMainLibName) = "library" showExposedComponent (ExposedLib (LSubLibName name)) = "library '" ++ unUnqualComponentName name ++ "'" showExposedComponent (ExposedExe name) = "executable '" ++ unUnqualComponentName name ++ "'" -constraintSource :: ConstraintSource -> String -constraintSource src = "constraint from " ++ showConstraintSource src - showConflictingDep :: ConflictingDep -> String showConflictingDep (ConflictingDep dr (PkgComponent qpn comp) ci) = let DependencyReason qpn' _ _ = dr @@ -357,4 +353,4 @@ showConflictingDep (ConflictingDep dr (PkgComponent qpn comp) ci) = -- >>> let v0 = POption (I (mkVersion [0]) InRepo) Nothing -- >>> let v1 = POption (I (mkVersion [1]) InRepo) Nothing -- >>> let i0 = POption (I (mkVersion [0]) (Inst $ mkUnitId "foo-bar-0-inplace")) Nothing --- >>> let i1 = POption (I (mkVersion [1]) (Inst $ mkUnitId "foo-bar-1-inplace")) Nothing \ No newline at end of file +-- >>> let i1 = POption (I (mkVersion [1]) (Inst $ mkUnitId "foo-bar-1-inplace")) Nothing diff --git a/cabal-install-solver/src/Distribution/Solver/Modular/Preference.hs b/cabal-install-solver/src/Distribution/Solver/Modular/Preference.hs index 9e0d5fb4d22..cd7c9342f87 100644 --- a/cabal-install-solver/src/Distribution/Solver/Modular/Preference.hs +++ b/cabal-install-solver/src/Distribution/Solver/Modular/Preference.hs @@ -172,10 +172,11 @@ preferPackageStanzaPreferences pcs = go -- given instance for a P-node. Translates the constraint into a -- tree-transformer that either leaves the subtree untouched, or replaces it -- with an appropriate failure node. -processPackageConstraintP :: forall d c. QPN +processPackageConstraintP :: forall d c cs. (Eq cs, Show cs, Typeable cs) + => QPN -> ConflictSet -> I - -> LabeledPackageConstraint + -> LabeledPackageConstraint cs -> Tree d c -> Tree d c processPackageConstraintP qpn c i (LabeledPackageConstraint (PackageConstraint scope prop) src) r = @@ -186,24 +187,25 @@ processPackageConstraintP qpn c i (LabeledPackageConstraint (PackageConstraint s go :: I -> PackageProperty -> Tree d c go (I v _) (PackagePropertyVersion vr) | checkVR vr v = r - | otherwise = Fail c (GlobalConstraintVersion vr src) + | otherwise = Fail c (GlobalConstraintVersion vr (SomeSrc src)) go _ PackagePropertyInstalled | instI i = r - | otherwise = Fail c (GlobalConstraintInstalled src) + | otherwise = Fail c (GlobalConstraintInstalled (SomeSrc src)) go _ PackagePropertySource | not (instI i) = r - | otherwise = Fail c (GlobalConstraintSource src) + | otherwise = Fail c (GlobalConstraintSource (SomeSrc src)) go _ _ = r -- | Helper function that tries to enforce a single package constraint on a -- given flag setting for an F-node. Translates the constraint into a -- tree-transformer that either leaves the subtree untouched, or replaces it -- with an appropriate failure node. -processPackageConstraintF :: forall d c. QPN +processPackageConstraintF :: forall d c cs . (Eq cs, Show cs, Typeable cs) + => QPN -> Flag -> ConflictSet -> Bool - -> LabeledPackageConstraint + -> LabeledPackageConstraint cs -> Tree d c -> Tree d c processPackageConstraintF qpn f c b' (LabeledPackageConstraint (PackageConstraint scope prop) src) r = @@ -216,18 +218,19 @@ processPackageConstraintF qpn f c b' (LabeledPackageConstraint (PackageConstrain case lookupFlagAssignment f fa of Nothing -> r Just b | b == b' -> r - | otherwise -> Fail c (GlobalConstraintFlag src) + | otherwise -> Fail c (GlobalConstraintFlag (SomeSrc src)) go _ = r -- | Helper function that tries to enforce a single package constraint on a -- given flag setting for an F-node. Translates the constraint into a -- tree-transformer that either leaves the subtree untouched, or replaces it -- with an appropriate failure node. -processPackageConstraintS :: forall d c. QPN +processPackageConstraintS :: forall d c cs. (Typeable cs, Eq cs, Show cs) + => QPN -> OptionalStanza -> ConflictSet -> Bool - -> LabeledPackageConstraint + -> LabeledPackageConstraint cs -> Tree d c -> Tree d c processPackageConstraintS qpn s c b' (LabeledPackageConstraint (PackageConstraint scope prop) src) r = @@ -237,14 +240,15 @@ processPackageConstraintS qpn s c b' (LabeledPackageConstraint (PackageConstrain where go :: PackageProperty -> Tree d c go (PackagePropertyStanzas ss) = - if not b' && s `elem` ss then Fail c (GlobalConstraintFlag src) + if not b' && s `elem` ss then Fail c (GlobalConstraintFlag (SomeSrc src)) else r go _ = r -- | Traversal that tries to establish various kinds of user constraints. Works -- by selectively disabling choices that have been ruled out by global user -- constraints. -enforcePackageConstraints :: M.Map PN [LabeledPackageConstraint] +enforcePackageConstraints :: (Typeable cs, Eq cs, Show cs) + => M.Map PN [LabeledPackageConstraint cs] -> EndoTreeTrav d c enforcePackageConstraints pcs = go where @@ -291,7 +295,7 @@ enforcePackageConstraints pcs = go -- -- This function does not enforce any of the constraints, since that is done by -- 'enforcePackageConstraints'. -enforceManualFlags :: M.Map PN [LabeledPackageConstraint] -> EndoTreeTrav d c +enforceManualFlags :: M.Map PN [LabeledPackageConstraint cs] -> EndoTreeTrav d c enforceManualFlags pcs = go where go (FChoiceF qfn@(FN (Q _ pn) fn) rdm gr tr Manual d ts) = diff --git a/cabal-install-solver/src/Distribution/Solver/Modular/Solver.hs b/cabal-install-solver/src/Distribution/Solver/Modular/Solver.hs index 39bd7bf4690..e03ea680667 100644 --- a/cabal-install-solver/src/Distribution/Solver/Modular/Solver.hs +++ b/cabal-install-solver/src/Distribution/Solver/Modular/Solver.hs @@ -88,12 +88,13 @@ newtype PruneAfterFirstSuccess = PruneAfterFirstSuccess Bool -- has been added relatively recently. Cycles are only removed directly -- before exploration. -- -solve :: SolverConfig -- ^ solver parameters +solve :: (Eq cs, Show cs, Typeable cs) + => SolverConfig -- ^ solver parameters -> CompilerInfo -> Index -- ^ all available packages as an index -> PkgConfigDb -- ^ available pkg-config pkgs -> (PN -> PackagePreferences) -- ^ preferences - -> M.Map PN [LabeledPackageConstraint] -- ^ global constraints + -> M.Map PN [LabeledPackageConstraint cs] -- ^ global constraints -> S.Set PN -- ^ global goals -> RetryLog Message SolverFailure (Assignment, RevDepMap) solve sc cinfo idx pkgConfigDB userPrefs userConstraints userGoals = diff --git a/cabal-install-solver/src/Distribution/Solver/Modular/Tree.hs b/cabal-install-solver/src/Distribution/Solver/Modular/Tree.hs index 10d372525b1..5554e1bc5c2 100644 --- a/cabal-install-solver/src/Distribution/Solver/Modular/Tree.hs +++ b/cabal-install-solver/src/Distribution/Solver/Modular/Tree.hs @@ -1,10 +1,13 @@ {-# LANGUAGE DeriveFunctor, DeriveFoldable, DeriveTraversable #-} +{-# LANGUAGE GADTs #-} + module Distribution.Solver.Modular.Tree ( POption(..) , Tree(..) , TreeF(..) , Weight , FailReason(..) + , SomeSrc(..) , ConflictingDep(..) , ana , cata @@ -21,16 +24,16 @@ module Distribution.Solver.Modular.Tree import Control.Monad hiding (mapM, sequence) import Data.Foldable import Data.Traversable +import Type.Reflection (Typeable, eqTypeRep, typeOf, (:~~:) (..)) import Prelude hiding (foldr, mapM, sequence) import Distribution.Solver.Modular.Dependency import Distribution.Solver.Modular.Flag -import Distribution.Solver.Modular.Package import Distribution.Solver.Modular.PSQ (PSQ) +import Distribution.Solver.Modular.Package import Distribution.Solver.Modular.Version import Distribution.Solver.Modular.WeightedPSQ (WeightedPSQ) import qualified Distribution.Solver.Modular.WeightedPSQ as W -import Distribution.Solver.Types.ConstraintSource import Distribution.Solver.Types.Flag import Distribution.Solver.Types.PackagePath import Distribution.Types.PkgconfigVersionRange @@ -115,10 +118,7 @@ data FailReason = UnsupportedExtension Extension | Shadowed | Broken UnitId | UnknownPackage - | GlobalConstraintVersion VR ConstraintSource - | GlobalConstraintInstalled ConstraintSource - | GlobalConstraintSource ConstraintSource - | GlobalConstraintFlag ConstraintSource + | GlobalConstraint GlobalConstraintReason | ManualFlag | MalformedFlagChoice QFN | MalformedStanzaChoice QSN @@ -128,8 +128,26 @@ data FailReason = UnsupportedExtension Extension | DependenciesNotLinked String | CyclicDependencies | UnsupportedSpecVer Ver + deriving (Eq, Show) + +data GlobalConstraintReason + = GlobalConstraintVersion VR SomeSrc + | GlobalConstraintInstalled SomeSrc + | GlobalConstraintSource SomeSrc + | GlobalConstraintFlag SomeSrc deriving (Eq, Show) +data SomeSrc = forall src. (Typeable src, Eq src, Show src) => SomeSrc src + +instance Eq SomeSrc where + SomeSrc lhs == SomeSrc rhs = + case eqTypeRep (typeOf lhs) (typeOf rhs) of + Nothing -> False + Just HRefl -> lhs == rhs + +instance Show SomeSrc where + showsPrec d (SomeSrc lhs) = showsPrec d lhs + -- | Information about a dependency involved in a conflict, for error messages. data ConflictingDep = ConflictingDep (DependencyReason QPN) (PkgComponent QPN) CI deriving (Eq, Show) diff --git a/cabal-install-solver/src/Distribution/Solver/Types/ConstraintSource.hs b/cabal-install-solver/src/Distribution/Solver/Types/ConstraintSource.hs deleted file mode 100644 index dadf8bf08b1..00000000000 --- a/cabal-install-solver/src/Distribution/Solver/Types/ConstraintSource.hs +++ /dev/null @@ -1,78 +0,0 @@ -{-# LANGUAGE DeriveGeneric #-} -module Distribution.Solver.Types.ConstraintSource - ( ConstraintSource(..) - , showConstraintSource - ) where - -import Distribution.Solver.Compat.Prelude -import Prelude () - --- | Source of a 'PackageConstraint'. -data ConstraintSource = - - -- | Main config file, which is ~/.cabal/config by default. - ConstraintSourceMainConfig FilePath - - -- | Local cabal.project file - | ConstraintSourceProjectConfig FilePath - - -- | User config file, which is ./cabal.config by default. - | ConstraintSourceUserConfig FilePath - - -- | Flag specified on the command line. - | ConstraintSourceCommandlineFlag - - -- | Target specified by the user, e.g., @cabal install package-0.1.0.0@ - -- implies @package==0.1.0.0@. - | ConstraintSourceUserTarget - - -- | Internal requirement to use installed versions of packages like ghc-prim. - | ConstraintSourceNonReinstallablePackage - - -- | Internal constraint used by @cabal freeze@. - | ConstraintSourceFreeze - - -- | Constraint specified by a config file, a command line flag, or a user - -- target, when a more specific source is not known. - | ConstraintSourceConfigFlagOrTarget - - -- | Constraint introduced by --enable-multi-repl, which requires features - -- from Cabal >= 3.11 - | ConstraintSourceMultiRepl - - -- | The source of the constraint is not specified. - | ConstraintSourceUnknown - - -- | An internal constraint due to compatibility issues with the Setup.hs - -- command line interface requires a minimum lower bound on Cabal - | ConstraintSetupCabalMinVersion - - -- | An internal constraint due to compatibility issues with the Setup.hs - -- command line interface requires a maximum upper bound on Cabal - | ConstraintSetupCabalMaxVersion - deriving (Eq, Show, Generic) - -instance Binary ConstraintSource -instance Structured ConstraintSource - --- | Description of a 'ConstraintSource'. -showConstraintSource :: ConstraintSource -> String -showConstraintSource (ConstraintSourceMainConfig path) = - "main config " ++ path -showConstraintSource (ConstraintSourceProjectConfig path) = - "project config " ++ path -showConstraintSource (ConstraintSourceUserConfig path)= "user config " ++ path -showConstraintSource ConstraintSourceCommandlineFlag = "command line flag" -showConstraintSource ConstraintSourceUserTarget = "user target" -showConstraintSource ConstraintSourceNonReinstallablePackage = - "non-reinstallable package" -showConstraintSource ConstraintSourceFreeze = "cabal freeze" -showConstraintSource ConstraintSourceConfigFlagOrTarget = - "config file, command line flag, or user target" -showConstraintSource ConstraintSourceMultiRepl = - "--enable-multi-repl" -showConstraintSource ConstraintSourceUnknown = "unknown source" -showConstraintSource ConstraintSetupCabalMinVersion = - "minimum version of Cabal used by Setup.hs" -showConstraintSource ConstraintSetupCabalMaxVersion = - "maximum version of Cabal used by Setup.hs" diff --git a/cabal-install-solver/src/Distribution/Solver/Types/DependencyResolver.hs b/cabal-install-solver/src/Distribution/Solver/Types/DependencyResolver.hs index e773492ae74..d0a2b192239 100644 --- a/cabal-install-solver/src/Distribution/Solver/Types/DependencyResolver.hs +++ b/cabal-install-solver/src/Distribution/Solver/Types/DependencyResolver.hs @@ -1,6 +1,6 @@ module Distribution.Solver.Types.DependencyResolver - ( DependencyResolver - ) where + ( DependencyResolver + ) where import Distribution.Solver.Compat.Prelude import Prelude () @@ -26,12 +26,12 @@ import Distribution.System ( Platform ) -- solving the package dependency problem and we want to make it easy to swap -- in alternatives. -- -type DependencyResolver loc = Platform +type DependencyResolver loc cs = Platform -> CompilerInfo -> InstalledPackageIndex -> PackageIndex (SourcePackage loc) -> PkgConfigDb -> (PackageName -> PackagePreferences) - -> [LabeledPackageConstraint] + -> [LabeledPackageConstraint cs] -> Set PackageName -> Progress String String [ResolverPackage loc] diff --git a/cabal-install-solver/src/Distribution/Solver/Types/LabeledPackageConstraint.hs b/cabal-install-solver/src/Distribution/Solver/Types/LabeledPackageConstraint.hs index 8715e46fd22..3309c325cc0 100644 --- a/cabal-install-solver/src/Distribution/Solver/Types/LabeledPackageConstraint.hs +++ b/cabal-install-solver/src/Distribution/Solver/Types/LabeledPackageConstraint.hs @@ -3,12 +3,11 @@ module Distribution.Solver.Types.LabeledPackageConstraint , unlabelPackageConstraint ) where -import Distribution.Solver.Types.ConstraintSource import Distribution.Solver.Types.PackageConstraint -- | 'PackageConstraint' labeled with its source. -data LabeledPackageConstraint - = LabeledPackageConstraint PackageConstraint ConstraintSource +data LabeledPackageConstraint cs + = LabeledPackageConstraint PackageConstraint cs -unlabelPackageConstraint :: LabeledPackageConstraint -> PackageConstraint +unlabelPackageConstraint :: LabeledPackageConstraint cs -> PackageConstraint unlabelPackageConstraint (LabeledPackageConstraint pc _) = pc diff --git a/cabal-install/cabal-install.cabal b/cabal-install/cabal-install.cabal index 373152e8f64..adc658a7360 100644 --- a/cabal-install/cabal-install.cabal +++ b/cabal-install/cabal-install.cabal @@ -160,6 +160,7 @@ library Distribution.Client.ProjectConfig Distribution.Client.ProjectConfig.Legacy Distribution.Client.ProjectConfig.Types + Distribution.Client.ProjectConfig.Types.ConstraintSource Distribution.Client.ProjectFlags Distribution.Client.ProjectOrchestration Distribution.Client.ProjectPlanOutput diff --git a/cabal-install/src/Distribution/Client/CmdFreeze.hs b/cabal-install/src/Distribution/Client/CmdFreeze.hs index 85c7eb137e2..91452b0655f 100644 --- a/cabal-install/src/Distribution/Client/CmdFreeze.hs +++ b/cabal-install/src/Distribution/Client/CmdFreeze.hs @@ -32,9 +32,6 @@ import Distribution.Client.Targets , UserConstraintScope (..) , UserQualifier (..) ) -import Distribution.Solver.Types.ConstraintSource - ( ConstraintSource (..) - ) import Distribution.Solver.Types.PackageConstraint ( PackageProperty (..) ) @@ -71,6 +68,9 @@ import Distribution.Version import qualified Data.Map as Map import Distribution.Client.Errors +import Distribution.Client.ProjectConfig.Types.ConstraintSource + ( ConstraintSource (..) + ) import Distribution.Simple.Command ( CommandUI (..) , usageAlternatives diff --git a/cabal-install/src/Distribution/Client/CmdRepl.hs b/cabal-install/src/Distribution/Client/CmdRepl.hs index e243eb82974..44483200639 100644 --- a/cabal-install/src/Distribution/Client/CmdRepl.hs +++ b/cabal-install/src/Distribution/Client/CmdRepl.hs @@ -111,9 +111,6 @@ import Distribution.Simple.Utils , withTempDirectoryEx , wrapText ) -import Distribution.Solver.Types.ConstraintSource - ( ConstraintSource (ConstraintSourceMultiRepl) - ) import Distribution.Solver.Types.PackageConstraint ( PackageProperty (PackagePropertyVersion) ) @@ -168,6 +165,9 @@ import Distribution.Client.ProjectConfig ( ProjectConfig (projectConfigShared) , ProjectConfigShared (projectConfigConstraints, projectConfigMultiRepl) ) +import Distribution.Client.ProjectConfig.Types.ConstraintSource + ( ConstraintSource (..) + ) import Distribution.Client.ReplFlags ( EnvFlags (envIncludeTransitive, envPackages) , ReplFlags (..) diff --git a/cabal-install/src/Distribution/Client/Config.hs b/cabal-install/src/Distribution/Client/Config.hs index 0fe93081bd7..841fd781156 100644 --- a/cabal-install/src/Distribution/Client/Config.hs +++ b/cabal-install/src/Distribution/Client/Config.hs @@ -118,6 +118,7 @@ import Distribution.Client.ParseUtils , ppFields , ppSection ) +import Distribution.Client.ProjectConfig.Types.ConstraintSource (ConstraintSource (..)) import Distribution.Client.ProjectFlags (ProjectFlags (..)) import Distribution.Client.ReplFlags import Distribution.Client.Version @@ -202,7 +203,6 @@ import Distribution.Simple.Utils , toUTF8BS , warn ) -import Distribution.Solver.Types.ConstraintSource import Distribution.Verbosity ( normal ) diff --git a/cabal-install/src/Distribution/Client/Configure.hs b/cabal-install/src/Distribution/Client/Configure.hs index b01681d9727..62d0ad812e1 100644 --- a/cabal-install/src/Distribution/Client/Configure.hs +++ b/cabal-install/src/Distribution/Client/Configure.hs @@ -59,7 +59,6 @@ import Distribution.Client.Targets import Distribution.Client.Types as Source import qualified Distribution.Solver.Types.ComponentDeps as CD -import Distribution.Solver.Types.ConstraintSource import Distribution.Solver.Types.LabeledPackageConstraint import Distribution.Solver.Types.OptionalStanza import Distribution.Solver.Types.PackageIndex @@ -129,6 +128,10 @@ import Distribution.Version ) import Distribution.Client.Errors +import Distribution.Client.ProjectConfig.Types.ConstraintSource + ( ConstraintSource (..) + , showConstraintSource + ) import System.FilePath (()) -- | Choose the Cabal version such that the setup scripts compiled against this diff --git a/cabal-install/src/Distribution/Client/Dependency.hs b/cabal-install/src/Distribution/Client/Dependency.hs index 37e0cbdf1ee..50ac8aa663e 100644 --- a/cabal-install/src/Distribution/Client/Dependency.hs +++ b/cabal-install/src/Distribution/Client/Dependency.hs @@ -133,7 +133,6 @@ import Distribution.Version import Distribution.Solver.Types.ComponentDeps (ComponentDeps) import qualified Distribution.Solver.Types.ComponentDeps as CD -import Distribution.Solver.Types.ConstraintSource import Distribution.Solver.Types.DependencyResolver import Distribution.Solver.Types.InstalledPreference as Preference import Distribution.Solver.Types.LabeledPackageConstraint @@ -150,6 +149,7 @@ import Distribution.Solver.Types.SolverId import Distribution.Solver.Types.SolverPackage import Distribution.Solver.Types.SourcePackage import Distribution.Solver.Types.Variable +import Distribution.Client.ProjectConfig.Types.ConstraintSource (ConstraintSource (..), showConstraintSource) import Control.Exception ( assert @@ -171,7 +171,7 @@ import qualified Data.Set as Set -- implemented in terms of adjustments to the parameters. data DepResolverParams = DepResolverParams { depResolverTargets :: Set PackageName - , depResolverConstraints :: [LabeledPackageConstraint] + , depResolverConstraints :: [LabeledPackageConstraint ConstraintSource] , depResolverPreferences :: [PackagePreference] , depResolverPreferenceDefault :: PackagesPreferenceDefault , depResolverInstalledPkgIndex :: InstalledPackageIndex @@ -241,7 +241,7 @@ showDepResolverParams p = show (depResolverMaxBackjumps p) where - showLabeledConstraint :: LabeledPackageConstraint -> String + showLabeledConstraint :: LabeledPackageConstraint ConstraintSource -> String showLabeledConstraint (LabeledPackageConstraint pc src) = showPackageConstraint pc ++ " (" ++ showConstraintSource src ++ ")" @@ -308,7 +308,7 @@ addTargets extraTargets params = } addConstraints - :: [LabeledPackageConstraint] + :: [LabeledPackageConstraint ConstraintSource] -> DepResolverParams -> DepResolverParams addConstraints extraConstraints params = @@ -752,7 +752,7 @@ standardInstallPolicy installedPkgIndex sourcePkgDb pkgSpecifiers = -- ------------------------------------------------------------ -runSolver :: SolverConfig -> DependencyResolver UnresolvedPkgLoc +runSolver :: SolverConfig -> DependencyResolver UnresolvedPkgLoc ConstraintSource runSolver = modularResolver -- | Run the dependency solver. diff --git a/cabal-install/src/Distribution/Client/Fetch.hs b/cabal-install/src/Distribution/Client/Fetch.hs index 54db5ae607b..db6fedd9966 100644 --- a/cabal-install/src/Distribution/Client/Fetch.hs +++ b/cabal-install/src/Distribution/Client/Fetch.hs @@ -32,7 +32,6 @@ import qualified Distribution.Client.SolverInstallPlan as SolverInstallPlan import Distribution.Client.Targets import Distribution.Client.Types -import Distribution.Solver.Types.ConstraintSource import Distribution.Solver.Types.LabeledPackageConstraint import Distribution.Solver.Types.OptionalStanza import Distribution.Solver.Types.PkgConfigDb (PkgConfigDb, readPkgConfigDb) @@ -40,6 +39,7 @@ import Distribution.Solver.Types.SolverPackage import Distribution.Solver.Types.SourcePackage import Distribution.Client.Errors +import Distribution.Client.ProjectConfig.Types.ConstraintSource (ConstraintSource (ConstraintSourceConfigFlagOrTarget)) import Distribution.Package ( packageId ) diff --git a/cabal-install/src/Distribution/Client/Freeze.hs b/cabal-install/src/Distribution/Client/Freeze.hs index 9bc4e3234b5..6924624899a 100644 --- a/cabal-install/src/Distribution/Client/Freeze.hs +++ b/cabal-install/src/Distribution/Client/Freeze.hs @@ -47,13 +47,13 @@ import qualified Distribution.Client.SolverInstallPlan as SolverInstallPlan import Distribution.Client.Targets import Distribution.Client.Types -import Distribution.Solver.Types.ConstraintSource import Distribution.Solver.Types.LabeledPackageConstraint import Distribution.Solver.Types.OptionalStanza import Distribution.Solver.Types.PkgConfigDb import Distribution.Solver.Types.SolverId import Distribution.Client.Errors +import Distribution.Client.ProjectConfig.Types.ConstraintSource import Distribution.Package ( Package , packageId diff --git a/cabal-install/src/Distribution/Client/Install.hs b/cabal-install/src/Distribution/Client/Install.hs index e1f855cdafe..f7a89b81b59 100644 --- a/cabal-install/src/Distribution/Client/Install.hs +++ b/cabal-install/src/Distribution/Client/Install.hs @@ -130,7 +130,6 @@ import qualified Distribution.InstalledPackageInfo as Installed import Distribution.Solver.Types.PackageFixedDeps import qualified Distribution.Solver.Types.ComponentDeps as CD -import Distribution.Solver.Types.ConstraintSource import Distribution.Solver.Types.LabeledPackageConstraint import Distribution.Solver.Types.OptionalStanza import qualified Distribution.Solver.Types.PackageIndex as SourcePackageIndex @@ -267,6 +266,7 @@ import Distribution.Version import qualified Data.ByteString as BS import Distribution.Client.Errors +import Distribution.Client.ProjectConfig.Types.ConstraintSource (ConstraintSource (ConstraintSourceConfigFlagOrTarget)) -- TODO: diff --git a/cabal-install/src/Distribution/Client/NixStyleOptions.hs b/cabal-install/src/Distribution/Client/NixStyleOptions.hs index 7a047774b2b..9e6bf5edf98 100644 --- a/cabal-install/src/Distribution/Client/NixStyleOptions.hs +++ b/cabal-install/src/Distribution/Client/NixStyleOptions.hs @@ -15,8 +15,8 @@ import Prelude () import Distribution.Simple.Command (OptionField (..), ShowOrParseArgs) import Distribution.Simple.Setup (BenchmarkFlags, HaddockFlags, TestFlags) -import Distribution.Solver.Types.ConstraintSource (ConstraintSource (..)) +import Distribution.Client.ProjectConfig.Types.ConstraintSource (ConstraintSource (..)) import Distribution.Client.ProjectFlags ( ProjectFlags (..) , defaultProjectFlags diff --git a/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs b/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs index d949437f5d6..4500373460d 100644 --- a/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs +++ b/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs @@ -54,8 +54,6 @@ import Distribution.Client.CmdInstall.ClientInstallFlags import Distribution.Compat.Lens (toListOf, view) -import Distribution.Solver.Types.ConstraintSource - import Distribution.Client.NixStyleOptions (NixStyleFlags (..)) import Distribution.Client.ProjectFlags (ProjectFlags (..), defaultProjectFlags, projectFlagsOptions) import Distribution.Client.Setup @@ -182,6 +180,7 @@ import Network.URI (URI (..), parseURI) import Distribution.Fields.ConfVar (parseConditionConfVarFromClause) import Distribution.Client.HttpUtils +import Distribution.Client.ProjectConfig.Types.ConstraintSource (ConstraintSource (..)) import Distribution.Client.ReplFlags (multiReplOption) import System.Directory (createDirectoryIfMissing) import System.FilePath (isAbsolute, isPathSeparator, makeValid, takeDirectory, ()) diff --git a/cabal-install/src/Distribution/Client/ProjectConfig/Types.hs b/cabal-install/src/Distribution/Client/ProjectConfig/Types.hs index 744a50ddc37..644dddc804a 100644 --- a/cabal-install/src/Distribution/Client/ProjectConfig/Types.hs +++ b/cabal-install/src/Distribution/Client/ProjectConfig/Types.hs @@ -51,7 +51,7 @@ import Distribution.Client.CmdInstall.ClientInstallFlags ( ClientInstallFlags (..) ) -import Distribution.Solver.Types.ConstraintSource +import Distribution.Client.ProjectConfig.Types.ConstraintSource (ConstraintSource) import Distribution.Solver.Types.Settings import Distribution.Package diff --git a/cabal-install/src/Distribution/Client/ProjectConfig/Types/ConstraintSource.hs b/cabal-install/src/Distribution/Client/ProjectConfig/Types/ConstraintSource.hs new file mode 100644 index 00000000000..20f6dce400e --- /dev/null +++ b/cabal-install/src/Distribution/Client/ProjectConfig/Types/ConstraintSource.hs @@ -0,0 +1,64 @@ +{-# LANGUAGE DeriveGeneric #-} + +module Distribution.Client.ProjectConfig.Types.ConstraintSource where + +import Distribution.Client.Compat.Prelude +import Prelude () + +-- | Source of a 'PackageConstraint'. +data ConstraintSource + = -- | Main config file, which is ~/.cabal/config by default. + ConstraintSourceMainConfig FilePath + | -- | Local cabal.project file + ConstraintSourceProjectConfig FilePath + | -- | User config file, which is ./cabal.config by default. + ConstraintSourceUserConfig FilePath + | -- | Flag specified on the command line. + ConstraintSourceCommandlineFlag + | -- | Target specified by the user, e.g., @cabal install package-0.1.0.0@ + -- implies @package==0.1.0.0@. + ConstraintSourceUserTarget + | -- | Internal requirement to use installed versions of packages like ghc-prim. + ConstraintSourceNonReinstallablePackage + | -- | Internal constraint used by @cabal freeze@. + ConstraintSourceFreeze + | -- | Constraint specified by a config file, a command line flag, or a user + -- target, when a more specific source is not known. + ConstraintSourceConfigFlagOrTarget + | -- | Constraint introduced by --enable-multi-repl, which requires features + -- from Cabal >= 3.11 + ConstraintSourceMultiRepl + | -- | The source of the constraint is not specified. + ConstraintSourceUnknown + | -- | An internal constraint due to compatibility issues with the Setup.hs + -- command line interface requires a minimum lower bound on Cabal + ConstraintSetupCabalMinVersion + | -- | An internal constraint due to compatibility issues with the Setup.hs + -- command line interface requires a maximum upper bound on Cabal + ConstraintSetupCabalMaxVersion + deriving (Eq, Show, Generic) + +instance Binary ConstraintSource +instance Structured ConstraintSource + +-- | Description of a 'ConstraintSource'. +showConstraintSource :: ConstraintSource -> String +showConstraintSource (ConstraintSourceMainConfig path) = + "main config " ++ path +showConstraintSource (ConstraintSourceProjectConfig path) = + "project config " ++ path +showConstraintSource (ConstraintSourceUserConfig path) = "user config " ++ path +showConstraintSource ConstraintSourceCommandlineFlag = "command line flag" +showConstraintSource ConstraintSourceUserTarget = "user target" +showConstraintSource ConstraintSourceNonReinstallablePackage = + "non-reinstallable package" +showConstraintSource ConstraintSourceFreeze = "cabal freeze" +showConstraintSource ConstraintSourceConfigFlagOrTarget = + "config file, command line flag, or user target" +showConstraintSource ConstraintSourceMultiRepl = + "--enable-multi-repl" +showConstraintSource ConstraintSourceUnknown = "unknown source" +showConstraintSource ConstraintSetupCabalMinVersion = + "minimum version of Cabal used by Setup.hs" +showConstraintSource ConstraintSetupCabalMaxVersion = + "maximum version of Cabal used by Setup.hs" diff --git a/cabal-install/src/Distribution/Client/ProjectPlanning.hs b/cabal-install/src/Distribution/Client/ProjectPlanning.hs index 9fd24b45ccc..7b2bd411071 100644 --- a/cabal-install/src/Distribution/Client/ProjectPlanning.hs +++ b/cabal-install/src/Distribution/Client/ProjectPlanning.hs @@ -138,7 +138,6 @@ import Distribution.Utils.NubList import qualified Hackage.Security.Client as Sec -import Distribution.Solver.Types.ConstraintSource import Distribution.Solver.Types.InstSolverPackage import Distribution.Solver.Types.LabeledPackageConstraint import Distribution.Solver.Types.OptionalStanza @@ -208,6 +207,7 @@ import qualified Data.List.NonEmpty as NE import qualified Data.Map as Map import qualified Data.Set as Set import Distribution.Client.Errors +import Distribution.Client.ProjectConfig.Types.ConstraintSource (ConstraintSource (..)) import System.FilePath import Text.PrettyPrint (colon, comma, fsep, hang, punctuate, quotes, text, vcat, ($$)) import qualified Text.PrettyPrint as Disp diff --git a/cabal-install/src/Distribution/Client/Sandbox/PackageEnvironment.hs b/cabal-install/src/Distribution/Client/Sandbox/PackageEnvironment.hs index 3033356493f..42fac7de7a3 100644 --- a/cabal-install/src/Distribution/Client/Sandbox/PackageEnvironment.hs +++ b/cabal-install/src/Distribution/Client/Sandbox/PackageEnvironment.hs @@ -58,7 +58,7 @@ import Distribution.Simple.Setup , HaddockFlags (..) ) import Distribution.Simple.Utils (debug, warn) -import Distribution.Solver.Types.ConstraintSource +import Distribution.Client.ProjectConfig.Types.ConstraintSource (ConstraintSource (..)) import System.Directory (doesFileExist) import System.FilePath (()) import System.IO.Error (isDoesNotExistError) diff --git a/cabal-install/src/Distribution/Client/Setup.hs b/cabal-install/src/Distribution/Client/Setup.hs index 85cc7665647..8cab586629e 100644 --- a/cabal-install/src/Distribution/Client/Setup.hs +++ b/cabal-install/src/Distribution/Client/Setup.hs @@ -129,7 +129,6 @@ import Distribution.Utils.NubList , toNubList ) -import Distribution.Solver.Types.ConstraintSource import Distribution.Solver.Types.Settings import Distribution.Client.GlobalFlags @@ -139,6 +138,7 @@ import Distribution.Client.GlobalFlags , withRepoContext ) import Distribution.Client.ManpageFlags (ManpageFlags, defaultManpageFlags, manpageOptions) +import Distribution.Client.ProjectConfig.Types.ConstraintSource (ConstraintSource (..)) import qualified Distribution.Compat.CharParsing as P import Distribution.FieldGrammar.Newtypes (SpecVersion (..)) import Distribution.PackageDescription diff --git a/cabal-install/src/Distribution/Client/Types/PackageSpecifier.hs b/cabal-install/src/Distribution/Client/Types/PackageSpecifier.hs index 5f25be4aa77..67c6877827a 100644 --- a/cabal-install/src/Distribution/Client/Types/PackageSpecifier.hs +++ b/cabal-install/src/Distribution/Client/Types/PackageSpecifier.hs @@ -14,7 +14,7 @@ import Distribution.Package (Package (..), packageName, packageVersion) import Distribution.Types.PackageName (PackageName) import Distribution.Version (thisVersion) -import Distribution.Solver.Types.ConstraintSource +import Distribution.Client.ProjectConfig.Types.ConstraintSource import Distribution.Solver.Types.LabeledPackageConstraint import Distribution.Solver.Types.PackageConstraint @@ -39,7 +39,7 @@ pkgSpecifierTarget (SpecificSourcePackage pkg) = packageName pkg pkgSpecifierConstraints :: Package pkg => PackageSpecifier pkg - -> [LabeledPackageConstraint] + -> [LabeledPackageConstraint ConstraintSource] pkgSpecifierConstraints (NamedPackage name props) = map toLpc props where toLpc prop =