Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 4cfa22eafe
Fetching contributors…

Cannot retrieve contributors at this time

file 52 lines (48 sloc) 2.384 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
module GenerateEbuild where

import Action
import Cabal2Ebuild
import Fetch
import TarUtils
import Config
import Error

import Prelude hiding (catch)
import Control.Monad.Trans
import Control.Monad.Error
import Control.Exception
import Distribution.PackageDescription
import Distribution.Package
import System.Directory

mergeEbuild :: FilePath -> EBuild -> HPAction ()
mergeEbuild target ebuild = do
cfg <- getCfg
let edir = target++"/"++(portageCategory cfg)++"/"++(name ebuild)
let epath = edir++"/"++(name ebuild)++"-"++(version ebuild)++".ebuild"
liftIO (createDirectoryIfMissing True edir)
`sayDebug` ("Creating '"++edir++"'... ",const "done.")
liftIO (writeFile epath (showEBuild ebuild))
`sayNormal` ("Merging to '"++epath++"'... ",const "done.")

hackage2ebuild ::
(PackageIdentifier,String,String) -> -- ^ the package
HPAction EBuild
hackage2ebuild (pkg,tarball,sig) = do
cfg <- getCfg
tarballPath <- (if verify cfg then liftIO (do
(tarPath,sigPath) <- downloadFileVerify (tmp cfg) tarball sig
removeFile sigPath
return tarPath) else liftIO (downloadTarball (tmp cfg) tarball))
`sayNormal` ("Downloading tarball from '"++tarball++"' to '"++(tmp cfg)++"'... ",const "done.")
tarType <- maybe (liftIO (removeFile tarballPath) >> throwError (UnknownCompression tarball)) return (tarballGetType tarballPath)
`sayDebug` ("Guessing compression type of tarball... ",const "done.")
filesInTarball <- tarballGetFiles (tarCommand cfg) tarballPath tarType
`sayDebug` ("Getting list of files from tarball... ",const "done.")
`catchError` (\x->liftIO (removeFile tarballPath) >> throwError x)
(cabalDir,cabalName) <- maybe (throwError $ NoCabalFound tarball) return (findCabal filesInTarball)
`sayDebug` ("Trying to find cabal file... ",\(dir,name)->"Found cabal file '"++name++"' in '"++dir++"'.")
cabalFile <- tarballExtractFile tarballPath tarType (cabalDir++"/"++cabalName)
`sayDebug` ("Extracting cabal file... ",const "done.")
packageDescription <- case parseDescription cabalFile of
ParseFailed err -> throwError $ CabalParseFailed cabalName (showError err)
ParseOk descr -> return descr
`sayDebug` ("Parsing '"++cabalName++"'... ",const "done.")
let ebuild=cabal2ebuild (packageDescription{pkgUrl=tarball}) --we don't trust the cabal file as we just successfully downloaded the tarbal somewhere
return ebuild {cabalPath=Just cabalDir}
Something went wrong with that request. Please try again.