diff --git a/cabal-install-solver/src/Distribution/Solver/Modular.hs b/cabal-install-solver/src/Distribution/Solver/Modular.hs index 2aac240318f..da453f35709 100644 --- a/cabal-install-solver/src/Distribution/Solver/Modular.hs +++ b/cabal-install-solver/src/Distribution/Solver/Modular.hs @@ -16,6 +16,7 @@ import Prelude () import Distribution.Solver.Compat.Prelude import qualified Data.Map as M +import qualified Data.List as L import Data.Set (isSubsetOf) import Distribution.Compat.Graph ( IsNode(..) ) @@ -66,7 +67,9 @@ modularResolver sc (Platform arch os) cinfo iidx sidx pkgConfigDB pprefs pcs pns -- Indices have to be converted into solver-specific uniform index. idx = convPIs os arch cinfo gcs (shadowPkgs sc) (strongFlags sc) (solveExecutables sc) iidx sidx -- Constraints have to be converted into a finite map indexed by PN. - gcs = M.fromListWith (++) (map pair pcs) + -- Preserve the order of the constraints, countering fromListWith + -- reversing the order by using flip (++). + gcs = M.fromListWith (flip (++)) (map pair pcs) where pair lpc = (pcName $ unlabelPackageConstraint lpc, [lpc]) @@ -122,23 +125,33 @@ solve' :: SolverConfig -> Set PN -> Progress String String (Assignment, RevDepMap) solve' sc cinfo idx pkgConfigDB pprefs gcs pns = - toProgress $ retry (runSolver printFullLog sc) createErrorMsg + toProgress $ + let gcs' = versionWin (solverVersionWin sc) <$> gcs + diff = concat (M.elems gcs) L.\\ concat (M.elems gcs') + msg = + if null diff then "Overriding doesn't remove any constraints." else + "Overriding constraints by " + ++ showVersionWin (solverVersionWin sc) ++ " removes these " ++ show (length diff) ++ " constraints:" + ++ showGroupedConstraints diff + in + continueWith msg $ + retry (runSolver printFullLog gcs' sc) createErrorMsg where - runSolver :: Bool -> SolverConfig + runSolver :: Bool -> Map PN [LabeledPackageConstraint] -> SolverConfig -> RetryLog String SolverFailure (Assignment, RevDepMap) - runSolver keepLog sc' = + runSolver keepLog gcs' sc' = displayLogMessages keepLog $ - solve sc' cinfo idx pkgConfigDB pprefs gcs pns + solve sc' cinfo idx pkgConfigDB pprefs gcs' pns createErrorMsg :: SolverFailure -> RetryLog String String (Assignment, RevDepMap) createErrorMsg failure@(ExhaustiveSearch cs cm) = - if asBool $ minimizeConflictSet sc + if asBool (minimizeConflictSet sc) then continueWith ("Found no solution after exhaustively searching the " ++ "dependency tree. Rerunning the dependency solver " ++ "to minimize the conflict set ({" ++ showConflictSet cs ++ "}).") $ - retry (tryToMinimizeConflictSet (runSolver printFullLog) sc cs cm) $ + retry (tryToMinimizeConflictSet (runSolver printFullLog gcs) sc cs cm) $ \case ExhaustiveSearch cs' cm' -> fromProgress $ Fail $ @@ -151,14 +164,16 @@ solve' sc cinfo idx pkgConfigDB pprefs gcs pns = ++ "Original error message:\n" ++ rerunSolverForErrorMsg cs ++ finalErrorMsg sc failure + else fromProgress $ Fail $ rerunSolverForErrorMsg cs ++ finalErrorMsg sc failure + createErrorMsg failure@BackjumpLimitReached = continueWith ("Backjump limit reached. Rerunning dependency solver to generate " ++ "a final conflict set for the search tree containing the " ++ "first backjump.") $ - retry (runSolver printFullLog sc { pruneAfterFirstSuccess = PruneAfterFirstSuccess True }) $ + retry (runSolver printFullLog gcs sc { pruneAfterFirstSuccess = PruneAfterFirstSuccess True }) $ \case ExhaustiveSearch cs _ -> fromProgress $ Fail $ @@ -181,7 +196,7 @@ solve' sc cinfo idx pkgConfigDB pprefs gcs pns = -- original goal order. goalOrder' = preferGoalsFromConflictSet cs <> fromMaybe mempty (goalOrder sc) - in unlines ("Could not resolve dependencies:" : messages (toProgress (runSolver True sc'))) + in unlines ("Could not resolve dependencies:" : messages (toProgress (runSolver True gcs sc'))) printFullLog = solverVerbosity sc >= verbose diff --git a/cabal-install-solver/src/Distribution/Solver/Modular/Solver.hs b/cabal-install-solver/src/Distribution/Solver/Modular/Solver.hs index 39bd7bf4690..e00e3ddcea9 100644 --- a/cabal-install-solver/src/Distribution/Solver/Modular/Solver.hs +++ b/cabal-install-solver/src/Distribution/Solver/Modular/Solver.hs @@ -67,6 +67,7 @@ data SolverConfig = SolverConfig { shadowPkgs :: ShadowPkgs, strongFlags :: StrongFlags, onlyConstrained :: OnlyConstrained, + solverVersionWin :: VersionWin, maxBackjumps :: Maybe Int, enableBackjumping :: EnableBackjumping, solveExecutables :: SolveExecutables, diff --git a/cabal-install-solver/src/Distribution/Solver/Types/ConstraintSource.hs b/cabal-install-solver/src/Distribution/Solver/Types/ConstraintSource.hs index dadf8bf08b1..9b60d748023 100644 --- a/cabal-install-solver/src/Distribution/Solver/Types/ConstraintSource.hs +++ b/cabal-install-solver/src/Distribution/Solver/Types/ConstraintSource.hs @@ -1,12 +1,26 @@ {-# LANGUAGE DeriveGeneric #-} module Distribution.Solver.Types.ConstraintSource ( ConstraintSource(..) + , ProjectConfigImport(..) , showConstraintSource ) where import Distribution.Solver.Compat.Prelude import Prelude () +data ProjectConfigImport = + ProjectConfigImport + { importDepth :: Int + -- ^ Depth of the import. The main project config file has depth 0, and each + -- import increases the depth by 1. + , importPath :: FilePath + -- ^ Path to the imported file contributing to the project config. + } + deriving (Eq, Show, Generic) + +instance Binary ProjectConfigImport +instance Structured ProjectConfigImport + -- | Source of a 'PackageConstraint'. data ConstraintSource = @@ -14,7 +28,7 @@ data ConstraintSource = ConstraintSourceMainConfig FilePath -- | Local cabal.project file - | ConstraintSourceProjectConfig FilePath + | ConstraintSourceProjectConfig ProjectConfigImport -- | User config file, which is ./cabal.config by default. | ConstraintSourceUserConfig FilePath @@ -59,8 +73,8 @@ instance Structured ConstraintSource showConstraintSource :: ConstraintSource -> String showConstraintSource (ConstraintSourceMainConfig path) = "main config " ++ path -showConstraintSource (ConstraintSourceProjectConfig path) = - "project config " ++ path +showConstraintSource (ConstraintSourceProjectConfig projectConfig) = + "project config " ++ show projectConfig showConstraintSource (ConstraintSourceUserConfig path)= "user config " ++ path showConstraintSource ConstraintSourceCommandlineFlag = "command line flag" showConstraintSource ConstraintSourceUserTarget = "user target" diff --git a/cabal-install-solver/src/Distribution/Solver/Types/LabeledPackageConstraint.hs b/cabal-install-solver/src/Distribution/Solver/Types/LabeledPackageConstraint.hs index 8715e46fd22..c6ce8511f8e 100644 --- a/cabal-install-solver/src/Distribution/Solver/Types/LabeledPackageConstraint.hs +++ b/cabal-install-solver/src/Distribution/Solver/Types/LabeledPackageConstraint.hs @@ -1,14 +1,185 @@ +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE PartialTypeSignatures #-} +{-# LANGUAGE TupleSections #-} +{-# LANGUAGE ViewPatterns #-} + module Distribution.Solver.Types.LabeledPackageConstraint ( LabeledPackageConstraint(..) + , VersionWin (..) , unlabelPackageConstraint + , versionWin + , showVersionWin + , showGroupedConstraints + , showLabeledConstraint + , showLabeledConstraints ) where +import Distribution.Compat.Prelude +import Prelude () import Distribution.Solver.Types.ConstraintSource import Distribution.Solver.Types.PackageConstraint +import Distribution.Pretty ( Pretty(pretty) ) +import Distribution.Parsec ( Parsec(parsec) ) + +import qualified Distribution.Compat.CharParsing as P +import qualified Text.PrettyPrint as PP +import Distribution.Types.VersionRange +import qualified Data.Map.Strict as Map +import qualified Data.List as L (elemIndex, groupBy) + +data VersionWin = ShallowWins | LastWins deriving (Eq, Generic) + +instance Binary VersionWin +instance Structured VersionWin + +instance Show VersionWin where + show = showVersionWin + +versionWin :: VersionWin -> [LabeledPackageConstraint] -> [LabeledPackageConstraint] +versionWin ShallowWins = shallowConstraintsWin +versionWin LastWins = laterConstraintsWin + +showVersionWin :: VersionWin -> String +showVersionWin ShallowWins = "shallow wins" +showVersionWin LastWins = "last wins" + +instance Pretty VersionWin where + pretty ShallowWins = PP.text "shallowest" + pretty LastWins = PP.text "latest" + +instance Parsec VersionWin where + parsec = P.choice + [ P.string "latest" >> return LastWins + , P.string "shallowest" >> return ShallowWins + ] -- | 'PackageConstraint' labeled with its source. data LabeledPackageConstraint = LabeledPackageConstraint PackageConstraint ConstraintSource + deriving Eq unlabelPackageConstraint :: LabeledPackageConstraint -> PackageConstraint unlabelPackageConstraint (LabeledPackageConstraint pc _) = pc + +unscopePackageConstraint :: PackageConstraint -> ConstraintScope +unscopePackageConstraint (PackageConstraint scope _) = scope + +showLabeledConstraint :: LabeledPackageConstraint -> String +showLabeledConstraint (LabeledPackageConstraint pc src) = + showPackageConstraint pc ++ " (" ++ showConstraintSource src ++ ")" + +showLabeledConstraints :: [LabeledPackageConstraint] -> String +showLabeledConstraints = concatMap (("\n " ++) . showLabeledConstraint) + +showGroupedConstraints :: [LabeledPackageConstraint] -> String +showGroupedConstraints xs = concat + [ concatMap (("\n " ++) . showLabeledConstraint) vs + | (_, vs) <- groupConstraints xs + ] + +groupConstraints :: [LabeledPackageConstraint] -> [(String, [LabeledPackageConstraint])] +groupConstraints xs = + let toKeyValues :: [(String, LabeledPackageConstraint)] -> (String, [LabeledPackageConstraint]) + toKeyValues kvs = (case kvs of (s, _) : _ -> (s,); [] -> ("",)) $ snd <$> kvs + in + toKeyValues <$> L.groupBy (\x y -> EQ == (comparing fst) x y) + [ (show . unscopePackageConstraint $ unlabelPackageConstraint x, x) + | x <- xs + ] + +-- | Later constraints win over earlier constraints. Preserves the original +-- order of the input constraints in the output constraints. +laterConstraintsWin :: [LabeledPackageConstraint] -> [LabeledPackageConstraint] +laterConstraintsWin [] = [] +laterConstraintsWin lpcs@[_] = lpcs +laterConstraintsWin lpcsIn = + let keepers = + (\(xs, (us, ys)) -> weedByOrder (weedByUser us xs) ++ us ++ ys) + . fmap (partition isUserVersionEquality) + $ partition (\c -> isProjectVersionInstalled c || isProjectVersionEquality c) lpcsIn + + in snd <$> sortBy (comparing fst) [(fromMaybe (negate 1) (L.elemIndex k lpcsIn), k) | k <- keepers] + +-- | Weed out potential package version conflicts for each package by picking +-- any user targets to win if they exist. Otherwise pick version equality +-- constraints with the lowest import depth to win. Discard the rest of the +-- version equality and installed constraints. Constraints for flags and +-- stanzas are untouched by this weeding. +-- +-- Flags that may have applied to weeded versions of a package may be orphaned. +shallowConstraintsWin :: [LabeledPackageConstraint] -> [LabeledPackageConstraint] +shallowConstraintsWin = + (\(xs, (us, ys)) -> + let xsGrouped = groupConstraints xs + xsWeeded = (weedByDepth . weedByUser us . sortByImportDepth) <$> Map.fromList xsGrouped + in concat (Map.elems xsWeeded) ++ us ++ ys + ) + . fmap (partition isUserVersionEquality) + . partition (\c -> isProjectVersionInstalled c || isProjectVersionEquality c) + +isUserVersionEquality :: LabeledPackageConstraint -> Bool +isUserVersionEquality (LabeledPackageConstraint constraint source) + | ConstraintSourceUserTarget{} <- source + , PackageConstraint _ (PackagePropertyVersion versionRange) <- constraint + , ThisVersionF _ <- projectVersionRange versionRange = True + | otherwise = False + +isProjectVersionEquality :: LabeledPackageConstraint -> Bool +isProjectVersionEquality (LabeledPackageConstraint constraint source) + | ConstraintSourceProjectConfig{} <- source + , PackageConstraint _ (PackagePropertyVersion versionRange) <- constraint + , ThisVersionF _ <- projectVersionRange versionRange = True + | otherwise = False + +isProjectVersionInstalled :: LabeledPackageConstraint -> Bool +isProjectVersionInstalled (LabeledPackageConstraint constraint source) + | ConstraintSourceProjectConfig{} <- source + , PackageConstraint _ PackagePropertyInstalled <- constraint = True + | otherwise = False + +-- | Sort by import depth, ascending. +sortByImportDepth :: [LabeledPackageConstraint] -> [LabeledPackageConstraint] +sortByImportDepth = sortBy (comparing (\(LabeledPackageConstraint _ src) -> case src of + ConstraintSourceProjectConfig pci -> importDepth pci + _ -> maxBound)) + +-- | Weed out any conflicts by picking user constraints over project +-- constraints. +weedByUser :: [LabeledPackageConstraint] -> [LabeledPackageConstraint] -> [LabeledPackageConstraint] +weedByUser us xs = case us of + [] -> xs + (toName -> uName) : us' -> weedByUser us' $ filter (\x -> uName /= toName x) xs + where + toName = scopeToPackageName . unscopePackageConstraint . unlabelPackageConstraint + +-- | Weed out any conflicts by picking project constraints with the lowest +-- import depth, assuming the input is sorted by import depth. +weedByDepth :: [LabeledPackageConstraint] -> [LabeledPackageConstraint] +weedByDepth xs = case xs of + [] -> [] + (LabeledPackageConstraint _ srcX) : _ -> case srcX of + ConstraintSourceProjectConfig ProjectConfigImport{importDepth = dX} -> + filter + (\(LabeledPackageConstraint _ srcY) -> case srcY of + ConstraintSourceProjectConfig ProjectConfigImport{importDepth = dY} -> + dX == dY + _ -> False) + xs + _ -> xs + +-- | Weed out any conflicts by picking the last project constraints, assuming +-- the input list is in definition order. +weedByOrder :: [LabeledPackageConstraint] -> [LabeledPackageConstraint] +weedByOrder [] = [] +weedByOrder xs@[_] = xs +weedByOrder (reverse -> xs) = reverse $ go (nub $ toName <$> xs) xs where + toName = scopeToPackageName . unscopePackageConstraint . unlabelPackageConstraint + + go [] ys = ys + go (n : ns) ys = + let sameNames = filter ((== n) . toName) ys + winner = take 1 sameNames + in + go ns (winner ++ filter ((/= n) . toName) ys) \ No newline at end of file diff --git a/cabal-install/src/Distribution/Client/Config.hs b/cabal-install/src/Distribution/Client/Config.hs index 0fe93081bd7..47c7090454b 100644 --- a/cabal-install/src/Distribution/Client/Config.hs +++ b/cabal-install/src/Distribution/Client/Config.hs @@ -423,6 +423,7 @@ instance Semigroup SavedConfig where , installStrongFlags = combine installStrongFlags , installAllowBootLibInstalls = combine installAllowBootLibInstalls , installOnlyConstrained = combine installOnlyConstrained + , installVersionWin = combine installVersionWin , installReinstall = combine installReinstall , installAvoidReinstalls = combine installAvoidReinstalls , installOverrideReinstall = combine installOverrideReinstall diff --git a/cabal-install/src/Distribution/Client/Dependency.hs b/cabal-install/src/Distribution/Client/Dependency.hs index 37e0cbdf1ee..3995f04a495 100644 --- a/cabal-install/src/Distribution/Client/Dependency.hs +++ b/cabal-install/src/Distribution/Client/Dependency.hs @@ -54,6 +54,7 @@ module Distribution.Client.Dependency , setStrongFlags , setAllowBootLibInstalls , setOnlyConstrained + , setVersionWin , setMaxBackjumps , setEnableBackjumping , setSolveExecutables @@ -136,7 +137,7 @@ 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 +import Distribution.Solver.Types.LabeledPackageConstraint hiding (versionWin) import Distribution.Solver.Types.OptionalStanza import Distribution.Solver.Types.PackageConstraint import qualified Distribution.Solver.Types.PackageIndex as PackageIndex @@ -189,6 +190,7 @@ data DepResolverParams = DepResolverParams , depResolverOnlyConstrained :: OnlyConstrained -- ^ Whether to only allow explicitly constrained packages plus -- goals or to allow any package. + , depResolverVersionWin :: VersionWin , depResolverMaxBackjumps :: Maybe Int , depResolverEnableBackjumping :: EnableBackjumping , depResolverSolveExecutables :: SolveExecutables @@ -209,6 +211,8 @@ showDepResolverParams p = ++ concatMap (("\n " ++) . showLabeledConstraint) (depResolverConstraints p) + ++ "\nversion override: " + ++ showVersionWin (depResolverVersionWin p) ++ "\npreferences: " ++ concatMap (("\n " ++) . showPackagePreference) @@ -240,10 +244,6 @@ showDepResolverParams p = "infinite" show (depResolverMaxBackjumps p) - where - showLabeledConstraint :: LabeledPackageConstraint -> String - showLabeledConstraint (LabeledPackageConstraint pc src) = - showPackageConstraint pc ++ " (" ++ showConstraintSource src ++ ")" -- | A package selection preference for a particular package. -- @@ -277,6 +277,7 @@ basicDepResolverParams installedPkgIndex sourcePkgIndex = DepResolverParams { depResolverTargets = Set.empty , depResolverConstraints = [] + , depResolverVersionWin = ShallowWins , depResolverPreferences = [] , depResolverPreferenceDefault = PreferLatestForSelected , depResolverInstalledPkgIndex = installedPkgIndex @@ -398,6 +399,12 @@ setOnlyConstrained i params = { depResolverOnlyConstrained = i } +setVersionWin :: VersionWin -> DepResolverParams -> DepResolverParams +setVersionWin i params = + params + { depResolverVersionWin = i + } + setMaxBackjumps :: Maybe Int -> DepResolverParams -> DepResolverParams setMaxBackjumps n params = params @@ -780,6 +787,7 @@ resolveDependencies platform comp pkgConfigDB params = shadowing strFlags onlyConstrained_ + versionWin maxBkjumps enableBj solveExes @@ -813,6 +821,7 @@ resolveDependencies platform comp pkgConfigDB params = strFlags _allowBootLibs onlyConstrained_ + versionWin maxBkjumps enableBj solveExes @@ -1137,6 +1146,7 @@ resolveWithoutDependencies _solveExes _allowBootLibInstalls _onlyConstrained + _versionWind _order _verbosity ) = diff --git a/cabal-install/src/Distribution/Client/Fetch.hs b/cabal-install/src/Distribution/Client/Fetch.hs index 54db5ae607b..a93b8821fad 100644 --- a/cabal-install/src/Distribution/Client/Fetch.hs +++ b/cabal-install/src/Distribution/Client/Fetch.hs @@ -210,6 +210,7 @@ planPackages . setStrongFlags strongFlags . setAllowBootLibInstalls allowBootLibInstalls . setOnlyConstrained onlyConstrained + . setVersionWin (fromFlag (fetchVersionWins fetchFlags)) . setSolverVerbosity verbosity . addConstraints [ let pc = diff --git a/cabal-install/src/Distribution/Client/Freeze.hs b/cabal-install/src/Distribution/Client/Freeze.hs index 9bc4e3234b5..fdcdb0709b2 100644 --- a/cabal-install/src/Distribution/Client/Freeze.hs +++ b/cabal-install/src/Distribution/Client/Freeze.hs @@ -239,6 +239,7 @@ planPackages . setStrongFlags strongFlags . setAllowBootLibInstalls allowBootLibInstalls . setOnlyConstrained onlyConstrained + . setVersionWin (fromFlag (freezeVersionWin freezeFlags)) . setSolverVerbosity verbosity . addConstraints [ let pkg = pkgSpecifierTarget pkgSpecifier diff --git a/cabal-install/src/Distribution/Client/Install.hs b/cabal-install/src/Distribution/Client/Install.hs index e1f855cdafe..1150d11a342 100644 --- a/cabal-install/src/Distribution/Client/Install.hs +++ b/cabal-install/src/Distribution/Client/Install.hs @@ -596,6 +596,7 @@ planPackages . setStrongFlags strongFlags . setAllowBootLibInstalls allowBootLibInstalls . setOnlyConstrained onlyConstrained + . setVersionWin (fromFlag (installVersionWin installFlags)) . setSolverVerbosity verbosity . setPreferenceDefault ( if upgradeDeps diff --git a/cabal-install/src/Distribution/Client/ProjectConfig.hs b/cabal-install/src/Distribution/Client/ProjectConfig.hs index 3083f9777bf..492342d9d71 100644 --- a/cabal-install/src/Distribution/Client/ProjectConfig.hs +++ b/cabal-install/src/Distribution/Client/ProjectConfig.hs @@ -3,11 +3,13 @@ {-# LANGUAGE LambdaCase #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE TupleSections #-} -- | Handling project configuration. module Distribution.Client.ProjectConfig ( -- * Types for project config ProjectConfig (..) + , ProjectConfigToParse (..) , ProjectConfigBuildOnly (..) , ProjectConfigShared (..) , ProjectConfigProvenance (..) @@ -172,6 +174,7 @@ import Distribution.Simple.Utils , rawSystemIOWithEnv , warn ) +import Distribution.Solver.Types.LabeledPackageConstraint (VersionWin (ShallowWins)) import Distribution.System ( Platform ) @@ -223,6 +226,8 @@ import System.IO , withBinaryFile ) +import Distribution.Solver.Types.ConstraintSource (ProjectConfigImport (importPath)) + ---------------------------------------- -- Resolving configuration to settings -- @@ -330,6 +335,7 @@ resolveSolverSettings solverSettingStrongFlags = fromFlag projectConfigStrongFlags solverSettingAllowBootLibInstalls = fromFlag projectConfigAllowBootLibInstalls solverSettingOnlyConstrained = fromFlag projectConfigOnlyConstrained + solverSettingVersionWin = fromFlag projectConfigVersionWin solverSettingIndexState = flagToMaybe projectConfigIndexState solverSettingActiveRepos = flagToMaybe projectConfigActiveRepos solverSettingIndependentGoals = fromFlag projectConfigIndependentGoals @@ -355,6 +361,7 @@ resolveSolverSettings , projectConfigStrongFlags = Flag (StrongFlags False) , projectConfigAllowBootLibInstalls = Flag (AllowBootLibInstalls False) , projectConfigOnlyConstrained = Flag OnlyConstrainedNone + , projectConfigVersionWin = Flag ShallowWins , projectConfigIndependentGoals = Flag (IndependentGoals False) , projectConfigPreferOldest = Flag (PreferOldest False) -- projectConfigShadowPkgs = Flag False, @@ -748,7 +755,7 @@ readProjectFileSkeleton then do monitorFiles [monitorFileHashed extensionFile] pcs <- liftIO readExtensionFile - monitorFiles $ map monitorFileHashed (projectSkeletonImports pcs) + monitorFiles $ map monitorFileHashed (importPath <$> projectSkeletonImports pcs) pure pcs else do monitorFiles [monitorNonExistentFile extensionFile] @@ -758,7 +765,14 @@ readProjectFileSkeleton readExtensionFile = reportParseResult verbosity extensionDescription extensionFile - =<< parseProjectSkeleton distDownloadSrcDirectory httpTransport verbosity [] extensionFile + =<< ( parseProjectSkeleton + distDownloadSrcDirectory + httpTransport + verbosity + [] + extensionFile + . ProjectConfigToParse 0 + ) =<< BS.readFile extensionFile -- | Render the 'ProjectConfig' format. @@ -795,7 +809,7 @@ readGlobalConfig verbosity configFileFlag = do reportParseResult :: Verbosity -> String -> FilePath -> OldParser.ParseResult ProjectConfigSkeleton -> IO ProjectConfigSkeleton reportParseResult verbosity _filetype filename (OldParser.ParseOk warnings x) = do unless (null warnings) $ - let msg = unlines (map (OldParser.showPWarning (intercalate ", " $ filename : projectSkeletonImports x)) warnings) + let msg = unlines (map (OldParser.showPWarning (intercalate ", " $ filename : (importPath <$> projectSkeletonImports x))) warnings) in warn verbosity msg return x reportParseResult verbosity filetype filename (OldParser.ParseFailed err) = diff --git a/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs b/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs index d949437f5d6..4d2e727ac6a 100644 --- a/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs +++ b/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs @@ -3,6 +3,8 @@ {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE TupleSections #-} +{-# LANGUAGE ViewPatterns #-} -- | Project configuration, implementation in terms of legacy types. module Distribution.Client.ProjectConfig.Legacy @@ -194,8 +196,6 @@ import System.FilePath (isAbsolute, isPathSeparator, makeValid, takeDirectory, ( -- and then resolving and downloading the imports type ProjectConfigSkeleton = CondTree ConfVar [ProjectConfigImport] ProjectConfig -type ProjectConfigImport = String - singletonProjectConfigSkeleton :: ProjectConfig -> ProjectConfigSkeleton singletonProjectConfigSkeleton x = CondNode x mempty mempty @@ -226,22 +226,31 @@ instantiateProjectConfigSkeletonWithCompiler os arch impl _flags skel = go $ map projectSkeletonImports :: ProjectConfigSkeleton -> [ProjectConfigImport] projectSkeletonImports = view traverseCondTreeC -parseProjectSkeleton :: FilePath -> HttpTransport -> Verbosity -> [ProjectConfigImport] -> FilePath -> BS.ByteString -> IO (ParseResult ProjectConfigSkeleton) -parseProjectSkeleton cacheDir httpTransport verbosity seenImports source bs = (sanityWalkPCS False =<<) <$> liftPR (go []) (ParseUtils.readFields bs) +parseProjectSkeleton :: FilePath -> HttpTransport -> Verbosity -> [ProjectConfigImport] -> FilePath -> ProjectConfigToParse -> IO (ParseResult ProjectConfigSkeleton) +parseProjectSkeleton cacheDir httpTransport verbosity seenImports source ProjectConfigToParse{toParseDepth = depthInitial, toParseContents = bs} = + (sanityWalkPCS False =<<) <$> liftPR (go depthInitial []) (ParseUtils.readFields bs) where - go :: [ParseUtils.Field] -> [ParseUtils.Field] -> IO (ParseResult ProjectConfigSkeleton) - go acc (x : xs) = case x of + go :: Int -> [ParseUtils.Field] -> [ParseUtils.Field] -> IO (ParseResult ProjectConfigSkeleton) + go depth acc (x : xs) = case x of (ParseUtils.F l "import" importLoc) -> - if importLoc `elem` seenImports + if importLoc `elem` (importPath <$> seenImports) then pure . parseFail $ ParseUtils.FromString ("cyclical import of " ++ importLoc) (Just l) else do - let fs = fmap (\z -> CondNode z [importLoc] mempty) $ fieldsToConfig (reverse acc) - res <- parseProjectSkeleton cacheDir httpTransport verbosity (importLoc : seenImports) importLoc =<< fetchImportConfig importLoc - rest <- go [] xs + let depthImport = ProjectConfigImport depth importLoc + let fs = fmap (\z -> CondNode z [depthImport] mempty) $ fieldsToConfig depth (reverse acc) + res <- + fetchImportConfig depthImport + >>= ( \sourceNext -> + let depthNext = depth + 1 + imports = ProjectConfigImport depthNext importLoc : seenImports + nextConfig = ProjectConfigToParse depthNext sourceNext + in parseProjectSkeleton cacheDir httpTransport verbosity imports importLoc nextConfig + ) + rest <- go depth [] xs pure . fmap mconcat . sequence $ [fs, res, rest] (ParseUtils.Section l "if" p xs') -> do - subpcs <- go [] xs' - let fs = fmap singletonProjectConfigSkeleton $ fieldsToConfig (reverse acc) + subpcs <- go depth [] xs' + let fs = fmap singletonProjectConfigSkeleton $ fieldsToConfig depth (reverse acc) (elseClauses, rest) <- parseElseClauses xs let condNode = (\c pcs e -> CondNode mempty mempty [CondBranch c pcs e]) @@ -251,17 +260,17 @@ parseProjectSkeleton cacheDir httpTransport verbosity seenImports source bs = (s <*> subpcs <*> elseClauses pure . fmap mconcat . sequence $ [fs, condNode, rest] - _ -> go (x : acc) xs - go acc [] = pure . fmap singletonProjectConfigSkeleton . fieldsToConfig $ reverse acc + _ -> go depth (x : acc) xs + go depth acc [] = pure . fmap singletonProjectConfigSkeleton . fieldsToConfig depth $ reverse acc parseElseClauses :: [ParseUtils.Field] -> IO (ParseResult (Maybe ProjectConfigSkeleton), ParseResult ProjectConfigSkeleton) parseElseClauses x = case x of (ParseUtils.Section _l "else" _p xs' : xs) -> do - subpcs <- go [] xs' - rest <- go [] xs + subpcs <- go 0 [] xs' + rest <- go 0 [] xs pure (Just <$> subpcs, rest) (ParseUtils.Section l "elif" p xs' : xs) -> do - subpcs <- go [] xs' + subpcs <- go 0 [] xs' (elseClauses, rest) <- parseElseClauses xs let condNode = (\c pcs e -> CondNode mempty mempty [CondBranch c pcs e]) @@ -269,9 +278,9 @@ parseProjectSkeleton cacheDir httpTransport verbosity seenImports source bs = (s <*> subpcs <*> elseClauses pure (Just <$> condNode, rest) - _ -> (\r -> (pure Nothing, r)) <$> go [] x + _ -> (\r -> (pure Nothing, r)) <$> go 0 [] x - fieldsToConfig xs = fmap (addProvenance . convertLegacyProjectConfig) $ parseLegacyProjectConfigFields source xs + fieldsToConfig depth xs = fmap (addProvenance . convertLegacyProjectConfig) $ parseLegacyProjectConfigFields (ProjectConfigImport depth source) xs addProvenance x = x{projectConfigProvenance = Set.singleton (Explicit source)} adaptParseError _ (Right x) = pure x @@ -285,7 +294,7 @@ parseProjectSkeleton cacheDir httpTransport verbosity seenImports source bs = (s liftPR _ (ParseFailed e) = pure $ ParseFailed e fetchImportConfig :: ProjectConfigImport -> IO BS.ByteString - fetchImportConfig pci = case parseURI pci of + fetchImportConfig (importPath -> pci) = case parseURI pci of Just uri -> do let fp = cacheDir map (\x -> if isPathSeparator x then '_' else x) (makeValid $ show uri) createDirectoryIfMissing True cacheDir @@ -667,6 +676,7 @@ convertLegacyAllPackageFlags globalFlags configFlags configExFlags installFlags installStrongFlags = projectConfigStrongFlags , installAllowBootLibInstalls = projectConfigAllowBootLibInstalls , installOnlyConstrained = projectConfigOnlyConstrained + , installVersionWin = projectConfigVersionWin } = installFlags ProjectFlags @@ -941,6 +951,7 @@ convertToLegacySharedConfig , installStrongFlags = projectConfigStrongFlags , installAllowBootLibInstalls = projectConfigAllowBootLibInstalls , installOnlyConstrained = projectConfigOnlyConstrained + , installVersionWin = projectConfigVersionWin , installOnly = mempty , installOnlyDeps = projectConfigOnlyDeps , installIndexState = projectConfigIndexState @@ -1177,18 +1188,16 @@ convertToLegacyPerPackageConfig PackageConfig{..} = -- Parsing and showing the project config file -- -parseLegacyProjectConfigFields :: FilePath -> [ParseUtils.Field] -> ParseResult LegacyProjectConfig -parseLegacyProjectConfigFields source = +parseLegacyProjectConfigFields :: ProjectConfigImport -> [ParseUtils.Field] -> ParseResult LegacyProjectConfig +parseLegacyProjectConfigFields (ConstraintSourceProjectConfig -> constraintSrc) = parseFieldsAndSections (legacyProjectConfigFieldDescrs constraintSrc) legacyPackageConfigSectionDescrs legacyPackageConfigFGSectionDescrs mempty - where - constraintSrc = ConstraintSourceProjectConfig source parseLegacyProjectConfig :: FilePath -> BS.ByteString -> ParseResult LegacyProjectConfig -parseLegacyProjectConfig source bs = parseLegacyProjectConfigFields source =<< ParseUtils.readFields bs +parseLegacyProjectConfig source bs = parseLegacyProjectConfigFields (ProjectConfigImport 0 source) =<< ParseUtils.readFields bs showLegacyProjectConfig :: LegacyProjectConfig -> String showLegacyProjectConfig config = @@ -1203,7 +1212,7 @@ showLegacyProjectConfig config = -- Note: ConstraintSource is unused when pretty-printing. We fake -- it here to avoid having to pass it on call-sites. It's not great -- but requires re-work of how we annotate provenance. - constraintSrc = ConstraintSourceProjectConfig "unused" + constraintSrc = ConstraintSourceProjectConfig $ ProjectConfigImport 0 "unused" legacyProjectConfigFieldDescrs :: ConstraintSource -> [FieldDescr LegacyProjectConfig] legacyProjectConfigFieldDescrs constraintSrc = @@ -1406,6 +1415,7 @@ legacySharedConfigFieldDescrs constraintSrc = , "allow-boot-library-installs" , "reject-unconstrained-dependencies" , "index-state" + , "version-win" ] . commandOptionsToFields $ installOptions ParseArgs diff --git a/cabal-install/src/Distribution/Client/ProjectConfig/Types.hs b/cabal-install/src/Distribution/Client/ProjectConfig/Types.hs index 744a50ddc37..899d18b1c3e 100644 --- a/cabal-install/src/Distribution/Client/ProjectConfig/Types.hs +++ b/cabal-install/src/Distribution/Client/ProjectConfig/Types.hs @@ -6,6 +6,7 @@ module Distribution.Client.ProjectConfig.Types ( -- * Types for project config ProjectConfig (..) + , ProjectConfigToParse (..) , ProjectConfigBuildOnly (..) , ProjectConfigShared (..) , ProjectConfigProvenance (..) @@ -26,6 +27,7 @@ module Distribution.Client.ProjectConfig.Types import Distribution.Client.Compat.Prelude import Prelude () +import qualified Data.ByteString.Char8 as BS import Distribution.Client.BuildReports.Types ( ReportLevel (..) ) @@ -94,12 +96,24 @@ import Distribution.Version ) import qualified Data.Map as Map +import Distribution.Solver.Types.LabeledPackageConstraint (VersionWin) import Distribution.Types.ParStrat ------------------------------- -- Project config types -- +-- | The project configuration is configuration that is parsed but parse +-- configuration may import more configuration. This record attaches an import +-- depth to each piece of imported configuration. +data ProjectConfigToParse = ProjectConfigToParse + { toParseDepth :: Int + -- ^ Depth of the import. The main project config file has depth 0, and each + -- import increases the depth by 1. + , toParseContents :: BS.ByteString + -- ^ Unparsed contents of an imported file contributing to the project config. + } + -- | This type corresponds directly to what can be written in the -- @cabal.project@ file. Other sources of configuration can also be injected -- into this type, such as the user-wide config file and the @@ -215,6 +229,7 @@ data ProjectConfigShared = ProjectConfigShared , projectConfigStrongFlags :: Flag StrongFlags , projectConfigAllowBootLibInstalls :: Flag AllowBootLibInstalls , projectConfigOnlyConstrained :: Flag OnlyConstrained + , projectConfigVersionWin :: Flag VersionWin , projectConfigPerComponent :: Flag Bool , projectConfigIndependentGoals :: Flag IndependentGoals , projectConfigPreferOldest :: Flag PreferOldest @@ -417,6 +432,7 @@ data SolverSettings = SolverSettings , solverSettingStrongFlags :: StrongFlags , solverSettingAllowBootLibInstalls :: AllowBootLibInstalls , solverSettingOnlyConstrained :: OnlyConstrained + , solverSettingVersionWin :: VersionWin , solverSettingIndexState :: Maybe TotalIndexState , solverSettingActiveRepos :: Maybe ActiveRepos , solverSettingIndependentGoals :: IndependentGoals diff --git a/cabal-install/src/Distribution/Client/ProjectPlanning.hs b/cabal-install/src/Distribution/Client/ProjectPlanning.hs index 9fd24b45ccc..eb53009cd8c 100644 --- a/cabal-install/src/Distribution/Client/ProjectPlanning.hs +++ b/cabal-install/src/Distribution/Client/ProjectPlanning.hs @@ -1244,6 +1244,7 @@ planPackages . setStrongFlags solverSettingStrongFlags . setAllowBootLibInstalls solverSettingAllowBootLibInstalls . setOnlyConstrained solverSettingOnlyConstrained + . setVersionWin solverSettingVersionWin . setSolverVerbosity verbosity -- TODO: [required eventually] decide if we need to prefer -- installed for global packages, or prefer latest even for diff --git a/cabal-install/src/Distribution/Client/ScriptUtils.hs b/cabal-install/src/Distribution/Client/ScriptUtils.hs index e66117414a8..fd1693f25f0 100644 --- a/cabal-install/src/Distribution/Client/ScriptUtils.hs +++ b/cabal-install/src/Distribution/Client/ScriptUtils.hs @@ -61,6 +61,7 @@ import Distribution.Client.ProjectConfig.Legacy , instantiateProjectConfigSkeletonFetchingCompiler , parseProjectSkeleton ) +import Distribution.Client.ProjectConfig.Types (ProjectConfigToParse (..)) import Distribution.Client.ProjectFlags ( flagIgnoreProject ) @@ -506,7 +507,7 @@ readProjectBlockFromScript verbosity httpTransport DistDirLayout{distDownloadSrc Left _ -> return mempty Right x -> reportParseResult verbosity "script" scriptName - =<< parseProjectSkeleton distDownloadSrcDirectory httpTransport verbosity [] scriptName x + =<< parseProjectSkeleton distDownloadSrcDirectory httpTransport verbosity [] scriptName (ProjectConfigToParse 0 x) -- | Extract the first encountered script metadata block started end -- terminated by the tokens diff --git a/cabal-install/src/Distribution/Client/Setup.hs b/cabal-install/src/Distribution/Client/Setup.hs index 85cc7665647..7a193c04b0e 100644 --- a/cabal-install/src/Distribution/Client/Setup.hs +++ b/cabal-install/src/Distribution/Client/Setup.hs @@ -234,6 +234,7 @@ import Control.Exception import Data.List ( deleteFirstsBy ) +import Distribution.Solver.Types.LabeledPackageConstraint (VersionWin (..)) import System.FilePath ( () ) @@ -1287,6 +1288,7 @@ data FetchFlags = FetchFlags , fetchStrongFlags :: Flag StrongFlags , fetchAllowBootLibInstalls :: Flag AllowBootLibInstalls , fetchOnlyConstrained :: Flag OnlyConstrained + , fetchVersionWins :: Flag VersionWin , fetchTests :: Flag Bool , fetchBenchmarks :: Flag Bool , fetchVerbosity :: Flag Verbosity @@ -1310,6 +1312,7 @@ defaultFetchFlags = , fetchStrongFlags = Flag (StrongFlags False) , fetchAllowBootLibInstalls = Flag (AllowBootLibInstalls False) , fetchOnlyConstrained = Flag OnlyConstrainedNone + , fetchVersionWins = Flag ShallowWins , fetchTests = toFlag False , fetchBenchmarks = toFlag False , fetchVerbosity = toFlag normal @@ -1398,6 +1401,8 @@ fetchCommand = (\v flags -> flags{fetchAllowBootLibInstalls = v}) fetchOnlyConstrained (\v flags -> flags{fetchOnlyConstrained = v}) + fetchVersionWins + (\v flags -> flags{fetchVersionWins = v}) } -- ------------------------------------------------------------ @@ -1422,6 +1427,7 @@ data FreezeFlags = FreezeFlags , freezeStrongFlags :: Flag StrongFlags , freezeAllowBootLibInstalls :: Flag AllowBootLibInstalls , freezeOnlyConstrained :: Flag OnlyConstrained + , freezeVersionWin :: Flag VersionWin , freezeVerbosity :: Flag Verbosity } @@ -1443,6 +1449,7 @@ defaultFreezeFlags = , freezeStrongFlags = Flag (StrongFlags False) , freezeAllowBootLibInstalls = Flag (AllowBootLibInstalls False) , freezeOnlyConstrained = Flag OnlyConstrainedNone + , freezeVersionWin = Flag ShallowWins , freezeVerbosity = toFlag normal } @@ -1520,6 +1527,8 @@ freezeCommand = (\v flags -> flags{freezeAllowBootLibInstalls = v}) freezeOnlyConstrained (\v flags -> flags{freezeOnlyConstrained = v}) + freezeVersionWin + (\v flags -> flags{freezeVersionWin = v}) } -- ------------------------------------------------------------ @@ -2118,6 +2127,7 @@ data InstallFlags = InstallFlags , installStrongFlags :: Flag StrongFlags , installAllowBootLibInstalls :: Flag AllowBootLibInstalls , installOnlyConstrained :: Flag OnlyConstrained + , installVersionWin :: Flag VersionWin , installReinstall :: Flag Bool , installAvoidReinstalls :: Flag AvoidReinstalls , installOverrideReinstall :: Flag Bool @@ -2163,6 +2173,7 @@ defaultInstallFlags = , installStrongFlags = Flag (StrongFlags False) , installAllowBootLibInstalls = Flag (AllowBootLibInstalls False) , installOnlyConstrained = Flag OnlyConstrainedNone + , installVersionWin = Flag ShallowWins , installReinstall = Flag False , installAvoidReinstalls = Flag (AvoidReinstalls False) , installOverrideReinstall = Flag False @@ -2506,6 +2517,8 @@ installOptions showOrParseArgs = (\v flags -> flags{installAllowBootLibInstalls = v}) installOnlyConstrained (\v flags -> flags{installOnlyConstrained = v}) + installVersionWin + (\v flags -> flags{installVersionWin = v}) ++ [ option [] ["reinstall"] @@ -3497,6 +3510,8 @@ optionSolverFlags -> (Flag AllowBootLibInstalls -> flags -> flags) -> (flags -> Flag OnlyConstrained) -> (Flag OnlyConstrained -> flags -> flags) + -> (flags -> Flag VersionWin) + -> (Flag VersionWin -> flags -> flags) -> [OptionField flags] optionSolverFlags showOrParseArgs @@ -3521,7 +3536,9 @@ optionSolverFlags getib setib getoc - setoc = + setoc + getw + setw = [ option [] ["max-backjumps"] @@ -3613,6 +3630,20 @@ optionSolverFlags ) (flagToList . fmap prettyShow) ) + , option + [] + ["version-win"] + "How to pick a winning version constraint when there are conflicts, often introduced by imports." + getw + setw + ( reqArg + "latest|shallowest" + ( parsecToReadE + (const "version-win must be 'latest' or 'shallowest'") + (toFlag `fmap` parsec) + ) + (flagToList . fmap prettyShow) + ) ] usagePackages :: String -> String -> String diff --git a/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs b/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs index cdb34a3534c..e7c945d00ed 100644 --- a/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs +++ b/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs @@ -52,6 +52,7 @@ import Distribution.Utils.NubList import Distribution.Verbosity (silent) import Distribution.Solver.Types.ConstraintSource +import Distribution.Solver.Types.LabeledPackageConstraint import Distribution.Solver.Types.PackageConstraint import Distribution.Solver.Types.Settings @@ -589,6 +590,7 @@ instance Arbitrary ProjectConfigShared where projectConfigStrongFlags <- arbitrary projectConfigAllowBootLibInstalls <- arbitrary projectConfigOnlyConstrained <- arbitrary + projectConfigVersionWin <- arbitrary projectConfigPerComponent <- arbitrary projectConfigIndependentGoals <- arbitrary projectConfigPreferOldest <- arbitrary @@ -635,6 +637,7 @@ instance Arbitrary ProjectConfigShared where <*> shrinker projectConfigStrongFlags <*> shrinker projectConfigAllowBootLibInstalls <*> shrinker projectConfigOnlyConstrained + <*> shrinker projectConfigVersionWin <*> shrinker projectConfigPerComponent <*> shrinker projectConfigIndependentGoals <*> shrinker projectConfigPreferOldest @@ -646,7 +649,7 @@ instance Arbitrary ProjectConfigShared where projectConfigConstraintSource :: ConstraintSource projectConfigConstraintSource = - ConstraintSourceProjectConfig "unused" + ConstraintSourceProjectConfig $ ProjectConfigImport 0 "unused" instance Arbitrary ProjectConfigProvenance where arbitrary = elements [Implicit, Explicit "cabal.project"] @@ -1002,3 +1005,10 @@ instance Arbitrary OnlyConstrained where [ pure OnlyConstrainedAll , pure OnlyConstrainedNone ] + +instance Arbitrary VersionWin where + arbitrary = + oneof + [ pure ShallowWins + , pure LastWins + ] diff --git a/cabal-install/tests/UnitTests/Distribution/Client/TreeDiffInstances.hs b/cabal-install/tests/UnitTests/Distribution/Client/TreeDiffInstances.hs index 495c4cbf402..d8bb8eca26d 100644 --- a/cabal-install/tests/UnitTests/Distribution/Client/TreeDiffInstances.hs +++ b/cabal-install/tests/UnitTests/Distribution/Client/TreeDiffInstances.hs @@ -4,6 +4,7 @@ module UnitTests.Distribution.Client.TreeDiffInstances () where import Distribution.Solver.Types.ConstraintSource +import Distribution.Solver.Types.LabeledPackageConstraint import Distribution.Solver.Types.OptionalStanza import Distribution.Solver.Types.PackageConstraint import Distribution.Solver.Types.Settings @@ -39,6 +40,7 @@ instance ToExpr AllowOlder instance ToExpr BuildReport instance ToExpr ClientInstallFlags instance ToExpr CombineStrategy +instance ToExpr ProjectConfigImport instance ToExpr ConstraintSource instance ToExpr CountConflicts instance ToExpr FineGrainedConflicts @@ -48,6 +50,7 @@ instance ToExpr InstallOutcome instance ToExpr LocalRepo instance ToExpr MinimizeConflictSet instance ToExpr OnlyConstrained +instance ToExpr VersionWin instance ToExpr OptionalStanza instance ToExpr Outcome instance ToExpr OverwritePolicy diff --git a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/DSL.hs b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/DSL.hs index 9307aae8feb..ccb8dffce4a 100644 --- a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/DSL.hs +++ b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/DSL.hs @@ -86,7 +86,7 @@ import Distribution.Solver.Types.ComponentDeps (ComponentDeps) import qualified Distribution.Solver.Types.ComponentDeps as CD import Distribution.Solver.Types.ConstraintSource import Distribution.Solver.Types.Flag -import Distribution.Solver.Types.LabeledPackageConstraint +import Distribution.Solver.Types.LabeledPackageConstraint hiding (versionWin) import Distribution.Solver.Types.OptionalStanza import Distribution.Solver.Types.PackageConstraint import qualified Distribution.Solver.Types.PackageIndex as CI.PackageIndex @@ -790,6 +790,7 @@ exResolve -> ReorderGoals -> AllowBootLibInstalls -> OnlyConstrained + -> VersionWin -> EnableBackjumping -> SolveExecutables -> Maybe (Variable P.QPN -> Variable P.QPN -> Ordering) @@ -813,6 +814,7 @@ exResolve reorder allowBootLibInstalls onlyConstrained + versionWin enableBj solveExes goalOrder @@ -859,11 +861,12 @@ exResolve setMaxBackjumps mbj $ setAllowBootLibInstalls allowBootLibInstalls $ setOnlyConstrained onlyConstrained $ - setEnableBackjumping enableBj $ - setSolveExecutables solveExes $ - setGoalOrder goalOrder $ - setSolverVerbosity verbosity $ - standardInstallPolicy instIdx avaiIdx targets' + setVersionWin versionWin $ + setEnableBackjumping enableBj $ + setSolveExecutables solveExes $ + setGoalOrder goalOrder $ + setSolverVerbosity verbosity $ + standardInstallPolicy instIdx avaiIdx targets' toLpc pc = LabeledPackageConstraint pc ConstraintSourceUnknown toConstraint (ExVersionConstraint scope v) = diff --git a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/DSL/TestCaseUtils.hs b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/DSL/TestCaseUtils.hs index 91ec541f976..42eeac3a0e4 100644 --- a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/DSL/TestCaseUtils.hs +++ b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/DSL/TestCaseUtils.hs @@ -46,6 +46,7 @@ import Language.Haskell.Extension (Extension (..), Language (..)) -- cabal-install import Distribution.Client.Dependency (foldProgress) +import Distribution.Solver.Types.LabeledPackageConstraint import qualified Distribution.Solver.Types.PackagePath as P import Distribution.Solver.Types.PkgConfigDb (PkgConfigDb (..), pkgConfigDbFromList) import Distribution.Solver.Types.Settings @@ -121,6 +122,7 @@ data SolverTest = SolverTest , testPreferOldest :: PreferOldest , testAllowBootLibInstalls :: AllowBootLibInstalls , testOnlyConstrained :: OnlyConstrained + , testVersionWin :: VersionWin , testEnableBackjumping :: EnableBackjumping , testSolveExecutables :: SolveExecutables , testGoalOrder :: Maybe [ExampleVar] @@ -224,6 +226,7 @@ mkTestExtLangPC exts langs mPkgConfigDb db label targets result = , testPreferOldest = PreferOldest False , testAllowBootLibInstalls = AllowBootLibInstalls False , testOnlyConstrained = OnlyConstrainedNone + , testVersionWin = ShallowWins , testEnableBackjumping = EnableBackjumping True , testSolveExecutables = SolveExecutables True , testGoalOrder = Nothing @@ -256,6 +259,7 @@ runTest SolverTest{..} = askOption $ \(OptionShowSolverLog showSolverLog) -> (ReorderGoals False) testAllowBootLibInstalls testOnlyConstrained + testVersionWin testEnableBackjumping testSolveExecutables (sortGoals <$> testGoalOrder) diff --git a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/QuickCheck.hs b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/QuickCheck.hs index 114db775f21..b8ba5ac4bd7 100644 --- a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/QuickCheck.hs +++ b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/QuickCheck.hs @@ -34,6 +34,7 @@ import Distribution.Solver.Types.ComponentDeps , ComponentDeps ) import qualified Distribution.Solver.Types.ComponentDeps as CD +import Distribution.Solver.Types.LabeledPackageConstraint import Distribution.Solver.Types.OptionalStanza import Distribution.Solver.Types.PackageConstraint import qualified Distribution.Solver.Types.PackagePath as P @@ -240,6 +241,7 @@ solve enableBj fineGrainedConflicts reorder countConflicts indep prefOldest goal reorder (AllowBootLibInstalls False) OnlyConstrainedNone + ShallowWins enableBj (SolveExecutables True) (unVarOrdering <$> goalOrder) diff --git a/cabal-testsuite/PackageTests/VersionPriority/0-local.out b/cabal-testsuite/PackageTests/VersionPriority/0-local.out new file mode 100644 index 00000000000..f2acb4449ba --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/0-local.out @@ -0,0 +1,31 @@ +# cabal v2-update +Downloading the latest package list from test-local-repo +# --version-win not supplied, default +# cabal v2-build +Resolving dependencies... +Error: [Cabal-7107] +Could not resolve dependencies: +[__0] trying: cabal-version-override-0.1.0.0 (user goal) +[__1] next goal: hashable (dependency of cabal-version-override) +[__1] rejecting: hashable-1.4.3.0 (constraint from project config ProjectConfigImport {importDepth = 0, importPath = "/0-local.project"} requires ==1.4.2.0) +[__1] rejecting: hashable-1.4.2.0 (constraint from project config ProjectConfigImport {importDepth = 0, importPath = "/0-local.project"} requires ==1.4.3.0) +[__1] fail (backjumping, conflict set: cabal-version-override, hashable) +After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: hashable (3), cabal-version-override (2) +# --version-win=shallowest +# cabal v2-build +Resolving dependencies... +Error: [Cabal-7107] +Could not resolve dependencies: +[__0] trying: cabal-version-override-0.1.0.0 (user goal) +[__1] next goal: hashable (dependency of cabal-version-override) +[__1] rejecting: hashable-1.4.3.0 (constraint from project config ProjectConfigImport {importDepth = 0, importPath = "/0-local.project"} requires ==1.4.2.0) +[__1] rejecting: hashable-1.4.2.0 (constraint from project config ProjectConfigImport {importDepth = 0, importPath = "/0-local.project"} requires ==1.4.3.0) +[__1] fail (backjumping, conflict set: cabal-version-override, hashable) +After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: hashable (3), cabal-version-override (2) +# --version-win=latest +# cabal v2-build +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following would be built: + - hashable-1.4.2.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) diff --git a/cabal-testsuite/PackageTests/VersionPriority/0-local.project b/cabal-testsuite/PackageTests/VersionPriority/0-local.project new file mode 100644 index 00000000000..262cd6eefbc --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/0-local.project @@ -0,0 +1,3 @@ +packages: . +constraints: hashable ==1.4.3.0 +constraints: hashable ==1.4.2.0 diff --git a/cabal-testsuite/PackageTests/VersionPriority/0-local.test.hs b/cabal-testsuite/PackageTests/VersionPriority/0-local.test.hs new file mode 100644 index 00000000000..3f2f4046860 --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/0-local.test.hs @@ -0,0 +1,10 @@ +import Test.Cabal.Prelude + +main = cabalTest . withRepo "repo" . withProjectFile "0-local.project" . recordMode RecordMarked $ do + let log = recordHeader . pure + log "--version-win not supplied, default" + fails $ cabal "v2-build" ["--dry-run"] + log "--version-win=shallowest" + fails $ cabal "v2-build" ["--dry-run", "--version-win=shallowest"] + log "--version-win=latest" + cabal "v2-build" ["--dry-run", "--version-win=latest"] \ No newline at end of file diff --git a/cabal-testsuite/PackageTests/VersionPriority/1-local-constraints-import.project b/cabal-testsuite/PackageTests/VersionPriority/1-local-constraints-import.project new file mode 100644 index 00000000000..986ca4376f2 --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/1-local-constraints-import.project @@ -0,0 +1,4 @@ +packages: . +allow-newer: hashable:* +constraints: hashable ==1.4.2.0 +import: stackage-local.config diff --git a/cabal-testsuite/PackageTests/VersionPriority/1-local-import-constraints.project b/cabal-testsuite/PackageTests/VersionPriority/1-local-import-constraints.project new file mode 100644 index 00000000000..1ee9a90cccc --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/1-local-import-constraints.project @@ -0,0 +1,4 @@ +packages: . +allow-newer: hashable:* +import: stackage-local.config +constraints: hashable ==1.4.2.0 diff --git a/cabal-testsuite/PackageTests/VersionPriority/1-local.out b/cabal-testsuite/PackageTests/VersionPriority/1-local.out new file mode 100644 index 00000000000..ee933bd260e --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/1-local.out @@ -0,0 +1,42 @@ +# cabal v2-update +Downloading the latest package list from test-local-repo +# 1-local-constraints-import.project --version-win not supplied, default +# cabal v2-build +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following would be built: + - hashable-1.4.2.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) +# 1-local-constraints-import.project --version-win=shallowest +# cabal v2-build +Build profile: -w ghc- -O1 +In order, the following would be built: + - hashable-1.4.2.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) +# 1-local-constraints-import.project --version-win=latest +# cabal v2-build +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following would be built: + - hashable-1.4.3.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) +# 1-local-import-constraints.project --version-win not supplied, default +# cabal v2-build +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following would be built: + - hashable-1.4.2.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) +# 1-local-import-constraints.project --version-win=shallowest +# cabal v2-build +Build profile: -w ghc- -O1 +In order, the following would be built: + - hashable-1.4.2.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) +# 1-local-import-constraints.project --version-win=latest +# cabal v2-build +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following would be built: + - hashable-1.4.2.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) diff --git a/cabal-testsuite/PackageTests/VersionPriority/1-local.test.hs b/cabal-testsuite/PackageTests/VersionPriority/1-local.test.hs new file mode 100644 index 00000000000..52604440a06 --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/1-local.test.hs @@ -0,0 +1,15 @@ +import Test.Cabal.Prelude + +testVersionWin project = + withProjectFile project $ do + let log = recordHeader . pure . ((project <> " ") <>) + log "--version-win not supplied, default" + cabal "v2-build" ["--dry-run"] + log "--version-win=shallowest" + cabal "v2-build" ["--dry-run", "--version-win=shallowest"] + log "--version-win=latest" + cabal "v2-build" ["--dry-run", "--version-win=latest"] + +main = cabalTest . withRepo "repo" . recordMode RecordMarked $ do + testVersionWin "1-local-constraints-import.project" + testVersionWin "1-local-import-constraints.project" \ No newline at end of file diff --git a/cabal-testsuite/PackageTests/VersionPriority/1-web-constraints-import.project b/cabal-testsuite/PackageTests/VersionPriority/1-web-constraints-import.project new file mode 100644 index 00000000000..461ab31539b --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/1-web-constraints-import.project @@ -0,0 +1,4 @@ +packages: . +allow-newer: hashable:* +constraints: hashable ==1.4.2.0 +import: https://www.stackage.org/nightly-2023-12-07/cabal.config diff --git a/cabal-testsuite/PackageTests/VersionPriority/1-web-import-constraints.project b/cabal-testsuite/PackageTests/VersionPriority/1-web-import-constraints.project new file mode 100644 index 00000000000..6eebd83af30 --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/1-web-import-constraints.project @@ -0,0 +1,4 @@ +packages: . +allow-newer: hashable:* +import: https://www.stackage.org/nightly-2023-12-07/cabal.config +constraints: hashable ==1.4.2.0 diff --git a/cabal-testsuite/PackageTests/VersionPriority/1-web.out b/cabal-testsuite/PackageTests/VersionPriority/1-web.out new file mode 100644 index 00000000000..1fd63484ab7 --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/1-web.out @@ -0,0 +1,42 @@ +# cabal v2-update +Downloading the latest package list from test-local-repo +# 1-web-constraints-import.project --version-win not supplied, default +# cabal v2-build +Resolving dependencies... +Build profile: -w ghc-9.6.3 -O1 +In order, the following would be built: + - hashable-1.4.2.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) +# 1-web-constraints-import.project --version-win=shallowest +# cabal v2-build +Build profile: -w ghc-9.6.3 -O1 +In order, the following would be built: + - hashable-1.4.2.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) +# 1-web-constraints-import.project --version-win=latest +# cabal v2-build +Resolving dependencies... +Build profile: -w ghc-9.6.3 -O1 +In order, the following would be built: + - hashable-1.4.3.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) +# 1-web-import-constraints.project --version-win not supplied, default +# cabal v2-build +Resolving dependencies... +Build profile: -w ghc-9.6.3 -O1 +In order, the following would be built: + - hashable-1.4.2.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) +# 1-web-import-constraints.project --version-win=shallowest +# cabal v2-build +Build profile: -w ghc-9.6.3 -O1 +In order, the following would be built: + - hashable-1.4.2.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) +# 1-web-import-constraints.project --version-win=latest +# cabal v2-build +Resolving dependencies... +Build profile: -w ghc-9.6.3 -O1 +In order, the following would be built: + - hashable-1.4.2.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) diff --git a/cabal-testsuite/PackageTests/VersionPriority/1-web.test.hs b/cabal-testsuite/PackageTests/VersionPriority/1-web.test.hs new file mode 100644 index 00000000000..88cfcc9ccf9 --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/1-web.test.hs @@ -0,0 +1,19 @@ +import Test.Cabal.Prelude + +testVersionWin project = + withProjectFile project $ do + let log = recordHeader . pure . ((project <> " ") <>) + log "--version-win not supplied, default" + cabal "v2-build" ["--dry-run"] + log "--version-win=shallowest" + cabal "v2-build" ["--dry-run", "--version-win=shallowest"] + log "--version-win=latest" + cabal "v2-build" ["--dry-run", "--version-win=latest"] + +main = cabalTest . withRepo "repo" . recordMode RecordMarked $ do + -- To avoid this diff: + -- -Build profile: -w ghc-9.6.3 -O1 + -- +Build profile: -w ghc- -O1 + skipIfGhcVersion "== 9.6.3" + testVersionWin "1-web-constraints-import.project" + testVersionWin "1-web-import-constraints.project" diff --git a/cabal-testsuite/PackageTests/VersionPriority/2-local-constraints-import.project b/cabal-testsuite/PackageTests/VersionPriority/2-local-constraints-import.project new file mode 100644 index 00000000000..b34145826a6 --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/2-local-constraints-import.project @@ -0,0 +1,4 @@ +packages: . +allow-newer: hashable:* +constraints: hashable ==1.4.2.0 +import: hop-local.config diff --git a/cabal-testsuite/PackageTests/VersionPriority/2-local-import-constraints.project b/cabal-testsuite/PackageTests/VersionPriority/2-local-import-constraints.project new file mode 100644 index 00000000000..783f5f24617 --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/2-local-import-constraints.project @@ -0,0 +1,4 @@ +packages: . +allow-newer: hashable:* +import: hop-local.config +constraints: hashable ==1.4.2.0 diff --git a/cabal-testsuite/PackageTests/VersionPriority/2-local.out b/cabal-testsuite/PackageTests/VersionPriority/2-local.out new file mode 100644 index 00000000000..dfb0080b010 --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/2-local.out @@ -0,0 +1,42 @@ +# cabal v2-update +Downloading the latest package list from test-local-repo +# 2-local-constraints-import.project --version-win not supplied, default +# cabal v2-build +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following would be built: + - hashable-1.4.2.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) +# 2-local-constraints-import.project --version-win=shallowest +# cabal v2-build +Build profile: -w ghc- -O1 +In order, the following would be built: + - hashable-1.4.2.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) +# 2-local-constraints-import.project --version-win=latest +# cabal v2-build +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following would be built: + - hashable-1.4.3.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) +# 2-local-import-constraints.project --version-win not supplied, default +# cabal v2-build +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following would be built: + - hashable-1.4.2.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) +# 2-local-import-constraints.project --version-win=shallowest +# cabal v2-build +Build profile: -w ghc- -O1 +In order, the following would be built: + - hashable-1.4.2.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) +# 2-local-import-constraints.project --version-win=latest +# cabal v2-build +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following would be built: + - hashable-1.4.2.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) diff --git a/cabal-testsuite/PackageTests/VersionPriority/2-local.test.hs b/cabal-testsuite/PackageTests/VersionPriority/2-local.test.hs new file mode 100644 index 00000000000..b6ac4352a35 --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/2-local.test.hs @@ -0,0 +1,15 @@ +import Test.Cabal.Prelude + +testVersionWin project = + withProjectFile project $ do + let log = recordHeader . pure . ((project <> " ") <>) + log "--version-win not supplied, default" + cabal "v2-build" ["--dry-run"] + log "--version-win=shallowest" + cabal "v2-build" ["--dry-run", "--version-win=shallowest"] + log "--version-win=latest" + cabal "v2-build" ["--dry-run", "--version-win=latest"] + +main = cabalTest . withRepo "repo" . recordMode RecordMarked $ do + testVersionWin "2-local-constraints-import.project" + testVersionWin "2-local-import-constraints.project" \ No newline at end of file diff --git a/cabal-testsuite/PackageTests/VersionPriority/2-web-constraints-import.project b/cabal-testsuite/PackageTests/VersionPriority/2-web-constraints-import.project new file mode 100644 index 00000000000..2be7836ec6e --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/2-web-constraints-import.project @@ -0,0 +1,4 @@ +packages: . +allow-newer: hashable:* +constraints: hashable ==1.4.2.0 +import: stackage-web.config diff --git a/cabal-testsuite/PackageTests/VersionPriority/2-web-import-constraints.project b/cabal-testsuite/PackageTests/VersionPriority/2-web-import-constraints.project new file mode 100644 index 00000000000..512f235dbbf --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/2-web-import-constraints.project @@ -0,0 +1,4 @@ +packages: . +allow-newer: hashable:* +import: stackage-web.config +constraints: hashable ==1.4.2.0 diff --git a/cabal-testsuite/PackageTests/VersionPriority/2-web.out b/cabal-testsuite/PackageTests/VersionPriority/2-web.out new file mode 100644 index 00000000000..1ae0dae4c91 --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/2-web.out @@ -0,0 +1,42 @@ +# cabal v2-update +Downloading the latest package list from test-local-repo +# 2-web-constraints-import.project --version-win not supplied, default +# cabal v2-build +Resolving dependencies... +Build profile: -w ghc-9.6.3 -O1 +In order, the following would be built: + - hashable-1.4.2.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) +# 2-web-constraints-import.project --version-win=shallowest +# cabal v2-build +Build profile: -w ghc-9.6.3 -O1 +In order, the following would be built: + - hashable-1.4.2.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) +# 2-web-constraints-import.project --version-win=latest +# cabal v2-build +Resolving dependencies... +Build profile: -w ghc-9.6.3 -O1 +In order, the following would be built: + - hashable-1.4.3.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) +# 2-web-import-constraints.project --version-win not supplied, default +# cabal v2-build +Resolving dependencies... +Build profile: -w ghc-9.6.3 -O1 +In order, the following would be built: + - hashable-1.4.2.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) +# 2-web-import-constraints.project --version-win=shallowest +# cabal v2-build +Build profile: -w ghc-9.6.3 -O1 +In order, the following would be built: + - hashable-1.4.2.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) +# 2-web-import-constraints.project --version-win=latest +# cabal v2-build +Resolving dependencies... +Build profile: -w ghc-9.6.3 -O1 +In order, the following would be built: + - hashable-1.4.2.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) diff --git a/cabal-testsuite/PackageTests/VersionPriority/2-web.test.hs b/cabal-testsuite/PackageTests/VersionPriority/2-web.test.hs new file mode 100644 index 00000000000..a0bf0c92ebe --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/2-web.test.hs @@ -0,0 +1,19 @@ +import Test.Cabal.Prelude + +testVersionWin project = + withProjectFile project $ do + let log = recordHeader . pure . ((project <> " ") <>) + log "--version-win not supplied, default" + cabal "v2-build" ["--dry-run"] + log "--version-win=shallowest" + cabal "v2-build" ["--dry-run", "--version-win=shallowest"] + log "--version-win=latest" + cabal "v2-build" ["--dry-run", "--version-win=latest"] + +main = cabalTest . withRepo "repo" . recordMode RecordMarked $ do + -- To avoid this diff: + -- -Build profile: -w ghc-9.6.3 -O1 + -- +Build profile: -w ghc- -O1 + skipIfGhcVersion "== 9.6.3" + testVersionWin "2-web-constraints-import.project" + testVersionWin "2-web-import-constraints.project" diff --git a/cabal-testsuite/PackageTests/VersionPriority/3-web-constraints-import.project b/cabal-testsuite/PackageTests/VersionPriority/3-web-constraints-import.project new file mode 100644 index 00000000000..11f33600f96 --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/3-web-constraints-import.project @@ -0,0 +1,4 @@ +packages: . +allow-newer: hashable:* +constraints: hashable ==1.4.2.0 +import: hop-web.config diff --git a/cabal-testsuite/PackageTests/VersionPriority/3-web-import-constraints.project b/cabal-testsuite/PackageTests/VersionPriority/3-web-import-constraints.project new file mode 100644 index 00000000000..79b3be19327 --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/3-web-import-constraints.project @@ -0,0 +1,4 @@ +packages: . +allow-newer: hashable:* +import: hop-web.config +constraints: hashable ==1.4.2.0 diff --git a/cabal-testsuite/PackageTests/VersionPriority/3-web.out b/cabal-testsuite/PackageTests/VersionPriority/3-web.out new file mode 100644 index 00000000000..feecbd51c4f --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/3-web.out @@ -0,0 +1,42 @@ +# cabal v2-update +Downloading the latest package list from test-local-repo +# 3-web-constraints-import.project --version-win not supplied, default +# cabal v2-build +Resolving dependencies... +Build profile: -w ghc-9.6.3 -O1 +In order, the following would be built: + - hashable-1.4.2.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) +# 3-web-constraints-import.project --version-win=shallowest +# cabal v2-build +Build profile: -w ghc-9.6.3 -O1 +In order, the following would be built: + - hashable-1.4.2.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) +# 3-web-constraints-import.project --version-win=latest +# cabal v2-build +Resolving dependencies... +Build profile: -w ghc-9.6.3 -O1 +In order, the following would be built: + - hashable-1.4.3.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) +# 3-web-import-constraints.project --version-win not supplied, default +# cabal v2-build +Resolving dependencies... +Build profile: -w ghc-9.6.3 -O1 +In order, the following would be built: + - hashable-1.4.2.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) +# 3-web-import-constraints.project --version-win=shallowest +# cabal v2-build +Build profile: -w ghc-9.6.3 -O1 +In order, the following would be built: + - hashable-1.4.2.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) +# 3-web-import-constraints.project --version-win=latest +# cabal v2-build +Resolving dependencies... +Build profile: -w ghc-9.6.3 -O1 +In order, the following would be built: + - hashable-1.4.2.0 (lib) (requires build) + - cabal-version-override-0.1.0.0 (exe:cabal-version-override) (first run) diff --git a/cabal-testsuite/PackageTests/VersionPriority/3-web.test.hs b/cabal-testsuite/PackageTests/VersionPriority/3-web.test.hs new file mode 100644 index 00000000000..4f9a1c28ac5 --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/3-web.test.hs @@ -0,0 +1,19 @@ +import Test.Cabal.Prelude + +testVersionWin project = + withProjectFile project $ do + let log = recordHeader . pure . ((project <> " ") <>) + log "--version-win not supplied, default" + cabal "v2-build" ["--dry-run"] + log "--version-win=shallowest" + cabal "v2-build" ["--dry-run", "--version-win=shallowest"] + log "--version-win=latest" + cabal "v2-build" ["--dry-run", "--version-win=latest"] + +main = cabalTest . withRepo "repo" . recordMode RecordMarked $ do + -- To avoid this diff: + -- -Build profile: -w ghc-9.6.3 -O1 + -- +Build profile: -w ghc- -O1 + skipIfGhcVersion "== 9.6.3" + testVersionWin "3-web-constraints-import.project" + testVersionWin "3-web-import-constraints.project" diff --git a/cabal-testsuite/PackageTests/VersionPriority/CHANGELOG.md b/cabal-testsuite/PackageTests/VersionPriority/CHANGELOG.md new file mode 100644 index 00000000000..94b42c2ee63 --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/CHANGELOG.md @@ -0,0 +1,5 @@ +# Revision history for cabal-version-override + +## 0.1.0.0 -- YYYY-mm-dd + +* First version. Released on an unsuspecting world. diff --git a/cabal-testsuite/PackageTests/VersionPriority/LICENSE b/cabal-testsuite/PackageTests/VersionPriority/LICENSE new file mode 100644 index 00000000000..a612ad9813b --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/LICENSE @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/cabal-testsuite/PackageTests/VersionPriority/README.md b/cabal-testsuite/PackageTests/VersionPriority/README.md new file mode 100644 index 00000000000..8f76f53f3ac --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/README.md @@ -0,0 +1,51 @@ +# Version Priority Tests + +The `1-` prefix projects have an import depth of 1, the `2-` prefix projects +have a depth of 2 and `3-` prefix has depth 3. The `0-` prefix project have any +imports. Only projects have the `.project` extension. Imported configuration +has a `.config` extension. + +- *0-local.project* + ``` + . + └── 0-local.project + ``` + +- *1-local.project* + ``` + . + └── 1-local.project + └── stackage-local.config + ``` + +- *2-local.project* + ``` + . + └── 2-local.project + └── hop-local.config + └── stackage-local.config + ``` + +- *1-web.project* + ``` + . + └── 1-web.project + └── https://www.stackage.org/nightly-2023-12-07/cabal.config + ``` + +- *2-web.project* + ``` + . + └── 2-web.project + └── stackage-web.config + └── https://www.stackage.org/nightly-2023-12-07/cabal.config + ``` + +- *3-web.project* + ``` + . + └── 3-web.project + └── hop-web.config + └── stackage-web.config + └── https://www.stackage.org/nightly-2023-12-07/cabal.config + ``` diff --git a/cabal-testsuite/PackageTests/VersionPriority/app/Main.hs b/cabal-testsuite/PackageTests/VersionPriority/app/Main.hs new file mode 100644 index 00000000000..a170ab7732d --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/app/Main.hs @@ -0,0 +1,6 @@ +module Main where + +import Data.Hashable + +main :: IO () +main = print $ hash "foo" diff --git a/cabal-testsuite/PackageTests/VersionPriority/cabal-version-override.cabal b/cabal-testsuite/PackageTests/VersionPriority/cabal-version-override.cabal new file mode 100644 index 00000000000..030918bb507 --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/cabal-version-override.cabal @@ -0,0 +1,20 @@ +cabal-version: 3.0 +name: cabal-version-override +version: 0.1.0.0 +license: MPL-2.0 +license-file: LICENSE +author: Phil de Joux +maintainer: philderbeast@gmail.com +category: Development +build-type: Simple +extra-doc-files: CHANGELOG.md + +common warnings + ghc-options: -Wall + +executable cabal-version-override + import: warnings + main-is: Main.hs + build-depends: base, hashable + hs-source-dirs: app + default-language: Haskell2010 diff --git a/cabal-testsuite/PackageTests/VersionPriority/hop-local.config b/cabal-testsuite/PackageTests/VersionPriority/hop-local.config new file mode 100644 index 00000000000..fc9024b3bb5 --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/hop-local.config @@ -0,0 +1 @@ +import: stackage-local.config diff --git a/cabal-testsuite/PackageTests/VersionPriority/hop-web.config b/cabal-testsuite/PackageTests/VersionPriority/hop-web.config new file mode 100644 index 00000000000..848f0c5920d --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/hop-web.config @@ -0,0 +1 @@ +import: stackage-web.config diff --git a/cabal-testsuite/PackageTests/VersionPriority/repo/hashable-1.4.2.0/hashable.cabal b/cabal-testsuite/PackageTests/VersionPriority/repo/hashable-1.4.2.0/hashable.cabal new file mode 100644 index 00000000000..be8d96b783d --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/repo/hashable-1.4.2.0/hashable.cabal @@ -0,0 +1,186 @@ +cabal-version: 1.12 +name: hashable +version: 1.4.2.0 +synopsis: A class for types that can be converted to a hash value +description: + This package defines a class, 'Hashable', for types that + can be converted to a hash value. This class + exists for the benefit of hashing-based data + structures. The package provides instances for + basic types and a way to combine hash values. + +homepage: http://github.com/haskell-unordered-containers/hashable + +-- SPDX-License-Identifier : BSD-3-Clause +license: BSD3 +license-file: LICENSE +author: + Milan Straka + Johan Tibell + +maintainer: Oleg Grenrus +bug-reports: + https://github.com/haskell-unordered-containers/hashable/issues + +stability: Provisional +category: Data +build-type: Simple +tested-with: + GHC ==8.2.2 + || ==8.4.4 + || ==8.6.5 + || ==8.8.3 + || ==8.10.4 + || ==8.10.7 + || ==9.0.1 + || ==9.0.2 + || ==9.2.5 + || ==9.4.4 + +extra-source-files: + CHANGES.md + include/HsHashable.h + README.md + +flag integer-gmp + description: + Are we using @integer-gmp@ to provide fast Integer instances? No effect on GHC-9.0 or later. + + manual: False + default: True + +flag random-initial-seed + description: + Randomly initialize the initial seed on each final executable invocation + This is useful for catching cases when you rely on (non-existent) + stability of hashable's hash functions. + This is not a security feature. + + manual: True + default: False + +library + exposed-modules: + Data.Hashable + Data.Hashable.Generic + Data.Hashable.Lifted + + other-modules: + Data.Hashable.Class + Data.Hashable.Generic.Instances + Data.Hashable.Imports + Data.Hashable.LowLevel + + c-sources: cbits/fnv.c + include-dirs: include + hs-source-dirs: src + build-depends: + -- REMOVED constraint on base for test + -- base >=4.10.1.0 && <4.18 + base + , bytestring >=0.10.8.2 && <0.12 + , containers >=0.5.10.2 && <0.7 + , deepseq >=1.4.3.0 && <1.5 + , filepath >=1.4.1.2 && <1.5 + , ghc-prim + , text >=1.2.3.0 && <1.3 || >=2.0 && <2.1 + + -- REMOVED conditional compilation pulling in extra dependencies + -- if !impl(ghc >=9.2) + -- build-depends: base-orphans >=0.8.6 && <0.9 + + -- if !impl(ghc >=9.4) + -- build-depends: data-array-byte >=0.1.0.1 && <0.2 + + -- Integer internals + if impl(ghc >=9) + build-depends: ghc-bignum >=1.0 && <1.4 + + if !impl(ghc >=9.0.2) + build-depends: ghc-bignum-orphans >=0.1 && <0.2 + + else + if flag(integer-gmp) + build-depends: integer-gmp >=0.4 && <1.1 + + else + -- this is needed for the automatic flag to be well-balanced + build-depends: integer-simple + + if (flag(random-initial-seed) && impl(ghc)) + cpp-options: -DHASHABLE_RANDOM_SEED=1 + + if os(windows) + c-sources: cbits-win/init.c + + else + c-sources: cbits-unix/init.c + + default-language: Haskell2010 + other-extensions: + BangPatterns + CPP + DeriveDataTypeable + FlexibleContexts + FlexibleInstances + GADTs + KindSignatures + MagicHash + MultiParamTypeClasses + ScopedTypeVariables + Trustworthy + TypeOperators + UnliftedFFITypes + + ghc-options: -Wall -fwarn-tabs + + if impl(ghc >=9.0) + -- these flags may abort compilation with GHC-8.10 + -- https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3295 + ghc-options: -Winferred-safe-imports -Wmissing-safe-haskell-mode + +test-suite hashable-tests + type: exitcode-stdio-1.0 + hs-source-dirs: tests + main-is: Main.hs + other-modules: + Properties + Regress + + build-depends: + base + , bytestring + , ghc-prim + , hashable + , HUnit + , QuickCheck >=2.4.0.1 + , random >=1.0 && <1.3 + , test-framework >=0.3.3 + , test-framework-hunit + , test-framework-quickcheck2 >=0.2.9 + , text >=0.11.0.5 + + if !os(windows) + build-depends: unix + cpp-options: -DHAVE_MMAP + other-modules: Regress.Mmap + other-extensions: CApiFFI + + ghc-options: -Wall -fno-warn-orphans + default-language: Haskell2010 + +test-suite hashable-examples + type: exitcode-stdio-1.0 + build-depends: + base + , ghc-prim + , hashable + + hs-source-dirs: examples + main-is: Main.hs + default-language: Haskell2010 + +source-repository head + type: git + location: + https://github.com/haskell-unordered-containers/hashable.git diff --git a/cabal-testsuite/PackageTests/VersionPriority/repo/hashable-1.4.3.0/hashable.cabal b/cabal-testsuite/PackageTests/VersionPriority/repo/hashable-1.4.3.0/hashable.cabal new file mode 100644 index 00000000000..69efe15c086 --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/repo/hashable-1.4.3.0/hashable.cabal @@ -0,0 +1,188 @@ +cabal-version: 1.12 +name: hashable +version: 1.4.3.0 +synopsis: A class for types that can be converted to a hash value +description: + This package defines a class, 'Hashable', for types that + can be converted to a hash value. This class + exists for the benefit of hashing-based data + structures. The package provides instances for + basic types and a way to combine hash values. + . + The 'Hashable' 'hash' values are not guaranteed to be stable across library versions, operating systems or architectures. For stable hashing use named hashes: SHA256, CRC32 etc. + +homepage: http://github.com/haskell-unordered-containers/hashable + +-- SPDX-License-Identifier : BSD-3-Clause +license: BSD3 +license-file: LICENSE +author: + Milan Straka + Johan Tibell + +maintainer: Oleg Grenrus +bug-reports: + https://github.com/haskell-unordered-containers/hashable/issues + +stability: Provisional +category: Data +build-type: Simple +tested-with: + GHC ==8.2.2 + || ==8.4.4 + || ==8.6.5 + || ==8.8.3 + || ==8.10.4 + || ==8.10.7 + || ==9.0.1 + || ==9.0.2 + || ==9.2.5 + || ==9.4.4 + || ==9.6.1 + +extra-source-files: + CHANGES.md + include/HsHashable.h + README.md + +flag integer-gmp + description: + Are we using @integer-gmp@ to provide fast Integer instances? No effect on GHC-9.0 or later. + + manual: False + default: True + +flag random-initial-seed + description: + Randomly initialize the initial seed on each final executable invocation + This is useful for catching cases when you rely on (non-existent) + stability of hashable's hash functions. + This is not a security feature. + + manual: True + default: False + +library + exposed-modules: + Data.Hashable + Data.Hashable.Generic + Data.Hashable.Lifted + + other-modules: + Data.Hashable.Class + Data.Hashable.Generic.Instances + Data.Hashable.Imports + Data.Hashable.LowLevel + + c-sources: cbits/fnv.c + include-dirs: include + hs-source-dirs: src + build-depends: + -- REMOVED constraint on base for test + -- base >=4.10.1.0 && <4.19 + base + , bytestring >=0.10.8.2 && <0.12 + , containers >=0.5.10.2 && <0.7 + , deepseq >=1.4.3.0 && <1.5 + , filepath >=1.4.1.2 && <1.5 + , ghc-prim + , text >=1.2.3.0 && <1.3 || >=2.0 && <2.1 + + if !impl(ghc >=9.2) + build-depends: base-orphans >=0.8.6 && <0.10 + + if !impl(ghc >=9.4) + build-depends: data-array-byte >=0.1.0.1 && <0.2 + + -- Integer internals + if impl(ghc >=9) + build-depends: ghc-bignum >=1.0 && <1.4 + + if !impl(ghc >=9.0.2) + build-depends: ghc-bignum-orphans >=0.1 && <0.2 + + else + if flag(integer-gmp) + build-depends: integer-gmp >=0.4 && <1.1 + + else + -- this is needed for the automatic flag to be well-balanced + build-depends: integer-simple + + if (flag(random-initial-seed) && impl(ghc)) + cpp-options: -DHASHABLE_RANDOM_SEED=1 + + if os(windows) + c-sources: cbits-win/init.c + + else + c-sources: cbits-unix/init.c + + default-language: Haskell2010 + other-extensions: + BangPatterns + CPP + DeriveDataTypeable + FlexibleContexts + FlexibleInstances + GADTs + KindSignatures + MagicHash + MultiParamTypeClasses + ScopedTypeVariables + Trustworthy + TypeOperators + UnliftedFFITypes + + ghc-options: -Wall -fwarn-tabs + + if impl(ghc >=9.0) + -- these flags may abort compilation with GHC-8.10 + -- https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3295 + ghc-options: -Winferred-safe-imports -Wmissing-safe-haskell-mode + +test-suite hashable-tests + type: exitcode-stdio-1.0 + hs-source-dirs: tests + main-is: Main.hs + other-modules: + Properties + Regress + + build-depends: + base + , bytestring + , ghc-prim + , hashable + , HUnit + , QuickCheck >=2.4.0.1 + , random >=1.0 && <1.3 + , test-framework >=0.3.3 + , test-framework-hunit + , test-framework-quickcheck2 >=0.2.9 + , text >=0.11.0.5 + + if !os(windows) + build-depends: unix + cpp-options: -DHAVE_MMAP + other-modules: Regress.Mmap + other-extensions: CApiFFI + + ghc-options: -Wall -fno-warn-orphans + default-language: Haskell2010 + +test-suite hashable-examples + type: exitcode-stdio-1.0 + build-depends: + base + , ghc-prim + , hashable + + hs-source-dirs: examples + main-is: Main.hs + default-language: Haskell2010 + +source-repository head + type: git + location: + https://github.com/haskell-unordered-containers/hashable.git diff --git a/cabal-testsuite/PackageTests/VersionPriority/stackage-local.config b/cabal-testsuite/PackageTests/VersionPriority/stackage-local.config new file mode 100644 index 00000000000..23e32e2f5a8 --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/stackage-local.config @@ -0,0 +1,2 @@ +-- Same constraint as on stackage at https://www.stackage.org/nightly-2023-12-07/cabal.config +constraints: hashable ==1.4.3.0 diff --git a/cabal-testsuite/PackageTests/VersionPriority/stackage-web.config b/cabal-testsuite/PackageTests/VersionPriority/stackage-web.config new file mode 100644 index 00000000000..35603680c01 --- /dev/null +++ b/cabal-testsuite/PackageTests/VersionPriority/stackage-web.config @@ -0,0 +1 @@ +import: https://www.stackage.org/nightly-2023-12-07/cabal.config diff --git a/changelog.d/issue-9511 b/changelog.d/issue-9511 new file mode 100644 index 00000000000..c109314b383 --- /dev/null +++ b/changelog.d/issue-9511 @@ -0,0 +1,61 @@ +synopsis: Override imported package version equalities +description: + This change enables a project to take constraints from stackage without having + to download and comment out conflicting version equality constraints where we + might prefer a different version of a package than the resolver has. + + Stackage provides a `/cabal.config` for any resolver, such as + [nightly-2023-12-07/cabal.config](https://www.stackage.org/nightly-2023-12-07/cabal.config). + This is made up mostly of exact versions of packages, stipulated as version + equality constraints. For any package in the resolver where we want a + different version we're stuck as we can't add a new equality constraint for + a package without creating a constraint set that is impossible to solve. We + can't solve for two versions of the same package. + + ``` + -- cabal.project + constraints: hashable ==1.4.3.0 + constraints: hashable ==1.4.2.0 + ``` + + This change gives priority to version equality constraints that are less + imported (by default) and does so by only passing along the top priority + constraints (the least imported for any package) to the solver. Priority can + also be given to constraints so that the last version constraint for a package + wins. The command line option for this is `--version-win=latest|shallowest`. + + The lower priority version equality constraints are discarded. If + `nightly-2023-12-07` has `constraints: hashable ==1.4.3.0` then this fix will + effectively allow the local `cabal.project` to override that version and pick + another. + + ``` + -- cabal.project + import: https://www.stackage.org/nightly-2023-12-07/cabal.config + constraints: hashable ==1.4.2.0 + ``` + + With the following project and `--version-win=latest` the import from stackage + would have priority and `hashable ==1.4.3.0` would be passed to the solver. + + ``` + -- cabal.project + constraints: hashable ==1.4.2.0 + import: https://www.stackage.org/nightly-2023-12-07/cabal.config + ``` + + With `--version-win=shallowest`, the order of the import relative to the + constraints **does not matter** within a project because the project is at the + root of the import tree. Anything put there is top priority. + + The same relative precedence rule applies per-package down an import tree for + more complex import situations. Other constraints, such as flags, are not + touched by this fix so it may be possible to orphan some flags that relate to + versions of packages that get weeded out. + + With `--version-win=latest`, the order of the import relative to the + constraints **does matter**. + +packages: cabal-install +prs: #9510 +issues: #9511 \ No newline at end of file