Skip to content

Commit

Permalink
Merge pull request #4723 from lehins/changes-for-stackage-server
Browse files Browse the repository at this point in the history
Additions necessary for integration of pantry into stackage-server:
  • Loading branch information
snoyberg authored Apr 25, 2019
2 parents 2cb309f + 8a57805 commit dfbf85a
Show file tree
Hide file tree
Showing 10 changed files with 380 additions and 230 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ tags
/etc/scripts/stack-scripts.cabal
.hspec-failures
better-cache/
/subs/*/*.cabal
1 change: 1 addition & 0 deletions subs/pantry/.hindent.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
indent-size: 2
5 changes: 5 additions & 0 deletions subs/pantry/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ dependencies:
- directory
- filepath

ghc-options:
- -Wall

library:
source-dirs: src/
when:
Expand All @@ -104,6 +107,8 @@ library:
# For testing
- Pantry.Internal
- Pantry.Internal.StaticBytes
# For stackage-server
- Pantry.Internal.Stackage

# FIXME must be removed from pantry!
- Data.Aeson.Extended
Expand Down
22 changes: 11 additions & 11 deletions subs/pantry/src/Pantry.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE ViewPatterns #-}
-- | Content addressable Haskell package management, providing for
-- secure, reproducible acquisition of Haskell package contents and
-- metadata.
Expand Down Expand Up @@ -179,7 +178,7 @@ import qualified RIO.FilePath as FilePath
import Pantry.Archive
import Pantry.Repo
import qualified Pantry.SHA256 as SHA256
import Pantry.Storage
import Pantry.Storage hiding (TreeEntry, PackageName, Version)
import Pantry.Tree
import Pantry.Types
import Pantry.Hackage
Expand Down Expand Up @@ -300,8 +299,8 @@ getLatestHackageLocation req name preferred = do

forM mVerCfKey $ \(version, cfKey@(BlobKey sha size)) -> do
let pir = PackageIdentifierRevision name version (CFIHash sha (Just size))
treeKey <- getHackageTarballKey pir
pure $ PLIHackage (PackageIdentifier name version) cfKey treeKey
treeKey' <- getHackageTarballKey pir
pure $ PLIHackage (PackageIdentifier name version) cfKey treeKey'

-- | Returns the latest revision of the given package version available from
-- Hackage.
Expand All @@ -319,8 +318,8 @@ getLatestHackageRevision req name version = do
Nothing -> pure Nothing
Just (revision, cfKey@(BlobKey sha size)) -> do
let cfi = CFIHash sha (Just size)
treeKey <- getHackageTarballKey (PackageIdentifierRevision name version cfi)
return $ Just (revision, cfKey, treeKey)
treeKey' <- getHackageTarballKey (PackageIdentifierRevision name version cfi)
return $ Just (revision, cfKey, treeKey')

fetchTreeKeys
:: (HasPantryConfig env, HasLogFunc env, Foldable f)
Expand Down Expand Up @@ -703,7 +702,8 @@ loadPackage
:: (HasPantryConfig env, HasLogFunc env, HasProcessContext env)
=> PackageLocationImmutable
-> RIO env Package
loadPackage (PLIHackage ident cfHash tree) = getHackageTarball (pirForHash ident cfHash) (Just tree)
loadPackage (PLIHackage ident cfHash tree) =
htrPackage <$> getHackageTarball (pirForHash ident cfHash) (Just tree)
loadPackage pli@(PLIArchive archive pm) = getArchivePackage (toRawPLI pli) (toRawArchive archive) (toRawPM pm)
loadPackage (PLIRepo repo pm) = getRepo repo (toRawPM pm)

Expand All @@ -714,7 +714,7 @@ loadPackageRaw
:: (HasPantryConfig env, HasLogFunc env, HasProcessContext env)
=> RawPackageLocationImmutable
-> RIO env Package
loadPackageRaw (RPLIHackage pir mtree) = getHackageTarball pir mtree
loadPackageRaw (RPLIHackage pir mtree) = htrPackage <$> getHackageTarball pir mtree
loadPackageRaw rpli@(RPLIArchive archive pm) = getArchivePackage rpli archive pm
loadPackageRaw (RPLIRepo repo rpm) = getRepo repo rpm

Expand All @@ -740,8 +740,8 @@ completePackageLocation (RPLIHackage pir0@(PackageIdentifierRevision name versio
pir = PackageIdentifierRevision name version cfi
logDebug $ "Added in cabal file hash: " <> display pir
pure (pir, BlobKey sha size)
treeKey <- getHackageTarballKey pir
pure $ PLIHackage (PackageIdentifier name version) cfKey treeKey
treeKey' <- getHackageTarballKey pir
pure $ PLIHackage (PackageIdentifier name version) cfKey treeKey'
completePackageLocation pl@(RPLIArchive archive rpm) = do
-- getArchive checks archive and package metadata
(sha, size, package) <- getArchive pl archive rpm
Expand Down Expand Up @@ -1345,7 +1345,7 @@ getRawPackageLocationTreeKey
-> RIO env TreeKey
getRawPackageLocationTreeKey pl =
case getRawTreeKey pl of
Just treeKey -> pure treeKey
Just treeKey' -> pure treeKey'
Nothing ->
case pl of
RPLIHackage pir _ -> getHackageTarballKey pir
Expand Down
6 changes: 3 additions & 3 deletions subs/pantry/src/Pantry/Archive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Pantry.Archive

import RIO
import qualified Pantry.SHA256 as SHA256
import Pantry.Storage
import Pantry.Storage hiding (Tree, TreeEntry)
import Pantry.Tree
import Pantry.Types
import RIO.Process
Expand Down Expand Up @@ -447,7 +447,7 @@ parseArchive rpli archive fp = do
BFCabal _ _ -> when (buildFilePath /= cabalFileName name) $ throwIO $ WrongCabalFileName rpli buildFilePath name
_ -> return ()
-- It's good! Store the tree, let's bounce
(tid, treeKey) <- withStorage $ storeTree rpli ident tree buildFile
(tid, treeKey') <- withStorage $ storeTree rpli ident tree buildFile
packageCabal <- case buildFile of
BFCabal _ _ -> pure $ PCCabalFile buildFileEntry
BFHpack _ -> do
Expand All @@ -458,7 +458,7 @@ parseArchive rpli archive fp = do
let cabalTreeEntry = TreeEntry cabalKey (teType buildFileEntry)
pure $ PCHpack $ PHpack { phOriginal = buildFileEntry, phGenerated = cabalTreeEntry, phVersion = hpackSoftwareVersion}
pure Package
{ packageTreeKey = treeKey
{ packageTreeKey = treeKey'
, packageTree = tree
, packageCabalEntry = packageCabal
, packageIdent = ident
Expand Down
Loading

0 comments on commit dfbf85a

Please sign in to comment.