mirror of
https://github.com/input-output-hk/foliage.git
synced 2024-12-02 07:54:45 +03:00
080197e9e2
1. Foliage takes as input a complete description of the index, where source distributions and revisions come with a timestamp. This allows us to recreate the entire index in a reproducible way. 2. Added a experimental command to import an index from a Hackage (as downloaded with Cabal). This was originally a testing/development need but there might be different use cases.
38 lines
1.0 KiB
Haskell
38 lines
1.0 KiB
Haskell
{-# LANGUAGE DeriveAnyClass #-}
|
|
{-# LANGUAGE DeriveGeneric #-}
|
|
{-# LANGUAGE DerivingStrategies #-}
|
|
|
|
module Foliage.Package
|
|
( PackageId (..),
|
|
parsePkgId,
|
|
pkgIdToTarGzName,
|
|
pkgIdToString,
|
|
pkgIdToHackageUrl,
|
|
)
|
|
where
|
|
|
|
import Data.Bifunctor
|
|
import Data.Tuple
|
|
import Development.Shake.Classes
|
|
import GHC.Generics
|
|
import System.FilePath
|
|
|
|
data PackageId = PackageId {pkgName :: String, pkgVersion :: String}
|
|
deriving (Eq, Ord, Show, Generic)
|
|
deriving anyclass (Binary, NFData, Hashable)
|
|
|
|
parsePkgId :: String -> PackageId
|
|
parsePkgId fn = PackageId (init pn) pv
|
|
where
|
|
(pn, pv) = swap $ bimap reverse reverse $ break (== '-') $ reverse fn
|
|
|
|
pkgIdToTarGzName :: PackageId -> FilePath
|
|
pkgIdToTarGzName pkgId = pkgIdToString pkgId <.> "tar.gz"
|
|
|
|
pkgIdToString :: PackageId -> String
|
|
pkgIdToString (PackageId name version) = name <> "-" <> version
|
|
|
|
pkgIdToHackageUrl :: PackageId -> String
|
|
pkgIdToHackageUrl pkgId =
|
|
"https://hackage.haskell.org/package" </> pkgIdToString pkgId </> pkgIdToString pkgId <.> "tar.gz"
|