Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move dependency resolution to its own file

  • Loading branch information...
commit 861db07a4ff79ce3eae90e28a80f56e9571f3a40 1 parent 58a7222
Lennart Kolmodin kolmodin authored
Showing with 168 additions and 145 deletions.
  1. +11 −145 Merge.hs
  2. +156 −0 Merge/Dependencies.hs
  3. +1 −0  hackport.cabal
156 Merge.hs
View
@@ -52,12 +52,7 @@ import Distribution.Package
import Distribution.Compiler (CompilerId(..), CompilerFlavor(GHC))
import Distribution.PackageDescription ( PackageDescription(..)
, FlagName(..)
- , libBuildInfo
- , buildInfo
- , buildable
- , extraLibs
- , buildTools
- , hasLibs )
+ )
import Distribution.PackageDescription.Configuration
( finalizePackageDescription )
import Distribution.Text (display)
@@ -89,11 +84,12 @@ import Distribution.Client.Types
import qualified Portage.PackageId as Portage
import qualified Portage.Version as Portage
-import qualified Portage.Dependency as Portage
import qualified Portage.Host as Host
import qualified Portage.Overlay as Overlay
import qualified Portage.Resolve as Portage
+import qualified Merge.Dependencies as Merge
+
import Debug.Trace ( trace )
(<->) :: String -> String -> String
@@ -158,8 +154,8 @@ merge verbosity repo serverURI args overlayPath = do
let (Cabal.PackageName user_pname_str) = user_pName
overlay <- Overlay.loadLazy overlayPath
- portage_path <- Host.portage_dir `fmap` Host.getInfo
- portage <- Overlay.loadLazy portage_path
+ -- portage_path <- Host.portage_dir `fmap` Host.getInfo
+ -- portage <- Overlay.loadLazy portage_path
index <- fmap packageIndex $ getAvailablePackages verbosity [ repo ]
-- find all packages that maches the user specified package name
@@ -207,74 +203,17 @@ merge verbosity repo serverURI args overlayPath = do
| Dependency pn vr <- buildDepends pkgDesc0
]
in pkgDesc0 { buildDepends = deps }
+ edeps = Merge.resolveDependencies pkgDesc
- hasBuildableExes p =
- any (buildable . buildInfo)
- . executables $ p
- treatAsLibrary = (not . hasBuildableExes) pkgDesc || hasLibs pkgDesc
-
- -- calculate build tools
- bt = [ pkg' -- TODO: currently ignoring version range
- | Cabal.Dependency (Cabal.PackageName pkg ) _range <- buildToolsDeps pkgDesc
- , Just pkg' <- return (lookup pkg buildToolsTable)
- ]
-
- packageNameResolver s = do
- (Portage.PackageName p_cat pn)
- <- Portage.resolveFullPortageName portage (Cabal.PackageName s)
- return $ Portage.AnyVersionOf (Portage.PackageName p_cat pn)
-
- -- calculate extra-libs
- extra_libs <- findCLibs verbosity packageNameResolver pkgDesc
-
debug verbosity ("Selected flags: " ++ show flags)
- debug verbosity ("extra-libs: ")
- mapM_ (debug verbosity . show) extra_libs
-
- debug verbosity ("build-tools:")
- mapM_ (debug verbosity . show) bt
-
- -- debug verbosity ("Finalized package:\n" ++ showPackageDescription pkgDesc)
-
- -- TODO: more fixes
- -- * inherit keywords from previous ebuilds
- let cabal_dep = head $ C2E.convertDependency (Portage.Category "dev-haskell")
- (Cabal.Dependency (Cabal.PackageName "Cabal")
- (descCabalVersion pkgDesc))
- ghc_dep = C2E.default_ghc_dependency
- haskell_deps = Portage.simplify_deps $ C2E.convertDependencies (Portage.Category "dev-haskell") (buildDepends pkgDesc)
- build_tools = bt
- pkg_config = []
-
- let edeps
- | treatAsLibrary = emptyEDep
- {
- dep = cabal_dep
- : build_tools,
- dep_e = [ "${RDEPEND}" ],
- rdep = ghc_dep
- : haskell_deps
- ++ extra_libs
- ++ pkg_config
- }
- | otherwise = emptyEDep
- {
- dep = ghc_dep
- : cabal_dep
- : build_tools
- ++ haskell_deps,
- dep_e = [ "${RDEPEND}" ],
- rdep = extra_libs
- ++ pkg_config
- }
+
let ebuild = fixSrc serverURI (packageId pkgDesc)
- . (\e -> e { E.depend = dep edeps } )
- . (\e -> e { E.depend_extra = dep_e edeps } )
- . (\e -> e { E.rdepend = rdep edeps } )
- . (\e -> e { E.rdepend_extra = rdep_e edeps } )
+ . (\e -> e { E.depend = Merge.dep edeps } )
+ . (\e -> e { E.depend_extra = Merge.dep_e edeps } )
+ . (\e -> e { E.rdepend = Merge.rdep edeps } )
+ . (\e -> e { E.rdepend_extra = Merge.rdep_e edeps } )
$ C2E.cabal2ebuild pkgDesc
- debug verbosity ("Treat as library: " ++ show treatAsLibrary)
mergeEbuild verbosity overlayPath (Portage.unCategory cat) ebuild
fetchAndDigest
verbosity
@@ -282,79 +221,6 @@ merge verbosity repo serverURI args overlayPath = do
(display cabal_pkgId <.> "tar.gz")
(mkUri cabal_pkgId)
-
--- | Dependencies of an ebuild
-data EDep = EDep
- {
- rdep :: [Portage.Dependency],
- rdep_e :: [String],
- dep :: [Portage.Dependency],
- dep_e :: [String]
- }
-
-emptyEDep :: EDep
-emptyEDep = EDep
- {
- rdep = [],
- rdep_e = [],
- dep = [],
- dep_e = []
- }
-
-findCLibs :: Verbosity -> (String -> Maybe Portage.Dependency) -> PackageDescription -> IO [Portage.Dependency]
-findCLibs verbosity portageResolver (PackageDescription { library = lib, executables = exes }) = do
- debug verbosity "Mapping extra-libraries into portage packages..."
- -- for extra libs we don't find, maybe look into into installed packages?
- when (not . null $ notFound) $
- warn verbosity ("Could not find portage packages for extra-libraries: " ++ unwords notFound)
- when (not . null $ found) $
- debug verbosity ("Found c-libraries deps: " ++ show found)
- return found
- where
- resolvers = [ staticTranslateExtraLib, portageResolver ]
-
- resolved = [ chain p resolvers
- | p <- libE ++ exeE
- ] :: [Either String Portage.Dependency]
-
- notFound = [ p | Left p <- resolved ]
- found = [ p | Right p <- resolved ]
-
- chain v [] = Left v
- chain v (f:fs) = case f v of
- Nothing -> chain v fs
- Just x -> Right x
-
- libE = maybe [] (extraLibs.libBuildInfo) lib
- exeE = concatMap (extraLibs.buildInfo) exes
-
-staticTranslateExtraLib :: String -> Maybe Portage.Dependency
-staticTranslateExtraLib lib = lookup lib m
- where
- m = [ ("z", Portage.AnyVersionOf (Portage.mkPackageName "sys-libs" "zlib"))
- , ("bz2", Portage.AnyVersionOf (Portage.mkPackageName "sys-libs" "bzlib"))
- , ("mysqlclient", Portage.LaterVersionOf (Portage.Version [4,0] Nothing [] 0) (Portage.mkPackageName "virtual" "mysql"))
- , ("pq", Portage.LaterVersionOf (Portage.Version [7] Nothing [] 0) (Portage.mkPackageName "virtual" "postgresql-base"))
- , ("ev", Portage.AnyVersionOf (Portage.mkPackageName "dev-libs" "libev"))
- ]
-
-buildToolsDeps :: PackageDescription -> [Cabal.Dependency]
-buildToolsDeps (PackageDescription { library = lib, executables = exes }) = cabalDeps
- where
- cabalDeps = depL ++ depE
- depL = maybe [] (buildTools.libBuildInfo) lib
- depE = concatMap (buildTools.buildInfo) exes
-
-buildToolsTable :: [(String, Portage.Dependency)]
-buildToolsTable =
- [ ("happy", Portage.AnyVersionOf (Portage.mkPackageName "dev-haskell" "happy"))
- , ("alex", Portage.AnyVersionOf (Portage.mkPackageName "dev-haskell" "alex"))
- , ("c2hs", Portage.AnyVersionOf (Portage.mkPackageName "dev-haskell" "c2hs"))
- , ("gtk2hsTypeGen", Portage.AnyVersionOf (Portage.mkPackageName "dev-haskell" "gtk2hs-buildtools"))
- , ("gtk2hsHookGenerator", Portage.AnyVersionOf (Portage.mkPackageName "dev-haskell" "gtk2hs-buildtools"))
- , ("gtk2hsC2hs", Portage.AnyVersionOf (Portage.mkPackageName "dev-haskell" "gtk2hs-buildtools"))
- ]
-
mkUri :: Cabal.PackageIdentifier -> URI
mkUri pid =
-- example:
156 Merge/Dependencies.hs
View
@@ -0,0 +1,156 @@
+module Merge.Dependencies
+ ( EDep(..)
+ , resolveDependencies
+ ) where
+
+import Distribution.PackageDescription ( PackageDescription(..)
+ , libBuildInfo
+ , buildInfo
+ , buildable
+ , extraLibs
+ , buildTools
+ , hasLibs )
+import Data.Maybe ( isNothing )
+
+import qualified Distribution.Package as Cabal
+
+import qualified Portage.PackageId as Portage
+import qualified Portage.Dependency as Portage
+import qualified Cabal2Ebuild as C2E
+
+import Debug.Trace ( trace )
+
+-- | Dependencies of an ebuild
+data EDep = EDep
+ {
+ rdep :: [Portage.Dependency],
+ rdep_e :: [String],
+ dep :: [Portage.Dependency],
+ dep_e :: [String]
+ }
+
+emptyEDep :: EDep
+emptyEDep = EDep
+ {
+ rdep = [],
+ rdep_e = [],
+ dep = [],
+ dep_e = []
+ }
+
+resolveDependencies :: PackageDescription -> EDep
+resolveDependencies pkg = edeps
+ where
+ hasBuildableExes p = any (buildable . buildInfo) . executables $ p
+ treatAsLibrary = (not . hasBuildableExes) pkg || hasLibs pkg
+ haskell_deps = haskellDependencies pkg
+ cabal_dep = cabalDependency pkg
+ ghc_dep = ghcDependency pkg
+ extra_libs = findCLibs pkg
+ build_tools = buildToolsDependencies pkg
+ pkg_config = []
+ edeps
+ | treatAsLibrary = emptyEDep
+ {
+ dep = cabal_dep
+ : build_tools,
+ dep_e = [ "${RDEPEND}" ],
+ rdep = ghc_dep
+ : haskell_deps
+ ++ extra_libs
+ ++ pkg_config
+ }
+ | otherwise = emptyEDep
+ {
+ dep = ghc_dep
+ : cabal_dep
+ : build_tools
+ ++ haskell_deps,
+ dep_e = [ "${RDEPEND}" ],
+ rdep = extra_libs ++ pkg_config
+ }
+
+---------------------------------------------------------------
+-- Haskell packages
+---------------------------------------------------------------
+
+haskellDependencies :: PackageDescription -> [Portage.Dependency]
+haskellDependencies pkg =
+ Portage.simplify_deps
+ $ C2E.convertDependencies (Portage.Category "dev-haskell") (buildDepends pkg)
+
+---------------------------------------------------------------
+-- Cabal Dependency
+---------------------------------------------------------------
+
+cabalDependency :: PackageDescription -> Portage.Dependency
+cabalDependency pkg =
+ head $ C2E.convertDependency (Portage.Category "dev-haskell")
+ (Cabal.Dependency (Cabal.PackageName "Cabal")
+ (descCabalVersion pkg))
+
+---------------------------------------------------------------
+-- GHC Dependency
+---------------------------------------------------------------
+
+ghcDependency :: PackageDescription -> Portage.Dependency
+ghcDependency _pkg = C2E.default_ghc_dependency
+
+---------------------------------------------------------------
+-- C Libraries
+---------------------------------------------------------------
+
+findCLibs :: PackageDescription -> [Portage.Dependency]
+findCLibs (PackageDescription { library = lib, executables = exes }) =
+ [ trace ("WARNING: This package depends on a C library we don't know the portage name for: " ++ p ++ ". Check the generated ebuild.")
+ (Portage.AnyVersionOf (Portage.mkPackageName "unknown-c-lib" p))
+ | p <- notFound
+ ] ++
+ found
+ where
+ libE = maybe [] (extraLibs.libBuildInfo) lib
+ exeE = concatMap extraLibs (filter buildable (map buildInfo exes))
+ allE = libE ++ exeE
+
+ notFound = [ p | p <- allE, isNothing (staticTranslateExtraLib p) ]
+ found = [ p | Just p <- map staticTranslateExtraLib allE ]
+
+
+staticTranslateExtraLib :: String -> Maybe Portage.Dependency
+staticTranslateExtraLib lib = lookup lib m
+ where
+ m = [ ("z", Portage.AnyVersionOf (Portage.mkPackageName "sys-libs" "zlib"))
+ , ("bz2", Portage.AnyVersionOf (Portage.mkPackageName "sys-libs" "bzlib"))
+ , ("mysqlclient", Portage.LaterVersionOf (Portage.Version [4,0] Nothing [] 0) (Portage.mkPackageName "virtual" "mysql"))
+ , ("pq", Portage.LaterVersionOf (Portage.Version [7] Nothing [] 0) (Portage.mkPackageName "virtual" "postgresql-base"))
+ , ("ev", Portage.AnyVersionOf (Portage.mkPackageName "dev-libs" "libev"))
+ ]
+
+---------------------------------------------------------------
+-- Build Tools
+---------------------------------------------------------------
+
+buildToolsDependencies :: PackageDescription -> [Portage.Dependency]
+buildToolsDependencies (PackageDescription { library = lib, executables = exes }) =
+ [ case pkg of
+ Just p -> p
+ Nothing -> trace ("WARNING: Unknown build tool '" ++ pn ++ "'. Check the generated ebuild.")
+ (Portage.AnyVersionOf (Portage.mkPackageName "unknown-build-tool" pn))
+ | Cabal.Dependency (Cabal.PackageName pn) _range <- cabalDeps
+ , pkg <- return (lookup pn buildToolsTable)
+ ]
+ where
+ cabalDeps = depL ++ depE
+ depL = maybe [] (buildTools.libBuildInfo) lib
+ -- depE = concatMap (buildTools.buildInfo) exes
+ depE = concatMap buildTools (filter buildable (map buildInfo exes))
+
+buildToolsTable :: [(String, Portage.Dependency)]
+buildToolsTable =
+ [ ("happy", Portage.AnyVersionOf (Portage.mkPackageName "dev-haskell" "happy"))
+ , ("alex", Portage.AnyVersionOf (Portage.mkPackageName "dev-haskell" "alex"))
+ , ("c2hs", Portage.AnyVersionOf (Portage.mkPackageName "dev-haskell" "c2hs"))
+ , ("gtk2hsTypeGen", Portage.AnyVersionOf (Portage.mkPackageName "dev-haskell" "gtk2hs-buildtools"))
+ , ("gtk2hsHookGenerator", Portage.AnyVersionOf (Portage.mkPackageName "dev-haskell" "gtk2hs-buildtools"))
+ , ("gtk2hsC2hs", Portage.AnyVersionOf (Portage.mkPackageName "dev-haskell" "gtk2hs-buildtools"))
+ ]
1  hackport.cabal
View
@@ -67,6 +67,7 @@ Executable hackport
Portage.Overlay
Portage.Resolve
Portage.Host
+ Merge.Dependencies
Setup
Status
Merge
Please sign in to comment.
Something went wrong with that request. Please try again.