Skip to content

HTTPS clone URL

Subversion checkout URL

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