Skip to content

Commit

Permalink
Update to Cabal-1.4 api
Browse files Browse the repository at this point in the history
  • Loading branch information
Duncan Coutts committed Aug 23, 2008
1 parent ace670a commit ffabce4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
20 changes: 11 additions & 9 deletions Cabal2Ebuild.hs
Expand Up @@ -28,11 +28,13 @@ module Cabal2Ebuild

import qualified Distribution.PackageDescription as Cabal
(PackageDescription(..))
import qualified Distribution.Package as Cabal (PackageIdentifier(..))
import qualified Distribution.Version as Cabal (showVersion, Dependency(..),
VersionRange(..))
import qualified Distribution.Package as Cabal
( PackageIdentifier(..), Dependency(..) )
import qualified Distribution.Version as Cabal
( VersionRange(..) )
import qualified Distribution.License as Cabal (License(..))
--import qualified Distribution.Compiler as Cabal (CompilerFlavor(..))
import Distribution.Text (display)

import Data.Char (toLower,isUpper)

Expand Down Expand Up @@ -85,7 +87,7 @@ ebuildTemplate = EBuild {
cabal2ebuild :: Cabal.PackageDescription -> EBuild
cabal2ebuild pkg = ebuildTemplate {
name = map toLower cabalPkgName,
version = Cabal.showVersion (Cabal.pkgVersion (Cabal.package pkg)),
version = display (Cabal.pkgVersion (Cabal.package pkg)),
description = if null (Cabal.synopsis pkg) then Cabal.description pkg
else Cabal.synopsis pkg,
homepage = Cabal.homepage pkg,
Expand Down Expand Up @@ -139,13 +141,13 @@ convertDependency (Cabal.Dependency pname versionRange)

convert :: Cabal.VersionRange -> Dependency
convert Cabal.AnyVersion = AnyVersionOf ebuildName
convert (Cabal.ThisVersion v) = ThisVersionOf (Cabal.showVersion v) ebuildName
convert (Cabal.LaterVersion v) = LaterVersionOf (Cabal.showVersion v) ebuildName
convert (Cabal.EarlierVersion v) = EarlierVersionOf (Cabal.showVersion v) ebuildName
convert (Cabal.ThisVersion v) = ThisVersionOf (display v) ebuildName
convert (Cabal.LaterVersion v) = LaterVersionOf (display v) ebuildName
convert (Cabal.EarlierVersion v) = EarlierVersionOf (display v) ebuildName
convert (Cabal.UnionVersionRanges (Cabal.ThisVersion v1) (Cabal.LaterVersion v2))
| v1 == v2 = OrLaterVersionOf (Cabal.showVersion v1) ebuildName
| v1 == v2 = OrLaterVersionOf (display v1) ebuildName
convert (Cabal.UnionVersionRanges (Cabal.ThisVersion v1) (Cabal.EarlierVersion v2))
| v1 == v2 = OrEarlierVersionOf (Cabal.showVersion v1) ebuildName
| v1 == v2 = OrEarlierVersionOf (display v1) ebuildName
convert (Cabal.UnionVersionRanges r1 r2)
= DependEither (convert r1) (convert r2)

Expand Down
4 changes: 2 additions & 2 deletions Cache.hs
Expand Up @@ -9,7 +9,7 @@ import P2
import Version
import Overlays

import qualified Distribution.Version as Cabal ( readVersion )
import Distribution.Text ( simpleParse )

import Control.Arrow
import Data.Char
Expand Down Expand Up @@ -73,7 +73,7 @@ indexToPortage index port = second nub . runWriter $ do
pkgs <- forM index $ \(pkg_h_name, pkg_h_ver, pkg_desc) -> do
let pkg_name = map toLower pkg_h_name
pkg_cat <- lookupCat pkg_name
Just ver <- return . Cabal.readVersion $ pkg_h_ver
Just ver <- return . simpleParse $ pkg_h_ver
return $ Ebuild (P pkg_cat pkg_name)
(fromCabalVersion ver)
"<hackage>"
Expand Down
22 changes: 14 additions & 8 deletions Main.hs
Expand Up @@ -6,10 +6,13 @@ import Data.Maybe
import Data.List
import Data.Version
import Distribution.Package
import Distribution.PackageDescription
(finalizePackageDescription, package)
import Distribution.Compiler (CompilerId(..), CompilerFlavor(GHC))
import Distribution.PackageDescription.Configuration
( finalizePackageDescription, flattenPackageDescription )
import Distribution.Simple.PackageIndex (PackageIndex)
import Distribution.Text (display)
import System.IO
import System.Info (os, arch)
import Distribution.System (buildOS, buildArch)
import qualified Data.Map as Map
import Text.ParserCombinators.Parsec

Expand Down Expand Up @@ -78,11 +81,14 @@ merge pstr = do
"hackage" -> return "dev-haskell"
c -> return c
let Just genericDesc = ePkgDesc pkg
Right (desc, _) = finalizePackageDescription [] Nothing os arch
("ghc", Version [6,8,2] []) genericDesc
ebuild <- fixSrc (package desc) (E.cabal2ebuild desc)
Right (desc, _) = finalizePackageDescription []
(Nothing :: Maybe (PackageIndex PackageIdentifier))
buildOS buildArch
(CompilerId GHC (Version [6,8,2] []))
[] genericDesc
ebuild <- fixSrc (packageId desc) (E.cabal2ebuild desc)
liftIO $ do
putStrLn $ "Merging " ++ category ++ '/': pname ++ "-" ++ showVersion (pkgVersion (package desc))
putStrLn $ "Merging " ++ category ++ '/': pname ++ "-" ++ display (pkgVersion (packageId desc))
putStrLn $ "Destination: " ++ portdir
mergeEbuild portdir category ebuild
where
Expand All @@ -99,7 +105,7 @@ merge pstr = do
makeEbuild :: String -> HPAction ()
makeEbuild cabalFileName = liftIO $ do
pkg <- Cabal.readPackageDescription normal cabalFileName
let ebuild = cabal2ebuild (Cabal.flattenPackageDescription pkg)
let ebuild = cabal2ebuild (flattenPackageDescription pkg)
let ebuildFileName = name ebuild ++ "-" ++ version ebuild ++ ".ebuild"
writeFile ebuildFileName (showEBuild ebuild)

Expand Down
2 changes: 1 addition & 1 deletion hackport.cabal
Expand Up @@ -21,7 +21,7 @@ Executable hackport
mtl,
network,
regex-compat,
Cabal >= 1.2 && < 1.3,
Cabal >= 1.4 && < 1.5,
HTTP >= 3000 && < 3002,
zlib,
tar
Expand Down

0 comments on commit ffabce4

Please sign in to comment.