Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Distinguish between deprecated and non-preferred versions in the package index #1345

Open
grayjay opened this issue Nov 23, 2024 · 0 comments

Comments

@grayjay
Copy link
Contributor

grayjay commented Nov 23, 2024

Hackage shows deprecated and preferred versions on each package page, but it seems to combine the two types of version ranges in the package index. This means that cabal can't distinguish between versions that are deprecated and versions that are only non-preferred. It would be great to add more functionality to cabal related to identifying and avoiding deprecated versions. Here is an example of an issue that could be solved: haskell/cabal#10097

Adding preferred versions to the index:

updateIndexPackagePreferredVersions :: MonadIO m => PackageName -> PreferredInfo -> m ()
updateIndexPackagePreferredVersions pkgname prefinfo = do
now <- liftIO getCurrentTime
let prefEntryName = display pkgname </> "preferred-versions"
prefContent = fromMaybe "" $
formatSinglePreferredVersions pkgname prefinfo
updateArchiveIndexEntry prefEntryName (BS.pack prefContent) now

Formatting deprecated/preferred versions for one package:

formatSinglePreferredVersions :: PackageName -> PreferredInfo -> Maybe String
formatSinglePreferredVersions pkgname pref =
display . (\vr -> Dependency pkgname vr mainLibSet) <$> sumRange pref

PreferredInfo, with sumRange field for merged version ranges:

data PreferredInfo = PreferredInfo {
preferredRanges :: [VersionRange],
deprecatedVersions :: [Version],
sumRange :: Maybe VersionRange -- cached form of 'consolidateRanges' below
} deriving (Typeable, Show, Eq)

Merging version ranges:

consolidateRanges :: [VersionRange] -> [Version] -> Maybe VersionRange
consolidateRanges ranges depr =
let range = simplifyVersionRange $ foldr intersectVersionRanges anyVersion (map notThisVersion depr ++ ranges)
in if isAnyVersion range || isNoVersion range
then Nothing
else Just range

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant