Skip to content

Commit

Permalink
Opt-in on requiring the Hackage index be present
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Apr 15, 2019
1 parent faaf4e4 commit 56c2cea
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/Stack/Build/ConstructPlan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ addDep name = do
-- names. This code does not feel right.
let version = installedVersion installed
askPkgLoc = liftRIO $ do
mrev <- getLatestHackageRevision name version
mrev <- getLatestHackageRevision YesRequireHackageIndex name version
case mrev of
Nothing -> do
-- this could happen for GHC boot libraries missing from Hackage
Expand Down Expand Up @@ -658,7 +658,7 @@ addPackageDeps package = do
eres <- addDep depname
let getLatestApplicableVersionAndRev :: M (Maybe (Version, BlobKey))
getLatestApplicableVersionAndRev = do
vsAndRevs <- runRIO ctx $ getHackagePackageVersions UsePreferredVersions depname
vsAndRevs <- runRIO ctx $ getHackagePackageVersions YesRequireHackageIndex UsePreferredVersions depname
pure $ do
lappVer <- latestApplicableVersion range $ Map.keysSet vsAndRevs
revs <- Map.lookup lappVer vsAndRevs
Expand Down
6 changes: 3 additions & 3 deletions src/Stack/Build/Target.hs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ resolveRawTarget sma allLocs (ri, rt) =
]
-- Not present at all, add it from Hackage
Nothing -> do
mrev <- getLatestHackageRevision name version
mrev <- getLatestHackageRevision YesRequireHackageIndex name version
pure $ case mrev of
Nothing -> deferToConstructPlan name
Just (_rev, cfKey, treeKey) -> Right ResolveResult
Expand All @@ -355,7 +355,7 @@ resolveRawTarget sma allLocs (ri, rt) =
}

hackageLatest name = do
mloc <- getLatestHackageLocation name UsePreferredVersions
mloc <- getLatestHackageLocation YesRequireHackageIndex name UsePreferredVersions
pure $ case mloc of
Nothing -> deferToConstructPlan name
Just loc -> do
Expand All @@ -368,7 +368,7 @@ resolveRawTarget sma allLocs (ri, rt) =
}

hackageLatestRevision name version = do
mrev <- getLatestHackageRevision name version
mrev <- getLatestHackageRevision YesRequireHackageIndex name version
pure $ case mrev of
Nothing -> deferToConstructPlan name
Just (_rev, cfKey, treeKey) -> Right ResolveResult
Expand Down
2 changes: 1 addition & 1 deletion src/Stack/Hoogle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ hoogleCmd (args,setup,rebuild,startServer) =
installHoogle :: RIO EnvConfig ()
installHoogle = do
hooglePackageIdentifier <- do
mversion <- getLatestHackageVersion hooglePackageName UsePreferredVersions
mversion <- getLatestHackageVersion YesRequireHackageIndex hooglePackageName UsePreferredVersions

-- FIXME For a while, we've been following the logic of
-- taking the latest Hoogle version available. However, we
Expand Down
2 changes: 1 addition & 1 deletion src/Stack/Runners.hs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ shouldUpgradeCheck = do
let yesterday = addUTCTime (-24 * 60 * 60) now
checks <- upgradeChecksSince yesterday
when (checks == 0) $ do
mversion <- getLatestHackageVersion "stack" UsePreferredVersions -- FIXME ensure it doesn't force an update ever
mversion <- getLatestHackageVersion NoRequireHackageIndex "stack" UsePreferredVersions
case mversion of
Just (PackageIdentifierRevision _ version _) | version > mkVersion' Paths_stack.version -> do
logWarn "<<<<<<<<<<<<<<<<<<"
Expand Down
4 changes: 2 additions & 2 deletions src/Stack/Unpack.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ unpackPackages mSnapshot dest input = do

toLocNoSnapshot :: PackageName -> RIO env (Either String (PackageLocationImmutable, PackageIdentifier))
toLocNoSnapshot name = do
mloc1 <- getLatestHackageLocation name UsePreferredVersions
mloc1 <- getLatestHackageLocation YesRequireHackageIndex name UsePreferredVersions
mloc <-
case mloc1 of
Just _ -> pure mloc1
Nothing -> do
updated <- updateHackageIndex $ Just $ "Could not find package " <> fromString (packageNameString name) <> ", updating"
case updated of
UpdateOccurred -> getLatestHackageLocation name UsePreferredVersions
UpdateOccurred -> getLatestHackageLocation YesRequireHackageIndex name UsePreferredVersions
NoUpdateOccurred -> pure Nothing
case mloc of
Nothing -> do
Expand Down
4 changes: 2 additions & 2 deletions src/Stack/Upgrade.hs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ sourceUpgrade builtHash (SourceOpts gitRepo) =
Nothing -> withConfig NoReexec $ do
void $ updateHackageIndex
$ Just "Updating index to make sure we find the latest Stack version"
mversion <- getLatestHackageVersion "stack" UsePreferredVersions
mversion <- getLatestHackageVersion YesRequireHackageIndex "stack" UsePreferredVersions
(PackageIdentifierRevision _ version _) <-
case mversion of
Nothing -> throwString "No stack found in package indices"
Expand All @@ -223,7 +223,7 @@ sourceUpgrade builtHash (SourceOpts gitRepo) =
else do
suffix <- parseRelDir $ "stack-" ++ versionString version
let dir = tmp </> suffix
mrev <- getLatestHackageRevision "stack" version
mrev <- getLatestHackageRevision YesRequireHackageIndex "stack" version
case mrev of
Nothing -> throwString "Latest version with no revision"
Just (_rev, cfKey, treeKey) -> do
Expand Down
2 changes: 1 addition & 1 deletion subs/curator/src/Curator/Snapshot.hs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ toLoc
toLoc name pc =
case pcSource pc of
PSHackage (HackageSource mrange mrequiredLatest revisions) -> do
versions <- getHackagePackageVersions IgnorePreferredVersions name -- don't follow the preferred versions on Hackage, give curators more control
versions <- getHackagePackageVersions YesRequireHackageIndex IgnorePreferredVersions name -- don't follow the preferred versions on Hackage, give curators more control
when (Map.null versions) $ error $ "Package not found on Hackage: " ++ packageNameString name
for_ mrequiredLatest $ \required ->
case Map.maxViewWithKey versions of
Expand Down
22 changes: 13 additions & 9 deletions subs/pantry/src/Pantry.hs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ module Pantry
-- * Hackage index
, updateHackageIndex
, DidUpdateOccur (..)
, RequireHackageIndex (..)
, hackageIndexTarballL
, getHackagePackageVersions
, getLatestHackageVersion
Expand Down Expand Up @@ -267,11 +268,12 @@ defaultHackageSecurityConfig = HackageSecurityConfig
-- @since 0.1.0.0
getLatestHackageVersion
:: (HasPantryConfig env, HasLogFunc env)
=> PackageName -- ^ package name
=> RequireHackageIndex
-> PackageName -- ^ package name
-> UsePreferredVersions
-> RIO env (Maybe PackageIdentifierRevision)
getLatestHackageVersion name preferred =
((fmap fst . Map.maxViewWithKey) >=> go) <$> getHackagePackageVersions preferred name
getLatestHackageVersion req name preferred =
((fmap fst . Map.maxViewWithKey) >=> go) <$> getHackagePackageVersions req preferred name
where
go (version, m) = do
(_rev, BlobKey sha size) <- fst <$> Map.maxViewWithKey m
Expand All @@ -283,12 +285,13 @@ getLatestHackageVersion name preferred =
-- @since 0.1.0.0
getLatestHackageLocation
:: (HasPantryConfig env, HasLogFunc env, HasProcessContext env)
=> PackageName -- ^ package name
=> RequireHackageIndex
-> PackageName -- ^ package name
-> UsePreferredVersions
-> RIO env (Maybe PackageLocationImmutable)
getLatestHackageLocation name preferred = do
getLatestHackageLocation req name preferred = do
mversion <-
fmap fst . Map.maxViewWithKey <$> getHackagePackageVersions preferred name
fmap fst . Map.maxViewWithKey <$> getHackagePackageVersions req preferred name
let mVerCfKey = do
(version, revisions) <- mversion
(_rev, cfKey) <- fst <$> Map.maxViewWithKey revisions
Expand All @@ -305,11 +308,12 @@ getLatestHackageLocation name preferred = do
-- @since 0.1.0.0
getLatestHackageRevision
:: (HasPantryConfig env, HasLogFunc env, HasProcessContext env)
=> PackageName -- ^ package name
=> RequireHackageIndex
-> PackageName -- ^ package name
-> Version
-> RIO env (Maybe (Revision, BlobKey, TreeKey))
getLatestHackageRevision name version = do
revisions <- getHackagePackageVersionRevisions name version
getLatestHackageRevision req name version = do
revisions <- getHackagePackageVersionRevisions req name version
case fmap fst $ Map.maxViewWithKey revisions of
Nothing -> pure Nothing
Just (revision, cfKey@(BlobKey sha size)) -> do
Expand Down
41 changes: 30 additions & 11 deletions subs/pantry/src/Pantry/Hackage.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
module Pantry.Hackage
( updateHackageIndex
, DidUpdateOccur (..)
, RequireHackageIndex (..)
, hackageIndexTarballL
, getHackageTarball
, getHackageTarballKey
Expand Down Expand Up @@ -335,7 +336,7 @@ fuzzyLookupCandidates
-> Version
-> RIO env FuzzyResults
fuzzyLookupCandidates name ver0 = do
m <- getHackagePackageVersions UsePreferredVersions name
m <- getHackagePackageVersions YesRequireHackageIndex UsePreferredVersions name
if Map.null m
then FRNameNotFound <$> getHackageTypoCorrections name
else
Expand Down Expand Up @@ -390,18 +391,37 @@ getHackageTypoCorrections name1 =
data UsePreferredVersions = UsePreferredVersions | IgnorePreferredVersions
deriving Show

-- | Require that the Hackage index is populated.
--
-- @since 0.1.0.0
data RequireHackageIndex
= YesRequireHackageIndex
-- ^ If there is nothing in the Hackage index, then perform an update
| NoRequireHackageIndex
-- ^ Do not perform an update
deriving Show

initializeIndex
:: (HasPantryConfig env, HasLogFunc env)
=> RequireHackageIndex
-> RIO env ()
initializeIndex NoRequireHackageIndex = pure ()
initializeIndex YesRequireHackageIndex = do
cabalCount <- withStorage countHackageCabals
when (cabalCount == 0) $ void $
updateHackageIndex $ Just $ "No information from Hackage index, updating"

-- | Returns the versions of the package available on Hackage.
--
-- @since 0.1.0.0
getHackagePackageVersions
:: (HasPantryConfig env, HasLogFunc env)
=> UsePreferredVersions
=> RequireHackageIndex
-> UsePreferredVersions
-> PackageName -- ^ package name
-> RIO env (Map Version (Map Revision BlobKey))
getHackagePackageVersions usePreferred name = do
cabalCount <- withStorage countHackageCabals
when (cabalCount == 0) $ void $
updateHackageIndex $ Just $ "No information from Hackage index, updating"
getHackagePackageVersions req usePreferred name = do
initializeIndex req
withStorage $ do
mpreferred <-
case usePreferred of
Expand All @@ -420,13 +440,12 @@ getHackagePackageVersions usePreferred name = do
-- @since 0.1.0.0
getHackagePackageVersionRevisions
:: (HasPantryConfig env, HasLogFunc env)
=> PackageName -- ^ package name
=> RequireHackageIndex
-> PackageName -- ^ package name
-> Version -- ^ package version
-> RIO env (Map Revision BlobKey)
getHackagePackageVersionRevisions name version = do
cabalCount <- withStorage countHackageCabals
when (cabalCount == 0) $ void $
updateHackageIndex $ Just $ "No information from Hackage index, updating"
getHackagePackageVersionRevisions req name version = do
initializeIndex req
withStorage $
Map.map snd <$> loadHackagePackageVersion name version

Expand Down

0 comments on commit 56c2cea

Please sign in to comment.