Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: cfd83a3fab
Fetching contributors…

Cannot retrieve contributors at this time

file 58 lines (54 sloc) 2.592 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 53 54 55 56 57 58
module GenerateEbuild where

import Cabal2Ebuild
import Fetch
import TarUtils
import Error
import Verbosity

import Prelude hiding (catch)
import Control.Exception
--import Network.Hackage.Client as Hackage
import Distribution.PackageDescription
import Distribution.Package
import System.Directory

mergeEbuild :: Verbosity -> FilePath -> String -> EBuild -> IO ()
mergeEbuild verb target category ebuild = do
let edir = target++"/"++category++"/"++(name ebuild)
let epath = edir++"/"++(name ebuild)++"-"++(version ebuild)++".ebuild"
createDirectoryIfMissing True edir
`sayDebug` ("Creating '"++edir++"'... ",const "done.\n")
writeFile epath (showEBuild ebuild)
`sayNormal` ("Merging to '"++epath++"'... ",const "done.\n")
where
sayNormal = verboseNormal verb
sayDebug = verboseDebug verb

hackage2ebuild ::
Verbosity -> -- ^ verbosity level
FilePath -> -- ^ the tar executable
FilePath -> -- ^ a temp path to store the tarball
Bool -> -- ^ gpg verify the package?
(PackageIdentifier,String,String) -> -- ^ the package
IO EBuild
hackage2ebuild verb tarCommand store verify (pkg,tarball,sig) = do
tarballPath <- (if verify then (do
(tarPath,sigPath) <- downloadFileVerify store tarball sig
removeFile sigPath
return tarPath) else downloadTarball store tarball)
`sayDebug` ("Downloading tarball to '"++store++"'... ",const "done.\n")
tarType <- maybe (removeFile tarballPath >> throwDyn (UnknownCompression tarball)) return (tarballGetType tarballPath)
`sayDebug` ("Guessing compression type of tarball... ",const "done.\n")
filesInTarball <- tarballGetFiles tarCommand tarballPath tarType
`sayDebug` ("Getting list of files from tarball... ",const "done.\n")
`catch` (\x->removeFile tarballPath >> throw x)
(cabalDir,cabalName) <- maybe (throwDyn $ NoCabalFound tarball) return (findCabal filesInTarball)
`sayDebug` ("Trying to find cabal file... ",\(dir,name)->"Found cabal file '"++name++"' in '"++dir++"'.\n")
cabalFile <- tarballExtractFile tarCommand tarballPath tarType (cabalDir++"/"++cabalName)
`sayDebug` ("Extracting cabal file... ",const "done.\n")
packageDescription <- case parseDescription cabalFile of
ParseFailed err -> throwDyn $ CabalParseFailed cabalName (showError err)
ParseOk descr -> return descr
`sayDebug` ("Parsing '"++cabalName++"'... ",const "done.\n")
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}
where
sayNormal = verboseNormal verb
sayDebug = verboseDebug verb
Something went wrong with that request. Please try again.