Permalink
Browse files

Tiny cleanup about different Version structures. Add rdepend to ebuild.

And document a bit on how RDEPEND, DEPEND and BUILDTOOLS relate.
  • Loading branch information...
1 parent 4543561 commit 6956e2f09760ae715acb1b1e28e6d89e29bba7b7 @kolmodin kolmodin committed Aug 3, 2009
Showing with 90 additions and 41 deletions.
  1. +12 −38 Cabal2Ebuild.hs
  2. +43 −3 Merge.hs
  3. +34 −0 Portage/Dependency.hs
  4. +1 −0 hackport.cabal
View
@@ -39,10 +39,13 @@ import qualified Distribution.Text as Cabal (display)
--import qualified Distribution.Compiler as Cabal (CompilerFlavor(..))
import Data.Char (toLower,isUpper)
-import Data.List (intercalate, groupBy, partition, nub, sortBy, init, last)
+import Data.List (groupBy, partition, nub, sortBy, init, last)
import Data.Ord (comparing)
import Data.Maybe (catMaybes, fromJust)
+import Portage.Dependency
+import Portage.Version
+
data EBuild = EBuild {
name :: String,
version :: String,
@@ -54,26 +57,13 @@ data EBuild = EBuild {
keywords :: [String],
iuse :: [String],
depend :: [Dependency],
+ rdepend :: [Dependency],
features :: [String],
-- comments on various fields for communicating stuff to the user
licenseComments :: String,
my_pn :: Maybe String --If the package's name contains upper-case
}
-type Package = String
-newtype Version = Version [Int] deriving (Ord, Eq)
-type UseFlag = String
-data Dependency = AnyVersionOf Package
- | ThisVersionOf Version Package -- =package-version
- | LaterVersionOf Version Package -- >package-version
- | EarlierVersionOf Version Package -- <package-version
- | OrLaterVersionOf Version Package -- >=package-version
- | OrEarlierVersionOf Version Package -- <=package-version
- | DependEither Dependency Dependency -- depend || depend
- | DependIfUse UseFlag Dependency -- use? ( depend )
- | ThisMajorOf Version Package -- =package-version*
- deriving (Eq,Show)
-
ebuildTemplate :: EBuild
ebuildTemplate = EBuild {
name = "foobar",
@@ -86,6 +76,7 @@ ebuildTemplate = EBuild {
keywords = ["~amd64","~x86"],
iuse = [],
depend = [],
+ rdepend = [],
features = [],
licenseComments = "",
my_pn = Nothing
@@ -116,7 +107,7 @@ cabal2ebuild pkg = ebuildTemplate {
cabalPkgName = Cabal.display $ Cabal.pkgName (Cabal.package pkg)
defaultDepGHC :: Dependency
-defaultDepGHC = OrLaterVersionOf (Version [6,6,1]) "dev-lang/ghc"
+defaultDepGHC = OrLaterVersionOf (Version [6,6,1] Nothing [] 0) "dev-lang/ghc"
-- map the cabal license type to the gentoo license string format
convertLicense :: Cabal.License -> String
@@ -165,12 +156,9 @@ convertDependency (Cabal.Dependency pname versionRange)
convert (Cabal.UnionVersionRanges r1 r2)
= DependEither (convert r1) (convert r2)
--- converts Cabal versiion type to hackopr version
+-- converts Cabal version type to hackport version
cabalVtoHPv :: Cabal.Version -> Version
-cabalVtoHPv = Version . Cabal.versionBranch
-
-instance Show Version where
- show (Version v) = intercalate "." $ map show v
+cabalVtoHPv = (\v -> Version v Nothing [] 0) . Cabal.versionBranch
coreLibs :: [Cabal.PackageName]
coreLibs = map Cabal.PackageName
@@ -231,20 +219,6 @@ showEBuild ebuild =
$ []
where replaceVars = replaceCommonVars (name ebuild) (my_pn ebuild) (version ebuild)
-showDepend :: Dependency -> Package
-showDepend (AnyVersionOf p) = p
-showDepend (ThisVersionOf v p) = "~" ++ p ++ "-" ++ show v
-showDepend (LaterVersionOf v p) = ">" ++ p ++ "-" ++ show v
-showDepend (EarlierVersionOf v p) = "<" ++ p ++ "-" ++ show v
-showDepend (OrLaterVersionOf v p) = ">=" ++ p ++ "-" ++ show v
-showDepend (OrEarlierVersionOf v p) = "<=" ++ p ++ "-" ++ show v
-showDepend (DependEither dep1 dep2) = showDepend dep1
- ++ " || " ++ showDepend dep2
-showDepend (DependIfUse useflag dep@(DependEither _ _))
- = useflag ++ "? " ++ showDepend dep
-showDepend (DependIfUse useflag dep) = useflag ++ "? ( " ++ showDepend dep++ " )"
-showDepend (ThisMajorOf v p) = "=" ++ p ++ "-" ++ show v ++ "*"
-
ss :: String -> String -> String
ss = showString
@@ -326,10 +300,10 @@ simplify_group_table p Nothing Nothing Nothing (Just v) Nothing = [OrEarl
simplify_group_table p Nothing Nothing Nothing Nothing (Just v) = [ThisVersionOf v p]
-- 2) simplification passes
-simplify_group_table p (Just (Version v1)) Nothing (Just (Version v2)) Nothing Nothing
+simplify_group_table p (Just (Version v1 _ _ _)) Nothing (Just (Version v2 _ _ _)) Nothing Nothing
-- specian case: >=a-v.N a<v.(N+1) => =a-v.N*
- | (init v1 == init v2) && (last v2 == last v1 + 1) = [ThisMajorOf (Version v1) p]
- | otherwise = [OrLaterVersionOf (Version v1) p, EarlierVersionOf (Version v2) p]
+ | (init v1 == init v2) && (last v2 == last v1 + 1) = [ThisMajorOf (Version v1 Nothing [] 0) p]
+ | otherwise = [OrLaterVersionOf (Version v1 Nothing [] 0) p, EarlierVersionOf (Version v2 Nothing [] 0) p]
-- TODO: simplify constraints of type: >=a-v1; > a-v2 and such
View
@@ -1,12 +1,48 @@
{-# OPTIONS -XPatternGuards #-}
+{- | Merge a package from hackage to an ebuild.
+
+Merging a library
+=================
+
+Compile time:
+ ghc
+ cabal
+ build tools
+ deps
+ extra-libs (c-libs)
+
+Run time:
+ deps
+ extra-libs (c-libs)
+
+RDEPEND="${DEPS} ${EXTRALIBS}"
+DEPEND="${RDEPEND} ghc cabal ${BUILDTOOLS}"
+
+Merging an executable
+=====================
+Packages with both executable and library must be treated as libraries, as it will impose a stricter DEPEND.
+
+Compile time:
+ ghc
+ cabal
+ build tools
+ deps
+ extra-libs (c-libs)
+
+Run time:
+ extra-libs (c-libs)
+
+RDEPEND="${EXTRALIBS}"
+DEPEND="${RDEPEND} ghc cabal ${BUILDTOOLS}"
+
+-}
module Merge where
import Control.Monad.Error
import Control.Exception
import Data.Char
import Data.Maybe
import Data.List
-import Data.Version
import Distribution.Package
import Distribution.Compiler (CompilerId(..), CompilerFlavor(GHC))
import Distribution.PackageDescription ( PackageDescription(..)
@@ -32,7 +68,6 @@ import qualified Data.Map as Map
import qualified Cabal2Ebuild as E
import Error as E
-import Overlays
import qualified Distribution.Package as Cabal
import qualified Distribution.Version as Cabal
@@ -221,7 +256,7 @@ merge verbosity repo serverURI args overlayPath = do
]
(Nothing :: Maybe (PackageIndex PackageIdentifier))
buildOS buildArch
- (CompilerId GHC (Version [6,10,4] []))
+ (CompilerId GHC (Cabal.Version [6,10,4] []))
[] pkgGenericDesc
pkgDesc = let deps = [ Dependency pn (simplifyVersionRange vr)
| Dependency pn vr <- buildDepends pkgDesc0
@@ -267,6 +302,9 @@ merge verbosity repo serverURI args overlayPath = do
addDeps :: [E.Dependency] -> EBuild -> EBuild
addDeps d e = e { depend = depend e ++ d }
+addRDeps :: [E.Dependency] -> EBuild -> EBuild
+addRDeps d e = e { rdepend = rdepend e ++ d }
+
findCLibs :: Verbosity -> (String -> Maybe E.Dependency) -> PackageDescription -> IO [E.Dependency]
findCLibs verbosity portageResolver (PackageDescription { library = lib, executables = exes }) = do
debug verbosity "Mapping extra-libraries into portage packages..."
@@ -299,6 +337,8 @@ staticTranslateExtraLib lib = lookup lib m
where
m = [ ("z", E.AnyVersionOf "sys-libs/zlib")
, ("bz2", E.AnyVersionOf "sys-libs/bzlib")
+ , ("mysqlclient", E.LaterVersionOf (Portage.Version [4,0] Nothing [] 0) "virtual/mysql")
+ , ("pq", E.LaterVersionOf (Portage.Version [7] Nothing [] 0) "virtual/postgresql-base")
]
buildToolsDeps :: PackageDescription -> [Cabal.Dependency]
View
@@ -0,0 +1,34 @@
+module Portage.Dependency where
+
+import Portage.Version
+import Distribution.Text (display)
+
+type Package = String
+type UseFlag = String
+
+data Dependency = AnyVersionOf Package
+ | ThisVersionOf Version Package -- =package-version
+ | LaterVersionOf Version Package -- >package-version
+ | EarlierVersionOf Version Package -- <package-version
+ | OrLaterVersionOf Version Package -- >=package-version
+ | OrEarlierVersionOf Version Package -- <=package-version
+ | DependEither Dependency Dependency -- depend || depend
+ | DependIfUse UseFlag Dependency -- use? ( depend )
+ | ThisMajorOf Version Package -- =package-version*
+ deriving (Eq,Show)
+
+showDepend :: Dependency -> Package
+showDepend (AnyVersionOf p) = p
+showDepend (ThisVersionOf v p) = "~" ++ p ++ "-" ++ display v
+showDepend (LaterVersionOf v p) = ">" ++ p ++ "-" ++ display v
+showDepend (EarlierVersionOf v p) = "<" ++ p ++ "-" ++ display v
+showDepend (OrLaterVersionOf v p) = ">=" ++ p ++ "-" ++ display v
+showDepend (OrEarlierVersionOf v p) = "<=" ++ p ++ "-" ++ display v
+showDepend (DependEither dep1 dep2) = showDepend dep1
+ ++ " || " ++ showDepend dep2
+showDepend (DependIfUse useflag dep@(DependEither _ _))
+ = useflag ++ "? " ++ showDepend dep
+showDepend (DependIfUse useflag dep) = useflag ++ "? ( " ++ showDepend dep++ " )"
+showDepend (ThisMajorOf v p) = "=" ++ p ++ "-" ++ display v ++ "*"
+
+
View
@@ -58,6 +58,7 @@ Executable hackport
P2
Portage
Portage.Version
+ Portage.Dependency
Portage.PackageId
Portage.Overlay
Portage.Host

0 comments on commit 6956e2f

Please sign in to comment.