Skip to content
Browse files

Merge.hs: move existing metadata reading out before ebuild generation

That way it's easier to adjust process of ebuild generation based on
existing metadata (like cabal flag picking).

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
  • Loading branch information...
1 parent 646638a commit 52a92a771e5e621fd25262f846799e640561f068 @trofi trofi committed
Showing with 23 additions and 13 deletions.
  1. +4 −3 Cabal2Ebuild.hs
  2. +7 −5 Merge.hs
  3. +6 −4 Portage/EMeta.hs
  4. +6 −1 Portage/PackageId.hs
View
7 Cabal2Ebuild.hs
@@ -34,7 +34,7 @@ import qualified Distribution.Package as Cabal (PackageIdentifier(..)
import qualified Distribution.Version as Cabal (VersionRange, foldVersionRange')
import Distribution.Text (display)
-import Data.Char (toLower,isUpper)
+import Data.Char (isUpper)
import Portage.Dependency
import qualified Portage.Cabal as Portage
@@ -48,7 +48,7 @@ import Portage.Version
cabal2ebuild :: Cabal.PackageDescription -> Portage.EBuild
cabal2ebuild pkg = Portage.ebuildTemplate {
- E.name = map toLower cabalPkgName,
+ E.name = Portage.cabal_pn_to_PN cabal_pn,
E.hackage_name= cabalPkgName,
E.version = display (Cabal.pkgVersion (Cabal.package pkg)),
E.description = if null (Cabal.synopsis pkg) then Cabal.description pkg
@@ -66,7 +66,8 @@ cabal2ebuild pkg = Portage.ebuildTemplate {
) (Cabal.library pkg) -- hscolour can't colour its own sources
++ (if hasTests then ["test-suite"] else [])
} where
- cabalPkgName = display $ Cabal.pkgName (Cabal.package pkg)
+ cabal_pn = Cabal.pkgName $ Cabal.package pkg
+ cabalPkgName = display cabal_pn
hasExe = (not . null) (Cabal.executables pkg)
hasTests = (not . null) (Cabal.testSuites pkg)
thisHomepage = if (null $ Cabal.homepage pkg)
View
12 Merge.hs
@@ -166,6 +166,9 @@ mergeGenericPackageDescription :: Verbosity -> FilePath -> Portage.Category -> C
mergeGenericPackageDescription verbosity overlayPath cat pkgGenericDesc fetch users_cabal_flags = do
overlay <- Overlay.loadLazy overlayPath
let merged_cabal_pkg_name = Cabal.pkgName (Cabal.package (Cabal.packageDescription pkgGenericDesc))
+ merged_PN = Portage.cabal_pn_to_PN merged_cabal_pkg_name
+ pkgdir = overlayPath </> Portage.unCategory cat </> merged_PN
+ existing_meta <- EM.findExistingMeta pkgdir
debug verbosity "searching for minimal suitable ghc version"
(compilerId, ghc_packages, pkgDesc0, _flags, pix) <- case GHCCore.minimumGHCVersionToBuildPackage pkgGenericDesc of
@@ -423,7 +426,7 @@ mergeGenericPackageDescription verbosity overlayPath cat pkgGenericDesc fetch us
Just ucf -> (\e -> e { E.used_options = E.used_options e ++ [("flags", ucf)] }))
$ C2E.cabal2ebuild pkgDesc
- mergeEbuild verbosity overlayPath (Portage.unCategory cat) ebuild
+ mergeEbuild verbosity existing_meta pkgdir ebuild
when fetch $ do
let cabal_pkgId = Cabal.packageId pkgDesc
norm_pkgName = Cabal.packageName (Portage.normalizeCabalPackageId cabal_pkgId)
@@ -461,16 +464,15 @@ to_unstable kw =
'-':_ -> kw
_ -> '~':kw
-mergeEbuild :: Verbosity -> FilePath -> String -> E.EBuild -> IO ()
-mergeEbuild verbosity target cat ebuild = do
- let edir = target </> cat </> E.name ebuild
+mergeEbuild :: Verbosity -> EM.EMeta -> FilePath -> E.EBuild -> IO ()
+mergeEbuild verbosity existing_meta pkgdir ebuild = do
+ let edir = pkgdir
elocal = E.name ebuild ++"-"++ E.version ebuild <.> "ebuild"
epath = edir </> elocal
emeta = "metadata.xml"
mpath = edir </> emeta
default_meta = BL.pack $ Portage.makeDefaultMetadata (E.long_desc ebuild)
createDirectoryIfMissing True edir
- existing_meta <- EM.findExistingMeta edir
now <- TC.getCurrentTime
let (existing_keywords, existing_license) = (EM.keywords existing_meta, EM.license existing_meta)
View
10 Portage/EMeta.hs
@@ -7,7 +7,7 @@ import Control.Monad.Error
import Data.Char (isSpace)
import qualified Data.List as L
-import System.Directory (getDirectoryContents)
+import System.Directory (doesDirectoryExist, getDirectoryContents)
import System.FilePath ((</>))
import Text.Printf
@@ -46,11 +46,13 @@ data EMeta = EMeta { keywords :: Maybe [String]
}
findExistingMeta :: FilePath -> IO EMeta
-findExistingMeta edir =
- do ebuilds <- filter (L.isSuffixOf ".ebuild") `fmap` getDirectoryContents edir
+findExistingMeta pkgdir =
+ do ebuilds <- filter (L.isSuffixOf ".ebuild") `fmap` do b <- doesDirectoryExist pkgdir
+ if b then getDirectoryContents pkgdir
+ else return []
-- TODO: version sort
e_metas <- forM ebuilds $ \e ->
- do let e_path = edir </> e
+ do let e_path = pkgdir </> e
e_conts <- readFile e_path
return EMeta { keywords = extractKeywords e e_conts
, license = extractLicense e e_conts
View
7 Portage/PackageId.hs
@@ -11,9 +11,12 @@ module Portage.PackageId (
parseFriendlyPackage,
normalizeCabalPackageName,
normalizeCabalPackageId,
- packageIdToFilePath
+ packageIdToFilePath,
+ cabal_pn_to_PN
) where
+import Data.Char
+
import qualified Distribution.Package as Cabal
import Distribution.Text (Text(..))
@@ -124,3 +127,5 @@ parseFriendlyPackage str =
return (Just v)
return (mc, p, mv)
+cabal_pn_to_PN :: Cabal.PackageName -> String
+cabal_pn_to_PN = map toLower . display

0 comments on commit 52a92a7

Please sign in to comment.
Something went wrong with that request. Please try again.