Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 404 lines (359 sloc) 16.835 kb
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
1 -- A program for generating a Gentoo ebuild from a .cabal file
2 --
3 -- Author : Duncan Coutts <dcoutts@gentoo.org>
4 --
5 -- Created: 21 July 2005
6 --
7 -- Copyright (C) 2005 Duncan Coutts
8 --
9 -- This library is free software; you can redistribute it and/or
10 -- modify it under the terms of the GNU General Public License
11 -- as published by the Free Software Foundation; either version 2
12 -- of the License, or (at your option) any later version.
13 --
14 -- This library is distributed in the hope that it will be useful,
15 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
16 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 -- General Public License for more details.
18 --
19 -- |
20 -- Maintainer : haskell@gentoo.org
21 --
22 -- cabal2ebuild - a program for generating a Gentoo ebuild from a .cabal file
23 --
24 module Cabal2Ebuild
e35e41e @kolmodin Make merging respect categories
kolmodin authored
25 (EBuild(..)
26 ,cabal2ebuild
27 ,showEBuild) where
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
28
29 import qualified Distribution.PackageDescription as Cabal
87d875b @kolmodin Wall police
kolmodin authored
30 (PackageDescription(..))
d52e140 @trofi hackport-basic-simplification-phase.patch
trofi authored
31 import qualified Distribution.Package as Cabal (PackageIdentifier(..), Dependency(..))
32 import qualified Distribution.Version as Cabal (VersionRange(..), versionBranch, Version)
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
33 import qualified Distribution.License as Cabal (License(..))
d52e140 @trofi hackport-basic-simplification-phase.patch
trofi authored
34 import qualified Distribution.Text as Cabal (display)
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
35 --import qualified Distribution.Compiler as Cabal (CompilerFlavor(..))
36
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
37 import Data.Char (toLower,isUpper)
d52e140 @trofi hackport-basic-simplification-phase.patch
trofi authored
38 import Data.List (intercalate, groupBy, partition, nub, sortBy, init, last)
39 import Data.Ord (comparing)
40 import Data.Maybe (catMaybes, fromJust)
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
41
6ec3592 Hackport now uses Cabal-1.6
Ivan.Miljenovic@gmail.com authored
42 import Index (pName, mkPackage)
43
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
44 data EBuild = EBuild {
45 name :: String,
46 version :: String,
47 description :: String,
48 homepage :: String,
49 src_uri :: String,
50 license :: String,
51 slot :: String,
52 keywords :: [String],
53 iuse :: [String],
54 depend :: [Dependency],
55 features :: [String],
56 -- comments on various fields for communicating stuff to the user
57 licenseComments :: String,
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
58 my_pn :: Maybe String --If the package's name contains upper-case
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
59 }
60
61 type Package = String
d52e140 @trofi hackport-basic-simplification-phase.patch
trofi authored
62 newtype Version = Version [Int] deriving (Ord, Eq)
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
63 type UseFlag = String
64 data Dependency = AnyVersionOf Package
65 | ThisVersionOf Version Package -- =package-version
66 | LaterVersionOf Version Package -- >package-version
67 | EarlierVersionOf Version Package -- <package-version
68 | OrLaterVersionOf Version Package -- >=package-version
69 | OrEarlierVersionOf Version Package -- <=package-version
70 | DependEither Dependency Dependency -- depend || depend
71 | DependIfUse UseFlag Dependency -- use? ( depend )
3726ec1 @trofi hackport-cabal2ebuild-string-to-int-representation.patch
trofi authored
72 | ThisMajorOf Version Package -- =package-version*
d52e140 @trofi hackport-basic-simplification-phase.patch
trofi authored
73 deriving Eq
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
74
87d875b @kolmodin Wall police
kolmodin authored
75 ebuildTemplate :: EBuild
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
76 ebuildTemplate = EBuild {
77 name = "foobar",
78 version = "0.1",
79 description = "",
80 homepage = "",
81 src_uri = "",
82 license = "",
83 slot = "0",
63b57b8 Adapted HackPort to the new Hackage interface
der_eq@freenet.de authored
84 keywords = ["~amd64","~x86"],
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
85 iuse = [],
86 depend = [],
c81b055 profile and haddock only make sense for lib packages
Duncan Coutts authored
87 features = [],
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
88 licenseComments = "",
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
89 my_pn = Nothing
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
90 }
91
d52e140 @trofi hackport-basic-simplification-phase.patch
trofi authored
92
93
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
94 cabal2ebuild :: Cabal.PackageDescription -> EBuild
95 cabal2ebuild pkg = ebuildTemplate {
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
96 name = map toLower cabalPkgName,
d52e140 @trofi hackport-basic-simplification-phase.patch
trofi authored
97 version = Cabal.display (Cabal.pkgVersion (Cabal.package pkg)),
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
98 description = if null (Cabal.synopsis pkg) then Cabal.description pkg
99 else Cabal.synopsis pkg,
100 homepage = Cabal.homepage pkg,
101 src_uri = Cabal.pkgUrl pkg,
102 license = convertLicense (Cabal.license pkg),
103 licenseComments = licenseComment (Cabal.license pkg),
104 depend = defaultDepGHC
d52e140 @trofi hackport-basic-simplification-phase.patch
trofi authored
105 : (simplify_deps $
6ec3592 Hackport now uses Cabal-1.6
Ivan.Miljenovic@gmail.com authored
106 convertDependency (Cabal.Dependency (mkPackage "Cabal")
d52e140 @trofi hackport-basic-simplification-phase.patch
trofi authored
107 (Cabal.descCabalVersion pkg))
108 ++ convertDependencies (Cabal.buildDepends pkg)),
20179c4 Set S= properly for packages with upper case names
Duncan Coutts authored
109 my_pn = if any isUpper cabalPkgName then Just cabalPkgName else Nothing,
f5d6f88 reorder the features list
Duncan Coutts authored
110 features = features ebuildTemplate
4c4b676 @kolmodin Fix subtile bug with missing features
kolmodin authored
111 ++ (if null (Cabal.executables pkg) then [] else ["bin"])
6b4364c Include the new hscolour feature
Stephan Friedrichs authored
112 ++ maybe [] (const ["lib","profile","haddock","hscolour"]) (Cabal.library pkg)
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
113 } where
6ec3592 Hackport now uses Cabal-1.6
Ivan.Miljenovic@gmail.com authored
114 cabalPkgName = pName $ Cabal.pkgName (Cabal.package pkg)
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
115
87d875b @kolmodin Wall police
kolmodin authored
116 defaultDepGHC :: Dependency
3726ec1 @trofi hackport-cabal2ebuild-string-to-int-representation.patch
trofi authored
117 defaultDepGHC = OrLaterVersionOf (Version [6,6,1]) "dev-lang/ghc"
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
118
119 -- map the cabal license type to the gentoo license string format
120 convertLicense :: Cabal.License -> String
121 convertLicense Cabal.GPL = "GPL-2" -- almost certainly version 2
122 convertLicense Cabal.LGPL = "LGPL-2.1" -- probably version 2.1
123 convertLicense Cabal.BSD3 = "BSD" -- do we really not
124 convertLicense Cabal.BSD4 = "BSD" -- distinguish between these?
125 convertLicense Cabal.PublicDomain = "public-domain"
126 convertLicense Cabal.AllRightsReserved = ""
127 convertLicense _ = ""
128
87d875b @kolmodin Wall police
kolmodin authored
129 licenseComment :: Cabal.License -> String
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
130 licenseComment Cabal.AllRightsReserved =
131 "Note: packages without a license cannot be included in portage"
132 licenseComment Cabal.OtherLicense =
133 "Fixme: \"OtherLicense\", please fill in manually"
134 licenseComment _ = ""
135
136 convertDependencies :: [Cabal.Dependency] -> [Dependency]
ace40ea Cope with IntersectVersionRanges, at least partially
Duncan Coutts authored
137 convertDependencies = concatMap convertDependency
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
138
ace40ea Cope with IntersectVersionRanges, at least partially
Duncan Coutts authored
139 convertDependency :: Cabal.Dependency -> [Dependency]
87d875b @kolmodin Wall police
kolmodin authored
140 convertDependency (Cabal.Dependency pname _)
6ec3592 Hackport now uses Cabal-1.6
Ivan.Miljenovic@gmail.com authored
141 | (pName pname) `elem` coreLibs = [] -- no explicit dep on core libs
87d875b @kolmodin Wall police
kolmodin authored
142 convertDependency (Cabal.Dependency pname versionRange)
ace40ea Cope with IntersectVersionRanges, at least partially
Duncan Coutts authored
143 = case versionRange of
144 (Cabal.IntersectVersionRanges v1 v2) -> [convert v1, convert v2]
145 v -> [convert v]
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
146
147 where
6ec3592 Hackport now uses Cabal-1.6
Ivan.Miljenovic@gmail.com authored
148 ebuildName = "dev-haskell/" ++ map toLower (pName pname)
9448bb7 @kolmodin Rewritten overlayonly functionality
kolmodin authored
149
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
150 convert :: Cabal.VersionRange -> Dependency
151 convert Cabal.AnyVersion = AnyVersionOf ebuildName
d52e140 @trofi hackport-basic-simplification-phase.patch
trofi authored
152 convert (Cabal.ThisVersion v) = ThisVersionOf (cabalVtoHPv v) ebuildName
153 convert (Cabal.LaterVersion v) = LaterVersionOf (cabalVtoHPv v) ebuildName
154 convert (Cabal.EarlierVersion v) = EarlierVersionOf (cabalVtoHPv v) ebuildName
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
155 convert (Cabal.UnionVersionRanges (Cabal.ThisVersion v1) (Cabal.LaterVersion v2))
d52e140 @trofi hackport-basic-simplification-phase.patch
trofi authored
156 | v1 == v2 = OrLaterVersionOf (cabalVtoHPv v1) ebuildName
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
157 convert (Cabal.UnionVersionRanges (Cabal.ThisVersion v1) (Cabal.EarlierVersion v2))
d52e140 @trofi hackport-basic-simplification-phase.patch
trofi authored
158 | v1 == v2 = OrEarlierVersionOf (cabalVtoHPv v1) ebuildName
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
159 convert (Cabal.UnionVersionRanges r1 r2)
160 = DependEither (convert r1) (convert r2)
161
3726ec1 @trofi hackport-cabal2ebuild-string-to-int-representation.patch
trofi authored
162 -- converts Cabal versiion type to hackopr version
163 cabalVtoHPv :: Cabal.Version -> Version
164 cabalVtoHPv = Version . Cabal.versionBranch
165
166 instance Show Version where
167 show (Version v) = intercalate "." $ map show v
168
87d875b @kolmodin Wall police
kolmodin authored
169 coreLibs :: [String]
5bcf377 Update hackport's ebuild generation to current conventions.
Duncan Coutts authored
170 coreLibs =
61f04b0 Update list of core libs
Duncan Coutts authored
171 ["array"
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
172 ,"base"
61f04b0 Update list of core libs
Duncan Coutts authored
173 --,"bytestring" --already has ebuild
174 ,"containers"
175 ,"directory"
176 --,"filepath" --already has ebuild
177 ,"ghc"
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
178 ,"haskell98"
2f85f14 @kolmodin Write comments about core packages
kolmodin authored
179 ,"hpc" --has ebuild, but only in the overlay
61f04b0 Update list of core libs
Duncan Coutts authored
180 ,"old-locale"
181 ,"old-time"
182 ,"packedstring"
183 ,"pretty"
184 ,"process"
185 ,"random"
2f85f14 @kolmodin Write comments about core packages
kolmodin authored
186 ,"readline" --has ebuild, but only in the overlay
61f04b0 Update list of core libs
Duncan Coutts authored
187 ,"rts"
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
188 ,"template-haskell"
2f85f14 @kolmodin Write comments about core packages
kolmodin authored
189 ,"unix" --has ebuild, but only in the overlay
61f04b0 Update list of core libs
Duncan Coutts authored
190 ]
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
191
192 showEBuild :: EBuild -> String
193 showEBuild ebuild =
53c877c @kolmodin Change to correct ebuild header
kolmodin authored
194 ss "# Copyright 1999-2008 Gentoo Foundation". nl.
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
195 ss "# Distributed under the terms of the GNU General Public License v2". nl.
196 ss "# $Header: $". nl.
197 nl.
198 ss "CABAL_FEATURES=". quote' (sepBy " " $ features ebuild). nl.
199 ss "inherit haskell-cabal". nl.
200 nl.
20179c4 Set S= properly for packages with upper case names
Duncan Coutts authored
201 (case my_pn ebuild of
202 Nothing -> id
203 Just pn -> ss "MY_PN=". quote pn. nl.
204 ss "MY_P=". quote "${MY_PN}-${PV}". nl. nl).
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
205 ss "DESCRIPTION=". quote (description ebuild). nl.
206 ss "HOMEPAGE=". quote (homepage ebuild). nl.
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
207 ss "SRC_URI=". quote (replaceVars (src_uri ebuild)).
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
208 (if null (src_uri ebuild) then ss "\t#Fixme: please fill in manually"
209 else id). nl.
5bcf377 Update hackport's ebuild generation to current conventions.
Duncan Coutts authored
210 nl.
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
211 ss "LICENSE=". quote (license ebuild).
212 (if null (licenseComments ebuild) then id
213 else ss "\t#". ss (licenseComments ebuild)). nl.
214 ss "SLOT=". quote (slot ebuild). nl.
63b57b8 Adapted HackPort to the new Hackage interface
der_eq@freenet.de authored
215 ss "KEYWORDS=". quote' (sepBy " " $ keywords ebuild).nl.
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
216 ss "IUSE=". quote' (sepBy ", " $ iuse ebuild). nl.
217 nl.
218 ss "DEPEND=". quote' (sepBy "\n\t\t" $ map showDepend $ depend ebuild). nl.
20179c4 Set S= properly for packages with upper case names
Duncan Coutts authored
219 (case my_pn ebuild of
220 Nothing -> id
87d875b @kolmodin Wall police
kolmodin authored
221 Just _ -> nl. ss "S=". quote ("${WORKDIR}/${MY_P}"). nl)
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
222 $ []
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
223 where replaceVars = replaceCommonVars (name ebuild) (my_pn ebuild) (version ebuild)
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
224
87d875b @kolmodin Wall police
kolmodin authored
225 showDepend :: Dependency -> Package
226 showDepend (AnyVersionOf p) = p
3726ec1 @trofi hackport-cabal2ebuild-string-to-int-representation.patch
trofi authored
227 showDepend (ThisVersionOf v p) = "~" ++ p ++ "-" ++ show v
228 showDepend (LaterVersionOf v p) = ">" ++ p ++ "-" ++ show v
229 showDepend (EarlierVersionOf v p) = "<" ++ p ++ "-" ++ show v
230 showDepend (OrLaterVersionOf v p) = ">=" ++ p ++ "-" ++ show v
231 showDepend (OrEarlierVersionOf v p) = "<=" ++ p ++ "-" ++ show v
87d875b @kolmodin Wall police
kolmodin authored
232 showDepend (DependEither dep1 dep2) = showDepend dep1
233 ++ " || " ++ showDepend dep2
6ec3592 Hackport now uses Cabal-1.6
Ivan.Miljenovic@gmail.com authored
234 showDepend (DependIfUse useflag dep@(DependEither _ _))
87d875b @kolmodin Wall police
kolmodin authored
235 = useflag ++ "? " ++ showDepend dep
236 showDepend (DependIfUse useflag dep) = useflag ++ "? ( " ++ showDepend dep++ " )"
3726ec1 @trofi hackport-cabal2ebuild-string-to-int-representation.patch
trofi authored
237 showDepend (ThisMajorOf v p) = "=" ++ p ++ "-" ++ show v ++ "*"
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
238
87d875b @kolmodin Wall police
kolmodin authored
239 ss :: String -> String -> String
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
240 ss = showString
87d875b @kolmodin Wall police
kolmodin authored
241
242 sc :: Char -> String -> String
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
243 sc = showChar
87d875b @kolmodin Wall police
kolmodin authored
244
245 nl :: String -> String
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
246 nl = sc '\n'
247
87d875b @kolmodin Wall police
kolmodin authored
248 quote :: String -> String -> String
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
249 quote str = sc '"'. ss str. sc '"'
87d875b @kolmodin Wall police
kolmodin authored
250
251 quote' :: (String -> String) -> String -> String
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
252 quote' str = sc '"'. str. sc '"'
253
254 sepBy :: String -> [String] -> ShowS
87d875b @kolmodin Wall police
kolmodin authored
255 sepBy _ [] = id
256 sepBy _ [x] = ss x
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
257 sepBy s (x:xs) = ss x. ss s. sepBy s xs
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
258
259 getRestIfPrefix ::
260 String -> -- ^ the prefix
261 String -> -- ^ the string
262 Maybe String
263 getRestIfPrefix (p:ps) (x:xs) = if p==x then getRestIfPrefix ps xs else Nothing
264 getRestIfPrefix [] rest = Just rest
265 getRestIfPrefix _ [] = Nothing
266
267 subStr ::
268 String -> -- ^ the search string
269 String -> -- ^ the string to be searched
9448bb7 @kolmodin Rewritten overlayonly functionality
kolmodin authored
270 Maybe (String,String) -- ^ Just (pre,post) if string is found
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
271 subStr sstr str = case getRestIfPrefix sstr str of
272 Nothing -> if null str then Nothing else case subStr sstr (tail str) of
273 Nothing -> Nothing
274 Just (pre,post) -> Just (head str:pre,post)
275 Just rest -> Just ([],rest)
276
277 replaceMultiVars ::
278 [(String,String)] -> -- ^ pairs of variable name and content
279 String -> -- ^ string to be searched
280 String -- ^ the result
281 replaceMultiVars [] str = str
87d875b @kolmodin Wall police
kolmodin authored
282 replaceMultiVars whole@((pname,cont):rest) str = case subStr cont str of
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
283 Nothing -> replaceMultiVars rest str
87d875b @kolmodin Wall police
kolmodin authored
284 Just (pre,post) -> (replaceMultiVars rest pre)++pname++(replaceMultiVars whole post)
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
285
286 replaceCommonVars ::
287 String -> -- ^ PN
288 Maybe String -> -- ^ MYPN
289 String -> -- ^ PV
290 String -> -- ^ the string to be replaced
291 String
292 replaceCommonVars pn mypn pv str
293 = replaceMultiVars
294 ([("${P}",pn++"-"++pv)]
295 ++ maybe [] (\x->[("${MY_P}",x++"-"++pv)]) mypn
296 ++[("${PN}",pn)]
297 ++ maybe [] (\x->[("${MY_PN}",x)]) mypn
298 ++[("${PV}",pv)]) str
d52e140 @trofi hackport-basic-simplification-phase.patch
trofi authored
299
300
301 {- Here goes code for dependencies simplification -}
302
303 simplify_group_table :: Package ->
304 Maybe Version ->
305 Maybe Version ->
306 Maybe Version ->
307 Maybe Version ->
308 Maybe Version -> [Dependency]
309
6ec3592 Hackport now uses Cabal-1.6
Ivan.Miljenovic@gmail.com authored
310 -- simplify_group_table p ol l e oe exact
d52e140 @trofi hackport-basic-simplification-phase.patch
trofi authored
311 -- 1) trivial cases:
312 simplify_group_table p Nothing Nothing Nothing Nothing Nothing = error $ p ++ ": unsolvable constraints"
313 simplify_group_table p (Just v) Nothing Nothing Nothing Nothing = [OrLaterVersionOf v p]
314 simplify_group_table p Nothing (Just v) Nothing Nothing Nothing = [LaterVersionOf v p]
315 simplify_group_table p Nothing Nothing (Just v) Nothing Nothing = [EarlierVersionOf v p]
316 simplify_group_table p Nothing Nothing Nothing (Just v) Nothing = [OrEarlierVersionOf v p]
317 simplify_group_table p Nothing Nothing Nothing Nothing (Just v) = [ThisVersionOf v p]
318
319 -- 2) simplification passes
320 simplify_group_table p (Just (Version v1)) Nothing (Just (Version v2)) Nothing Nothing
321 -- specian case: >=a-v.N a<v.(N+1) => =a-v.N*
322 | (init v1 == init v2) && (last v2 == last v1 + 1) = [ThisMajorOf (Version v1) p]
323 | otherwise = [OrLaterVersionOf (Version v1) p, EarlierVersionOf (Version v2) p]
324
325 -- TODO: simplify constraints of type: >=a-v1; > a-v2 and such
326
327 -- o3) therwise sink:
328 simplify_group_table p (Just v) l@(_) e@(_) oe@(_) exact@(_) = OrLaterVersionOf v p : simplify_group_table p Nothing l e oe exact
329 simplify_group_table p ol@(Nothing) (Just v) e@(_) oe@(_) exact@(_) = LaterVersionOf v p : simplify_group_table p ol Nothing e oe exact
330 simplify_group_table p ol@(Nothing) l@(Nothing) (Just v) oe@(_) exact@(_) = EarlierVersionOf v p : simplify_group_table p ol l Nothing oe exact
331 simplify_group_table p ol@(Nothing) l@(Nothing) e@(Nothing) (Just v) exact@(_) = OrEarlierVersionOf v p : simplify_group_table p ol l e Nothing exact
332 -- already defined earlier
333 -- simplify_group_table p ol@(Nothing) l@(Nothing) e@(Nothing) oe@(Nothing) (Just v) = OrEarlierVersionOf v p : simplify_group_table p ol l e oe Nothing
334
335 -- >a-v1 >a-v2 => >a-(max v1 v2)
336 -- key idea: all constraints are enforcing constraints, so we can't get
337 -- more, than one interval.
338 simplify_group :: [Dependency] -> [Dependency]
339 simplify_group [dep@(AnyVersionOf _package)] = [dep]
340 simplify_group deps = simplify_group_table package
341 min_or_later_v -- >=
342 min_later_v -- >
343 max_earlier_v -- <
344 max_or_earlier_v -- <=
345 exact_this_v -- ==
346 where
347 package = fromJust.getPackage $ head deps
348 max_earlier_v = safe_minimum $ map earlier_v deps
349 max_or_earlier_v = safe_minimum $ map or_earlier_v deps
350 min_later_v = safe_maximum $ map later_v deps
351 min_or_later_v = safe_maximum $ map or_later_v deps
352 exact_this_v = case catMaybes (map this_v deps) of
353 [] -> Nothing
354 [v] -> Just v
355 xs -> error $ "too many exact versions:" ++ show xs
356 --
357 earlier_v (EarlierVersionOf v _p) = Just v
358 earlier_v _ = Nothing
359
360 or_earlier_v (OrEarlierVersionOf v _p) = Just v
361 or_earlier_v _ = Nothing
362
363 later_v (LaterVersionOf v _p) = Just v
364 later_v _ = Nothing
365
366 or_later_v (OrLaterVersionOf v _p) = Just v
367 or_later_v _ = Nothing
368
369 this_v (ThisVersionOf v _p) = Just v
370 this_v _ = Nothing
371 --
372 safe_minimum xs = case catMaybes xs of
373 [] -> Nothing
374 xs' -> Just $ minimum xs'
375 safe_maximum xs = case catMaybes xs of
376 [] -> Nothing
377 xs' -> Just $ maximum xs'
378
379 -- divide packages to groups (by package name), simplify groups, merge again
380 simplify_deps :: [Dependency] -> [Dependency]
381 simplify_deps deps = (concatMap (simplify_group.nub) $
382 groupBy cmpPkgName $
383 sortBy (comparing getPackageString) groupable)
384 ++ ungroupable
385 where (ungroupable, groupable) = partition ((==Nothing).getPackage) deps
386 --
387 cmpPkgName p1 p2 = cmpMaybe (getPackage p1) (getPackage p2)
388 cmpMaybe (Just p1) (Just p2) = p1 == p2
389 cmpMaybe _ _ = False
390 --
391 getPackage :: Dependency -> Maybe Package
392 getPackage (AnyVersionOf package) = Just package
393 getPackage (ThisVersionOf _version package) = Just package
394 getPackage (LaterVersionOf _version package) = Just package
395 getPackage (EarlierVersionOf _version package) = Just package
396 getPackage (OrLaterVersionOf _version package) = Just package
397 getPackage (OrEarlierVersionOf _version package) = Just package
398 getPackage (DependEither _dependency _Dependency) = Nothing
399 getPackage (DependIfUse _useFlag _Dependency) = Nothing
400 getPackage (ThisMajorOf _version package) = Just package
401 --
402 getPackageString :: Dependency -> Package
403 getPackageString dep = maybe "" id $ getPackage dep
Something went wrong with that request. Please try again.