Permalink
Browse files

Work on the Portage/ implementation

  • Loading branch information...
1 parent 404ca17 commit 6dea19e9392f115bd4b57fa818429245833d6a5a @kolmodin kolmodin committed Jan 26, 2009
Showing with 62 additions and 20 deletions.
  1. +19 −0 Portage/Cabal.hs
  2. +26 −6 Portage/Overlay.hs
  3. +17 −14 Portage/PackageId.hs
View
@@ -0,0 +1,19 @@
+module Portage.Cabal
+ (fromOverlay) where
+
+import Data.List as List
+import Data.Maybe
+import qualified Data.Map as Map
+
+import qualified Distribution.Package as Cabal
+import qualified Distribution.Simple.PackageIndex as Cabal
+
+import qualified Portage.Overlay as Portage
+import qualified Portage.PackageId as Portage
+
+fromOverlay :: Portage.Overlay -> Cabal.PackageIndex Portage.ExistingEbuild
+fromOverlay overlay = Cabal.fromList $
+ [ ebuild
+ | (pn, ebuilds) <- Map.toAscList (Portage.overlayMap overlay)
+ , ebuild <- ebuilds
+ ]
View
@@ -1,12 +1,19 @@
-module Portage.Overlay where
+module Portage.Overlay
+ ( ExistingEbuild(..)
+ , Overlay(..)
+ , load, loadLazy
+ , reduceOverlay
+ , inOverlay
+ )
+ where
import qualified Portage.PackageId as Portage
import qualified Portage.Version as Portage
import qualified Distribution.Package as Cabal
import qualified Distribution.Simple.PackageIndex as PackageIndex
-import Distribution.Simple.PackageIndex (PackageIndex)
+-- import Distribution.Simple.PackageIndex (PackageIndex)
import Distribution.Text (simpleParse, display)
import Distribution.Simple.Utils ( comparing, equating )
@@ -42,6 +49,20 @@ data Overlay = Overlay {
-- overlayIndex :: PackageIndex ExistingEbuild
} deriving Show
+inOverlay :: Overlay -> Cabal.PackageId -> Bool
+inOverlay overlay pkgId = not (Map.null packages)
+ where
+ packages = Map.filterWithKey
+ (\(Portage.PackageName _cat overlay_pn) ebuilds ->
+ let cabal_pn = Cabal.pkgName pkgId
+ ebs = [ ()
+ | e <- ebuilds
+ , let ebuild_cabal_id = ebuildCabalId e
+ , ebuild_cabal_id == pkgId
+ ]
+ in cabal_pn == overlay_pn && (not (null ebs))) om
+ om = overlayMap overlay
+
load :: FilePath -> IO Overlay
load dir = fmap (mkOverlay . readOverlay) (getDirectoryTree dir)
where
@@ -85,9 +106,9 @@ reduceOverlay overlay = overlay { overlayMap = Map.map reduceVersions (overlayMa
versionNumbers (Portage.Version nums _ _ _) = nums
reduceVersions :: [ExistingEbuild] -> [ExistingEbuild]
reduceVersions ebuilds = -- gah!
- map (maximumBy (comparing (Portage.packageVersion . ebuildId)))
- . groupBy (equating (versionNumbers . Portage.packageVersion . ebuildId))
- . sortBy (comparing (Portage.packageVersion . ebuildId))
+ map (maximumBy (comparing (Portage.pkgVersion . ebuildId)))
+ . groupBy (equating (versionNumbers . Portage.pkgVersion . ebuildId))
+ . sortBy (comparing (Portage.pkgVersion . ebuildId))
$ ebuilds
readOverlayByPackage :: DirectoryTree -> [(Portage.PackageName, [Portage.Version])]
@@ -136,7 +157,6 @@ getDirectoryTree = dirEntries
where
dirEntries :: FilePath -> IO [DirectoryEntry]
dirEntries dir = do
- putStrLn dir
names <- getDirectoryContents dir
sequence
[ do isDirectory <- doesDirectoryExist path
View
@@ -4,36 +4,38 @@ module Portage.PackageId (
Category(..),
PackageName(..),
PackageId(..),
- PN(..),
fromCabalPackageId,
toCabalPackageId,
parseFriendlyPackage
) where
-import qualified Portage.Version as Portage
+import qualified Data.Char as Char (isAlphaNum, isDigit, isSpace, toLower)
+import Data.List (intersperse)
+import qualified Text.PrettyPrint as Disp
+import Text.PrettyPrint ((<>))
import qualified Distribution.Package as Cabal
-import Distribution.Text (Text(..))
+import Distribution.Text (Text(..),display)
import qualified Distribution.Compat.ReadP as Parse
+
+import qualified Portage.Version as Portage
+
import qualified Text.PrettyPrint as Disp
import Text.PrettyPrint ((<>))
import qualified Data.Char as Char (isAlphaNum, isDigit, isSpace, toLower)
import Data.List (intersperse)
-import Index (pName, mkPackage)
newtype Category = Category String
deriving (Eq, Ord, Show, Read)
-data PackageName = PackageName Category PN
- deriving (Eq, Ord, Show, Read)
-
-data PackageId = PackageId { packageId :: PackageName, packageVersion :: Portage.Version }
+data PackageName = PackageName Category Cabal.PackageName
deriving (Eq, Ord, Show, Read)
-data PN = PN String -- replace with Cabal.PackageName once we use Cabal>=1.5
+data PackageId = PackageId { packageId :: PackageName, pkgVersion :: Portage.Version }
deriving (Eq, Ord, Show, Read)
+{-
instance Text PN where
disp (PN n) = Disp.text n
parse = do
@@ -45,17 +47,18 @@ instance Text PN where
if all Char.isDigit cs then Parse.pfail else return cs
-- each component must contain an alphabetic character, to avoid
-- ambiguity in identifiers like foo-1 (the 1 is the version number).
+-}
fromCabalPackageId :: Category -> Cabal.PackageIdentifier -> PackageId
fromCabalPackageId category (Cabal.PackageIdentifier name version) =
- PackageId (PackageName category (PN (lowercase . pName $ name)))
+ PackageId (PackageName category (lowercase name))
(Portage.fromCabalVersion version)
where
- lowercase = map Char.toLower
+ lowercase (Cabal.PackageName name) = Cabal.PackageName (map Char.toLower name)
toCabalPackageId :: PackageId -> Maybe Cabal.PackageIdentifier
-toCabalPackageId (PackageId (PackageName _cat (PN name)) version) =
- fmap (Cabal.PackageIdentifier (mkPackage name))
+toCabalPackageId (PackageId (PackageName _cat name) version) =
+ fmap (Cabal.PackageIdentifier name)
(Portage.toCabalVersion version)
instance Text Category where
@@ -84,7 +87,7 @@ instance Text PackageId where
version <- parse
return (PackageId name version)
-parseFriendlyPackage :: String -> Maybe (Maybe Category, PN, Maybe Portage.Version)
+parseFriendlyPackage :: String -> Maybe (Maybe Category, Cabal.PackageName, Maybe Portage.Version)
parseFriendlyPackage str =
case [ p | (p,s) <- Parse.readP_to_S parser str
, all Char.isSpace s ] of

0 comments on commit 6dea19e

Please sign in to comment.