Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 413 lines (371 sloc) 17.407 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 Lennart Kolmodin Make merging respect categories
kolmodin authored
25 (EBuild(..)
cb4a7bb Lennart Kolmodin Start on translating extra-libraries into ebuild deps
kolmodin authored
26 ,Dependency(..)
e35e41e Lennart Kolmodin Make merging respect categories
kolmodin authored
27 ,cabal2ebuild
cb4a7bb Lennart Kolmodin Start on translating extra-libraries into ebuild deps
kolmodin authored
28 ,convertDependencies
e35e41e Lennart 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 Lennart Kolmodin Wall police
kolmodin authored
32 (PackageDescription(..))
8273e68 Lennart 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 Sergei Trofimovich 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 Sergei Trofimovich 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 Sergei Trofimovich 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 Sergei Trofimovich 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 Sergei Trofimovich hackport-cabal2ebuild-string-to-int-representation.patch
trofi authored
74 | ThisMajorOf Version Package -- =package-version*
cb4a7bb Lennart 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 Lennart 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 Sergei Trofimovich 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 Sergei Trofimovich hackport-basic-simplification-phase.patch
trofi authored
105 : (simplify_deps $
8273e68 Lennart Kolmodin Update the CLI and start using cabal-install features
kolmodin authored
106 convertDependency (Cabal.Dependency (Cabal.PackageName "Cabal")
d52e140 Sergei Trofimovich 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 Lennart 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 Lennart 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 Lennart Kolmodin Wall police
kolmodin authored
118 defaultDepGHC :: Dependency
3726ec1 Sergei Trofimovich 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 Lennart 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 Sergei Trofimovich Some more -Wall fixes (import refinements + unused -> _unused)
trofi authored
142 convertDependency (Cabal.Dependency pname@(Cabal.PackageName _name) _)
8273e68 Lennart Kolmodin Update the CLI and start using cabal-install features
kolmodin authored
143 | pname `elem` coreLibs = [] -- no explicit dep on core libs
87d875b Lennart 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 Lennart 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 Lennart 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 Lennart 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 Lennart Kolmodin Update the CLI and start using cabal-install features
kolmodin authored
154 ebuildName = "dev-haskell/" ++ map toLower (Cabal.display pname)
9448bb7 Lennart 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 Sergei Trofimovich 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 Sergei Trofimovich 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 Sergei Trofimovich 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 Sergei Trofimovich 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 Lennart 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"
136cbd4 Lennart Kolmodin We do need editline dependencies
kolmodin authored
182 --,"editline"
61f04b0 Update list of core libs
Duncan Coutts authored
183 --,"filepath" --already has ebuild
184 ,"ghc"
285f6b1 Lennart Kolmodin Add missing core libs to list
kolmodin authored
185 ,"ghc-prim"
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
186 ,"haskell98"
2f85f14 Lennart Kolmodin Write comments about core packages
kolmodin authored
187 ,"hpc" --has ebuild, but only in the overlay
285f6b1 Lennart Kolmodin Add missing core libs to list
kolmodin authored
188 ,"integer"
61f04b0 Update list of core libs
Duncan Coutts authored
189 ,"old-locale"
190 ,"old-time"
191 ,"packedstring"
192 ,"pretty"
193 ,"process"
194 ,"random"
2f85f14 Lennart Kolmodin Write comments about core packages
kolmodin authored
195 ,"readline" --has ebuild, but only in the overlay
61f04b0 Update list of core libs
Duncan Coutts authored
196 ,"rts"
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
197 ,"template-haskell"
2f85f14 Lennart Kolmodin Write comments about core packages
kolmodin authored
198 ,"unix" --has ebuild, but only in the overlay
61f04b0 Update list of core libs
Duncan Coutts authored
199 ]
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
200
201 showEBuild :: EBuild -> String
202 showEBuild ebuild =
decf164 Lennart Kolmodin Bump Copyright header
kolmodin authored
203 ss "# Copyright 1999-2009 Gentoo Foundation". nl.
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
204 ss "# Distributed under the terms of the GNU General Public License v2". nl.
205 ss "# $Header: $". nl.
206 nl.
207 ss "CABAL_FEATURES=". quote' (sepBy " " $ features ebuild). nl.
208 ss "inherit haskell-cabal". nl.
209 nl.
20179c4 Set S= properly for packages with upper case names
Duncan Coutts authored
210 (case my_pn ebuild of
211 Nothing -> id
212 Just pn -> ss "MY_PN=". quote pn. nl.
213 ss "MY_P=". quote "${MY_PN}-${PV}". nl. nl).
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
214 ss "DESCRIPTION=". quote (description ebuild). nl.
215 ss "HOMEPAGE=". quote (homepage ebuild). nl.
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
216 ss "SRC_URI=". quote (replaceVars (src_uri ebuild)).
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
217 (if null (src_uri ebuild) then ss "\t#Fixme: please fill in manually"
218 else id). nl.
5bcf377 Update hackport's ebuild generation to current conventions.
Duncan Coutts authored
219 nl.
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
220 ss "LICENSE=". quote (license ebuild).
221 (if null (licenseComments ebuild) then id
222 else ss "\t#". ss (licenseComments ebuild)). nl.
223 ss "SLOT=". quote (slot ebuild). nl.
63b57b8 Adapted HackPort to the new Hackage interface
der_eq@freenet.de authored
224 ss "KEYWORDS=". quote' (sepBy " " $ keywords ebuild).nl.
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
225 ss "IUSE=". quote' (sepBy ", " $ iuse ebuild). nl.
226 nl.
227 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
228 (case my_pn ebuild of
229 Nothing -> id
87d875b Lennart Kolmodin Wall police
kolmodin authored
230 Just _ -> nl. ss "S=". quote ("${WORKDIR}/${MY_P}"). nl)
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
231 $ []
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
232 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
233
87d875b Lennart Kolmodin Wall police
kolmodin authored
234 showDepend :: Dependency -> Package
235 showDepend (AnyVersionOf p) = p
3726ec1 Sergei Trofimovich hackport-cabal2ebuild-string-to-int-representation.patch
trofi authored
236 showDepend (ThisVersionOf v p) = "~" ++ p ++ "-" ++ show v
237 showDepend (LaterVersionOf v p) = ">" ++ p ++ "-" ++ show v
238 showDepend (EarlierVersionOf v p) = "<" ++ p ++ "-" ++ show v
239 showDepend (OrLaterVersionOf v p) = ">=" ++ p ++ "-" ++ show v
240 showDepend (OrEarlierVersionOf v p) = "<=" ++ p ++ "-" ++ show v
87d875b Lennart Kolmodin Wall police
kolmodin authored
241 showDepend (DependEither dep1 dep2) = showDepend dep1
242 ++ " || " ++ showDepend dep2
6ec3592 Hackport now uses Cabal-1.6
Ivan.Miljenovic@gmail.com authored
243 showDepend (DependIfUse useflag dep@(DependEither _ _))
87d875b Lennart Kolmodin Wall police
kolmodin authored
244 = useflag ++ "? " ++ showDepend dep
245 showDepend (DependIfUse useflag dep) = useflag ++ "? ( " ++ showDepend dep++ " )"
3726ec1 Sergei Trofimovich hackport-cabal2ebuild-string-to-int-representation.patch
trofi authored
246 showDepend (ThisMajorOf v p) = "=" ++ p ++ "-" ++ show v ++ "*"
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
247
87d875b Lennart Kolmodin Wall police
kolmodin authored
248 ss :: String -> String -> String
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
249 ss = showString
87d875b Lennart Kolmodin Wall police
kolmodin authored
250
251 sc :: Char -> String -> String
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
252 sc = showChar
87d875b Lennart Kolmodin Wall police
kolmodin authored
253
254 nl :: String -> String
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
255 nl = sc '\n'
256
87d875b Lennart Kolmodin Wall police
kolmodin authored
257 quote :: String -> String -> String
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
258 quote str = sc '"'. ss str. sc '"'
87d875b Lennart Kolmodin Wall police
kolmodin authored
259
260 quote' :: (String -> String) -> String -> String
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
261 quote' str = sc '"'. str. sc '"'
262
263 sepBy :: String -> [String] -> ShowS
87d875b Lennart Kolmodin Wall police
kolmodin authored
264 sepBy _ [] = id
265 sepBy _ [x] = ss x
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
266 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
267
268 getRestIfPrefix ::
269 String -> -- ^ the prefix
270 String -> -- ^ the string
271 Maybe String
272 getRestIfPrefix (p:ps) (x:xs) = if p==x then getRestIfPrefix ps xs else Nothing
273 getRestIfPrefix [] rest = Just rest
274 getRestIfPrefix _ [] = Nothing
275
276 subStr ::
277 String -> -- ^ the search string
278 String -> -- ^ the string to be searched
9448bb7 Lennart Kolmodin Rewritten overlayonly functionality
kolmodin authored
279 Maybe (String,String) -- ^ Just (pre,post) if string is found
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
280 subStr sstr str = case getRestIfPrefix sstr str of
281 Nothing -> if null str then Nothing else case subStr sstr (tail str) of
282 Nothing -> Nothing
283 Just (pre,post) -> Just (head str:pre,post)
284 Just rest -> Just ([],rest)
285
286 replaceMultiVars ::
287 [(String,String)] -> -- ^ pairs of variable name and content
288 String -> -- ^ string to be searched
289 String -- ^ the result
290 replaceMultiVars [] str = str
87d875b Lennart Kolmodin Wall police
kolmodin authored
291 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
292 Nothing -> replaceMultiVars rest str
87d875b Lennart Kolmodin Wall police
kolmodin authored
293 Just (pre,post) -> (replaceMultiVars rest pre)++pname++(replaceMultiVars whole post)
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
294
295 replaceCommonVars ::
296 String -> -- ^ PN
297 Maybe String -> -- ^ MYPN
298 String -> -- ^ PV
299 String -> -- ^ the string to be replaced
300 String
301 replaceCommonVars pn mypn pv str
302 = replaceMultiVars
303 ([("${P}",pn++"-"++pv)]
304 ++ maybe [] (\x->[("${MY_P}",x++"-"++pv)]) mypn
305 ++[("${PN}",pn)]
306 ++ maybe [] (\x->[("${MY_PN}",x)]) mypn
307 ++[("${PV}",pv)]) str
d52e140 Sergei Trofimovich hackport-basic-simplification-phase.patch
trofi authored
308
309
310 {- Here goes code for dependencies simplification -}
311
312 simplify_group_table :: Package ->
313 Maybe Version ->
314 Maybe Version ->
315 Maybe Version ->
316 Maybe Version ->
317 Maybe Version -> [Dependency]
318
6ec3592 Hackport now uses Cabal-1.6
Ivan.Miljenovic@gmail.com authored
319 -- simplify_group_table p ol l e oe exact
d52e140 Sergei Trofimovich hackport-basic-simplification-phase.patch
trofi authored
320 -- 1) trivial cases:
321 simplify_group_table p Nothing Nothing Nothing Nothing Nothing = error $ p ++ ": unsolvable constraints"
322 simplify_group_table p (Just v) Nothing Nothing Nothing Nothing = [OrLaterVersionOf v p]
323 simplify_group_table p Nothing (Just v) Nothing Nothing Nothing = [LaterVersionOf v p]
324 simplify_group_table p Nothing Nothing (Just v) Nothing Nothing = [EarlierVersionOf v p]
325 simplify_group_table p Nothing Nothing Nothing (Just v) Nothing = [OrEarlierVersionOf v p]
326 simplify_group_table p Nothing Nothing Nothing Nothing (Just v) = [ThisVersionOf v p]
327
328 -- 2) simplification passes
329 simplify_group_table p (Just (Version v1)) Nothing (Just (Version v2)) Nothing Nothing
330 -- specian case: >=a-v.N a<v.(N+1) => =a-v.N*
331 | (init v1 == init v2) && (last v2 == last v1 + 1) = [ThisMajorOf (Version v1) p]
332 | otherwise = [OrLaterVersionOf (Version v1) p, EarlierVersionOf (Version v2) p]
333
334 -- TODO: simplify constraints of type: >=a-v1; > a-v2 and such
335
336 -- o3) therwise sink:
337 simplify_group_table p (Just v) l@(_) e@(_) oe@(_) exact@(_) = OrLaterVersionOf v p : simplify_group_table p Nothing l e oe exact
338 simplify_group_table p ol@(Nothing) (Just v) e@(_) oe@(_) exact@(_) = LaterVersionOf v p : simplify_group_table p ol Nothing e oe exact
339 simplify_group_table p ol@(Nothing) l@(Nothing) (Just v) oe@(_) exact@(_) = EarlierVersionOf v p : simplify_group_table p ol l Nothing oe exact
340 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
341 -- already defined earlier
342 -- 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
343
344 -- >a-v1 >a-v2 => >a-(max v1 v2)
345 -- key idea: all constraints are enforcing constraints, so we can't get
346 -- more, than one interval.
347 simplify_group :: [Dependency] -> [Dependency]
348 simplify_group [dep@(AnyVersionOf _package)] = [dep]
349 simplify_group deps = simplify_group_table package
350 min_or_later_v -- >=
351 min_later_v -- >
352 max_earlier_v -- <
353 max_or_earlier_v -- <=
354 exact_this_v -- ==
355 where
356 package = fromJust.getPackage $ head deps
357 max_earlier_v = safe_minimum $ map earlier_v deps
358 max_or_earlier_v = safe_minimum $ map or_earlier_v deps
359 min_later_v = safe_maximum $ map later_v deps
360 min_or_later_v = safe_maximum $ map or_later_v deps
361 exact_this_v = case catMaybes (map this_v deps) of
362 [] -> Nothing
363 [v] -> Just v
364 xs -> error $ "too many exact versions:" ++ show xs
365 --
366 earlier_v (EarlierVersionOf v _p) = Just v
367 earlier_v _ = Nothing
368
369 or_earlier_v (OrEarlierVersionOf v _p) = Just v
370 or_earlier_v _ = Nothing
371
372 later_v (LaterVersionOf v _p) = Just v
373 later_v _ = Nothing
374
375 or_later_v (OrLaterVersionOf v _p) = Just v
376 or_later_v _ = Nothing
377
378 this_v (ThisVersionOf v _p) = Just v
379 this_v _ = Nothing
380 --
381 safe_minimum xs = case catMaybes xs of
382 [] -> Nothing
383 xs' -> Just $ minimum xs'
384 safe_maximum xs = case catMaybes xs of
385 [] -> Nothing
386 xs' -> Just $ maximum xs'
387
388 -- divide packages to groups (by package name), simplify groups, merge again
389 simplify_deps :: [Dependency] -> [Dependency]
390 simplify_deps deps = (concatMap (simplify_group.nub) $
391 groupBy cmpPkgName $
392 sortBy (comparing getPackageString) groupable)
393 ++ ungroupable
394 where (ungroupable, groupable) = partition ((==Nothing).getPackage) deps
395 --
396 cmpPkgName p1 p2 = cmpMaybe (getPackage p1) (getPackage p2)
397 cmpMaybe (Just p1) (Just p2) = p1 == p2
398 cmpMaybe _ _ = False
399 --
400 getPackage :: Dependency -> Maybe Package
401 getPackage (AnyVersionOf package) = Just package
402 getPackage (ThisVersionOf _version package) = Just package
403 getPackage (LaterVersionOf _version package) = Just package
404 getPackage (EarlierVersionOf _version package) = Just package
405 getPackage (OrLaterVersionOf _version package) = Just package
406 getPackage (OrEarlierVersionOf _version package) = Just package
407 getPackage (DependEither _dependency _Dependency) = Nothing
408 getPackage (DependIfUse _useFlag _Dependency) = Nothing
409 getPackage (ThisMajorOf _version package) = Just package
410 --
411 getPackageString :: Dependency -> Package
412 getPackageString dep = maybe "" id $ getPackage dep
Something went wrong with that request. Please try again.