Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 159 lines (122 sloc) 6.132 kB
6c58c4a @kolmodin Add stub for distromap
kolmodin authored
1 {-# OPTIONS -XPatternGuards #-}
1dba206 @kolmodin Initial version of distromap
kolmodin authored
2 {-
3 Generate a distromap, like these:
4 http://hackage.haskell.org/packages/archive/00-distromap/
5 Format:
6
7 ("xmobar","0.8",Just "http://packages.gentoo.org/package/x11-misc/xmobar")
8 ("xmobar","0.9",Just "http://packages.gentoo.org/package/x11-misc/xmobar")
9 ("xmobar","0.9.2",Just "http://packages.gentoo.org/package/x11-misc/xmobar")
10 ("xmonad","0.5",Just "http://packages.gentoo.org/package/x11-wm/xmonad")
11 ("xmonad","0.6",Just "http://packages.gentoo.org/package/x11-wm/xmonad")
12 ("xmonad","0.7",Just "http://packages.gentoo.org/package/x11-wm/xmonad")
13 ("xmonad","0.8",Just "http://packages.gentoo.org/package/x11-wm/xmonad")
14 ("xmonad","0.8.1",Just "http://packages.gentoo.org/package/x11-wm/xmonad")
15 ("xmonad","0.9",Just "http://packages.gentoo.org/package/x11-wm/xmonad")
16 ("xmonad","0.9.1",Just "http://en.gentoo-wiki.com/wiki/Haskell/overlay")
17
18 Multiple entries for each package is allowed, given that there are different versions.
19
20
21 Setup:
22 Join all packages from portage and the overlay into a big map;
23 From Portage.PackageId: PackageName = category/package
24 PVULine = (packagename, versionstring, url)
25 Create such a map: Map PackageName DistroLine
26 Only one PVULine per version, and prefer portage over the overlay.
27
28 Algorithm;
29 1. Take a package from hackage
30 2. Look for it in the map
ec5f558 @kolmodin distromap: only print the versions available in hackage
kolmodin authored
31 a. For each version:
32 find a match in the list of versions:
33 yield the PVULine
1dba206 @kolmodin Initial version of distromap
kolmodin authored
34 -}
6c58c4a @kolmodin Add stub for distromap
kolmodin authored
35
36 module DistroMap
37 ( distroMap ) where
38
1dba206 @kolmodin Initial version of distromap
kolmodin authored
39 import Control.Applicative
40 import qualified Data.List as List ( nub )
41 import qualified Data.Map as Map
42 import Data.Map ( Map )
43 import System.FilePath ( (</>) )
44 import Debug.Trace ( trace )
ec5f558 @kolmodin distromap: only print the versions available in hackage
kolmodin authored
45 import Data.Maybe ( fromJust )
1dba206 @kolmodin Initial version of distromap
kolmodin authored
46
6c58c4a @kolmodin Add stub for distromap
kolmodin authored
47 import Distribution.Verbosity
1dba206 @kolmodin Initial version of distromap
kolmodin authored
48 import Distribution.Text ( display )
ac5deac @trofi port to (bundled) Cabal-1.12
trofi authored
49 import Distribution.Client.Types ( Repo, SourcePackageDb(..), SourcePackage(..) )
2d84418 @jkarlson Remove useless imports and variables.
jkarlson authored
50 import Distribution.Simple.Utils ( info )
1dba206 @kolmodin Initial version of distromap
kolmodin authored
51
ec5f558 @kolmodin distromap: only print the versions available in hackage
kolmodin authored
52 import qualified Data.Version as Cabal
1dba206 @kolmodin Initial version of distromap
kolmodin authored
53 import qualified Distribution.Package as Cabal
54 import qualified Distribution.Client.PackageIndex as CabalInstall
55 import qualified Distribution.Client.IndexUtils as CabalInstall
56
2d84418 @jkarlson Remove useless imports and variables.
jkarlson authored
57 import Portage.Overlay ( readOverlayByPackage, getDirectoryTree )
1dba206 @kolmodin Initial version of distromap
kolmodin authored
58 import qualified Portage.PackageId as Portage
59 import qualified Portage.Version as Portage
60
ec5f558 @kolmodin distromap: only print the versions available in hackage
kolmodin authored
61 type PVU = (Cabal.PackageName, Cabal.Version, Maybe String)
62 type PVU_Map = Map Portage.PackageName [(Cabal.Version, Maybe String)]
6c58c4a @kolmodin Add stub for distromap
kolmodin authored
63
64 distroMap :: Verbosity -> Repo -> FilePath -> FilePath -> [String] -> IO ()
65 distroMap verbosity repo portagePath overlayPath args = do
dd3f9a0 @kolmodin distromap: cleaunps
kolmodin authored
66 info verbosity "distro map called"
67 info verbosity ("verbosity: " ++ show verbosity)
68 info verbosity ("portage: " ++ portagePath)
69 info verbosity ("overlay: " ++ overlayPath)
70 info verbosity ("args: " ++ show args)
1dba206 @kolmodin Initial version of distromap
kolmodin authored
71
72 portage <- readOverlayByPackage <$> getDirectoryTree portagePath
73 overlay <- readOverlayByPackage <$> getDirectoryTree overlayPath
74
dd3f9a0 @kolmodin distromap: cleaunps
kolmodin authored
75 info verbosity ("portage packages: " ++ show (length portage))
76 info verbosity ("overlay packages: " ++ show (length overlay))
1dba206 @kolmodin Initial version of distromap
kolmodin authored
77
ec5f558 @kolmodin distromap: only print the versions available in hackage
kolmodin authored
78 let portageMap = buildPortageMap portage
79 overlayMap = buildOverlayMap overlay
1dba206 @kolmodin Initial version of distromap
kolmodin authored
80 completeMap = unionMap portageMap overlayMap
81
dd3f9a0 @kolmodin distromap: cleaunps
kolmodin authored
82 info verbosity ("portage map: " ++ show (Map.size portageMap))
83 info verbosity ("overlay map: " ++ show (Map.size overlayMap))
84 info verbosity ("complete map: " ++ show (Map.size completeMap))
1dba206 @kolmodin Initial version of distromap
kolmodin authored
85
ac5deac @trofi port to (bundled) Cabal-1.12
trofi authored
86 SourcePackageDb { packageIndex = packageIndex } <-
87 CabalInstall.getSourcePackages verbosity [repo]
1dba206 @kolmodin Initial version of distromap
kolmodin authored
88
ec5f558 @kolmodin distromap: only print the versions available in hackage
kolmodin authored
89 let pkgs0 = map (map packageInfoId) (CabalInstall.allPackagesByName packageIndex)
90 hackagePkgs = [ (Cabal.pkgName (head p), map Cabal.pkgVersion p) | p <- pkgs0 ]
91
dd3f9a0 @kolmodin distromap: cleaunps
kolmodin authored
92 info verbosity ("cabal packages: " ++ show (length hackagePkgs))
ec5f558 @kolmodin distromap: only print the versions available in hackage
kolmodin authored
93
94 let pvus = concat $ map (\(p,vs) -> lookupPVU completeMap p vs) hackagePkgs
dd3f9a0 @kolmodin distromap: cleaunps
kolmodin authored
95 info verbosity ("found pvus: " ++ show (length pvus))
1dba206 @kolmodin Initial version of distromap
kolmodin authored
96
97 mapM_ (putStrLn . showPVU) pvus
ec5f558 @kolmodin distromap: only print the versions available in hackage
kolmodin authored
98 return ()
1dba206 @kolmodin Initial version of distromap
kolmodin authored
99
100
101 showPVU :: PVU -> String
ec5f558 @kolmodin distromap: only print the versions available in hackage
kolmodin authored
102 showPVU (p,v,u) = show $ (display p, display v, u)
1dba206 @kolmodin Initial version of distromap
kolmodin authored
103
104 -- building the PVU_Map
105
106 reduceVersion :: Portage.Version -> Portage.Version
107 reduceVersion (Portage.Version ns _ _ _) = Portage.Version ns Nothing [] 0
108
109 reduceVersions :: [Portage.Version] -> [Portage.Version]
110 reduceVersions = List.nub . map reduceVersion
111
112 buildMap :: [(Portage.PackageName, [Portage.Version])]
113 -> (Portage.PackageName -> Portage.Version -> Maybe String)
114 -> PVU_Map
ec5f558 @kolmodin distromap: only print the versions available in hackage
kolmodin authored
115 buildMap pvs f = Map.mapWithKey (\p vs -> [ (fromJust $ Portage.toCabalVersion v, f p v)
116 | v <- reduceVersions vs ])
117 (Map.fromList pvs)
1dba206 @kolmodin Initial version of distromap
kolmodin authored
118
ec5f558 @kolmodin distromap: only print the versions available in hackage
kolmodin authored
119 buildPortageMap :: [(Portage.PackageName, [Portage.Version])] -> PVU_Map
120 buildPortageMap lst = buildMap lst $ \ (Portage.PackageName c p) _v ->
121 Just $ "http://packages.gentoo.org/package" </> display c </> display p
1dba206 @kolmodin Initial version of distromap
kolmodin authored
122
ec5f558 @kolmodin distromap: only print the versions available in hackage
kolmodin authored
123 buildOverlayMap :: [(Portage.PackageName, [Portage.Version])] -> PVU_Map
124 buildOverlayMap lst = buildMap lst $ \_ _ -> Just "http://en.gentoo-wiki.com/wiki/Haskell/overlay"
1dba206 @kolmodin Initial version of distromap
kolmodin authored
125
126 unionMap :: PVU_Map -> PVU_Map -> PVU_Map
127 unionMap = Map.unionWith f
128 where
ec5f558 @kolmodin distromap: only print the versions available in hackage
kolmodin authored
129 f :: [(Cabal.Version, Maybe String)]
130 -> [(Cabal.Version, Maybe String)]
131 -> [(Cabal.Version, Maybe String)]
1dba206 @kolmodin Initial version of distromap
kolmodin authored
132 f vas vbs = Map.toList (Map.union (Map.fromList vas) (Map.fromList vbs))
133
134
135 -- resolving Cabal.PackageName to Portage.PackageName
136
ec5f558 @kolmodin distromap: only print the versions available in hackage
kolmodin authored
137 lookupPVU :: PVU_Map -> Cabal.PackageName -> [Cabal.Version] -> [PVU]
138 lookupPVU pvu_map pn cvs =
ad9dce3 @kolmodin distromap: when multiple categories, look in dev-haskell
kolmodin authored
139 case findItems pvu_map (Portage.normalizeCabalPackageName pn) of
ec5f558 @kolmodin distromap: only print the versions available in hackage
kolmodin authored
140 [] -> []
1dba206 @kolmodin Initial version of distromap
kolmodin authored
141 [item] -> ret item
ad9dce3 @kolmodin distromap: when multiple categories, look in dev-haskell
kolmodin authored
142 items | [item] <- preferableItem items -> ret item
143 | otherwise -> trace (noDefaultText items) []
1dba206 @kolmodin Initial version of distromap
kolmodin authored
144 where
ad9dce3 @kolmodin distromap: when multiple categories, look in dev-haskell
kolmodin authored
145 noDefaultText is = unlines $ ("no default for package: " ++ display pn)
146 : [ " * " ++ (display cat)
dd3f9a0 @kolmodin distromap: cleaunps
kolmodin authored
147 | (Portage.PackageName cat _, _) <- is]
ad9dce3 @kolmodin distromap: when multiple categories, look in dev-haskell
kolmodin authored
148
ec5f558 @kolmodin distromap: only print the versions available in hackage
kolmodin authored
149 ret (_, vs) = [ (pn, v, u) | (v, u) <- vs, v `elem` cvs ]
150 preferableItem items =
151 [ item
152 | item@(Portage.PackageName cat _pn, _vs) <- items
153 , cat == Portage.Category "dev-haskell"]
ad9dce3 @kolmodin distromap: when multiple categories, look in dev-haskell
kolmodin authored
154 findItems pvu_map cpn = Map.toList $ Map.filterWithKey f pvu_map
155 where
156 f (Portage.PackageName _cat pn) _vs = cpn == pn
157
158
Something went wrong with that request. Please try again.