Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 131 lines (120 sloc) 4.824 kb
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
1 module Merge where
2
3 import Control.Monad.Error
8135c0c @kolmodin Implement fetching and creation of digests for new ebuilds
kolmodin authored
4 -- import Control.Monad.Error
5 import Control.Exception
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
6 import Data.Char
7 import Data.Maybe
8 import Data.List
9 import Data.Version
10 import Distribution.Package
11 import Distribution.Compiler (CompilerId(..), CompilerFlavor(GHC))
8135c0c @kolmodin Implement fetching and creation of digests for new ebuilds
kolmodin authored
12 import Distribution.PackageDescription ( PackageDescription(..) )
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
13 import Distribution.PackageDescription.Configuration
14 ( finalizePackageDescription )
15 import Distribution.Simple.PackageIndex (PackageIndex)
16 import Distribution.Text (display)
17
8135c0c @kolmodin Implement fetching and creation of digests for new ebuilds
kolmodin authored
18 import System.Directory ( getCurrentDirectory , setCurrentDirectory )
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
19 import System.IO
8135c0c @kolmodin Implement fetching and creation of digests for new ebuilds
kolmodin authored
20 import System.Cmd (system)
21 import System.FilePath ((</>), splitPath, joinPath, takeFileName)
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
22 import qualified Data.Map as Map
23
24 import qualified Cabal2Ebuild as E
25 import Cache
26 import Error
27 import GenerateEbuild
225135f @kolmodin Switch to using Portage.{PackageId,Version}
kolmodin authored
28 import qualified Portage.PackageId as Portage
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
29 import Overlays
30 import P2
6ec3592 Hackport now uses Cabal-1.6
Ivan.Miljenovic@gmail.com authored
31 import Index (pName)
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
32
8135c0c @kolmodin Implement fetching and creation of digests for new ebuilds
kolmodin authored
33 import Distribution.System (buildOS, buildArch)
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
34 import Distribution.Verbosity
35 import Distribution.Simple.Utils
36
37 import Network.URI
8135c0c @kolmodin Implement fetching and creation of digests for new ebuilds
kolmodin authored
38 import Network.HTTP
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
39
40 import Cabal2Ebuild
41
f56d508 @kolmodin Cleanup in merge
kolmodin authored
42 a <-> b = a ++ '-':b
43 a <.> b = a ++ '.':b
44
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
45 merge :: Verbosity -> URI -> String -> IO ()
225135f @kolmodin Switch to using Portage.{PackageId,Version}
kolmodin authored
46 merge verbosity serverURI pstr = do
47 (m_category, Portage.PN pname, m_version) <- case Portage.parseFriendlyPackage pstr of
48 Just v -> return v
49 Nothing -> throwEx (ArgumentError ("Could not parse [category/]package[-version]: " ++ show pstr))
50 overlayPath <- getOverlayPath verbosity
51 overlay <- readPortageTree overlayPath
52 cache <- readCache verbosity overlayPath serverURI
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
53 let (indexTree,clashes) = indexToPortage cache overlay
54 mapM_ putStrLn clashes
225135f @kolmodin Switch to using Portage.{PackageId,Version}
kolmodin authored
55 info verbosity $ "Searching for: "++ pstr
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
56 let pkgs =
57 Map.elems
58 . Map.filterWithKey (\(P _ pname') _ -> map toLower pname' == map toLower pname)
59 $ indexTree
60 return ()
61 pkg <- case pkgs of
62 [] -> throwEx (PackageNotFound pname)
63 [xs] -> case m_version of
64 Nothing -> return (maximum xs) -- highest version
65 Just v -> do
66 let ebuilds = filter (\e -> eVersion e == v) xs
67 case ebuilds of
68 [] -> throwEx (PackageNotFound (pname ++ '-':show v))
69 [e] -> return e
70 _ -> fail "the impossible happened"
71 _ -> fail "the impossible happened"
72 category <- do
73 case m_category of
225135f @kolmodin Switch to using Portage.{PackageId,Version}
kolmodin authored
74 Just (Portage.Category cat) -> return cat
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
75 Nothing -> do
76 case pCategory (ePackage pkg) of
77 "hackage" -> return "dev-haskell"
78 c -> return c
79 let Just genericDesc = ePkgDesc pkg
80 Right (desc, _) = finalizePackageDescription []
81 (Nothing :: Maybe (PackageIndex PackageIdentifier))
82 buildOS buildArch
83 (CompilerId GHC (Version [6,8,2] []))
84 [] genericDesc
85 let ebuild = fixSrc serverURI (packageId desc) (E.cabal2ebuild desc)
f56d508 @kolmodin Cleanup in merge
kolmodin authored
86 ebuildName = category </> pname <-> display (pkgVersion (packageId desc))
8135c0c @kolmodin Implement fetching and creation of digests for new ebuilds
kolmodin authored
87 putStrLn $ "Merging " ++ ebuildName
88 putStrLn $ "Destination: " ++ overlayPath
89 mergeEbuild overlayPath category ebuild
90 let
6ec3592 Hackport now uses Cabal-1.6
Ivan.Miljenovic@gmail.com authored
91 package_name = pName $ pkgName (package desc)
f56d508 @kolmodin Cleanup in merge
kolmodin authored
92 package_version = showVersion (pkgVersion (package desc))
8135c0c @kolmodin Implement fetching and creation of digests for new ebuilds
kolmodin authored
93 url = "http://hackage.haskell.org/packages/archive/"
94 </> package_name </> package_version </> package_name <-> package_version <.> "tar.gz"
95 Just uri = parseURI url
96 tarballName = package_name <-> package_version <.> "tar.gz"
97 -- example:
98 -- http://hackage.haskell.org/packages/archive/Cabal/1.4.0.2/Cabal-1.4.0.2.tar.gz
99 fetchAndDigest
100 verbosity
101 (overlayPath </> category </> pname)
102 tarballName
103 uri
104
105 fetchAndDigest :: Verbosity
106 -> FilePath -- ^ directory of ebuild
107 -> String -- ^ tarball name
108 -> URI -- ^ tarball uri
6ec3592 Hackport now uses Cabal-1.6
Ivan.Miljenovic@gmail.com authored
109 -> IO ()
8135c0c @kolmodin Implement fetching and creation of digests for new ebuilds
kolmodin authored
110 fetchAndDigest verbosity ebuildDir tarballName tarballURI = do
111 withWorkingDirectory ebuildDir $ do
f56d508 @kolmodin Cleanup in merge
kolmodin authored
112 notice verbosity $ "Fetching " ++ show tarballURI
8135c0c @kolmodin Implement fetching and creation of digests for new ebuilds
kolmodin authored
113 response <- simpleHTTP (Request tarballURI GET [] "")
114 case response of
115 Left err -> print err
116 Right response -> do
117 let tarDestination = "/usr/portage/distfiles" </> tarballName
f56d508 @kolmodin Cleanup in merge
kolmodin authored
118 notice verbosity $ "Saving to " ++ tarDestination
8135c0c @kolmodin Implement fetching and creation of digests for new ebuilds
kolmodin authored
119 writeFile tarDestination (rspBody response)
f56d508 @kolmodin Cleanup in merge
kolmodin authored
120 notice verbosity $ "Recalculating digests..."
8135c0c @kolmodin Implement fetching and creation of digests for new ebuilds
kolmodin authored
121 system "repoman manifest"
122 return ()
123
124 withWorkingDirectory :: FilePath -> IO a -> IO a
125 withWorkingDirectory newDir action = do
126 oldDir <- getCurrentDirectory
127 bracket
128 (setCurrentDirectory newDir)
129 (\_ -> setCurrentDirectory oldDir)
130 (\_ -> action)
Something went wrong with that request. Please try again.