Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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