Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 409 lines (368 sloc) 17.364 kb
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
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
e35e41e6 » kolmodin
2007-08-19 Make merging respect categories
25 (EBuild(..)
cb4a7bb9 » kolmodin
2009-03-01 Start on translating extra-libraries into ebuild deps
26 ,Dependency(..)
e35e41e6 » kolmodin
2007-08-19 Make merging respect categories
27 ,cabal2ebuild
cb4a7bb9 » kolmodin
2009-03-01 Start on translating extra-libraries into ebuild deps
28 ,convertDependencies
e35e41e6 » kolmodin
2007-08-19 Make merging respect categories
29 ,showEBuild) where
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
30
31 import qualified Distribution.PackageDescription as Cabal
87d875b3 » kolmodin
2008-03-15 Wall police
32 (PackageDescription(..))
8273e68c » kolmodin
2009-02-07 Update the CLI and start using cabal-install features
33 import qualified Distribution.Package as Cabal (PackageIdentifier(..)
34 , Dependency(..)
35 , PackageName(..))
d52e1405 » trofi
2008-08-24 hackport-basic-simplification-phase.patch
36 import qualified Distribution.Version as Cabal (VersionRange(..), versionBranch, Version)
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
37 import qualified Distribution.License as Cabal (License(..))
d52e1405 » trofi
2008-08-24 hackport-basic-simplification-phase.patch
38 import qualified Distribution.Text as Cabal (display)
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
39 --import qualified Distribution.Compiler as Cabal (CompilerFlavor(..))
40
8022ddcf » der_eq@freenet.de
2005-09-21 Adding support for variable substitution in generated ebuilds
41 import Data.Char (toLower,isUpper)
d52e1405 » trofi
2008-08-24 hackport-basic-simplification-phase.patch
42 import Data.List (intercalate, groupBy, partition, nub, sortBy, init, last)
43 import Data.Ord (comparing)
44 import Data.Maybe (catMaybes, fromJust)
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
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,
8022ddcf » der_eq@freenet.de
2005-09-21 Adding support for variable substitution in generated ebuilds
60 my_pn :: Maybe String --If the package's name contains upper-case
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
61 }
62
63 type Package = String
d52e1405 » trofi
2008-08-24 hackport-basic-simplification-phase.patch
64 newtype Version = Version [Int] deriving (Ord, Eq)
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
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 )
3726ec19 » trofi
2008-08-23 hackport-cabal2ebuild-string-to-int-representation.patch
74 | ThisMajorOf Version Package -- =package-version*
cb4a7bb9 » kolmodin
2009-03-01 Start on translating extra-libraries into ebuild deps
75 deriving (Eq,Show)
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
76
87d875b3 » kolmodin
2008-03-15 Wall police
77 ebuildTemplate :: EBuild
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
78 ebuildTemplate = EBuild {
79 name = "foobar",
80 version = "0.1",
81 description = "",
82 homepage = "",
83 src_uri = "",
84 license = "",
85 slot = "0",
63b57b89 » der_eq@freenet.de
2007-07-28 Adapted HackPort to the new Hackage interface
86 keywords = ["~amd64","~x86"],
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
87 iuse = [],
88 depend = [],
c81b0559 » Duncan Coutts
2007-07-30 profile and haddock only make sense for lib packages
89 features = [],
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
90 licenseComments = "",
8022ddcf » der_eq@freenet.de
2005-09-21 Adding support for variable substitution in generated ebuilds
91 my_pn = Nothing
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
92 }
93
94 cabal2ebuild :: Cabal.PackageDescription -> EBuild
95 cabal2ebuild pkg = ebuildTemplate {
8022ddcf » der_eq@freenet.de
2005-09-21 Adding support for variable substitution in generated ebuilds
96 name = map toLower cabalPkgName,
d52e1405 » trofi
2008-08-24 hackport-basic-simplification-phase.patch
97 version = Cabal.display (Cabal.pkgVersion (Cabal.package pkg)),
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
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
d52e1405 » trofi
2008-08-24 hackport-basic-simplification-phase.patch
105 : (simplify_deps $
8273e68c » kolmodin
2009-02-07 Update the CLI and start using cabal-install features
106 convertDependency (Cabal.Dependency (Cabal.PackageName "Cabal")
d52e1405 » trofi
2008-08-24 hackport-basic-simplification-phase.patch
107 (Cabal.descCabalVersion pkg))
108 ++ convertDependencies (Cabal.buildDepends pkg)),
20179c4c » Duncan Coutts
2007-07-30 Set S= properly for packages with upper case names
109 my_pn = if any isUpper cabalPkgName then Just cabalPkgName else Nothing,
f5d6f88d » Duncan Coutts
2008-01-16 reorder the features list
110 features = features ebuildTemplate
4c4b6765 » kolmodin
2008-05-10 Fix subtile bug with missing features
111 ++ (if null (Cabal.executables pkg) then [] else ["bin"])
9d28e5bc » Stephan Friedrichs
2009-03-04 make sure hscolour does not get the hscolour feature
112 ++ maybe [] (const (["lib","profile","haddock"]
113 ++ if cabalPkgName == "hscolour" then [] else ["hscolour"])
114 ) (Cabal.library pkg) -- hscolour can't colour its own sources
8022ddcf » der_eq@freenet.de
2005-09-21 Adding support for variable substitution in generated ebuilds
115 } where
8273e68c » kolmodin
2009-02-07 Update the CLI and start using cabal-install features
116 cabalPkgName = Cabal.display $ Cabal.pkgName (Cabal.package pkg)
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
117
87d875b3 » kolmodin
2008-03-15 Wall police
118 defaultDepGHC :: Dependency
3726ec19 » trofi
2008-08-23 hackport-cabal2ebuild-string-to-int-representation.patch
119 defaultDepGHC = OrLaterVersionOf (Version [6,6,1]) "dev-lang/ghc"
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
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
87d875b3 » kolmodin
2008-03-15 Wall police
131 licenseComment :: Cabal.License -> String
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
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]
ace40ea5 » Duncan Coutts
2007-07-31 Cope with IntersectVersionRanges, at least partially
139 convertDependencies = concatMap convertDependency
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
140
ace40ea5 » Duncan Coutts
2007-07-31 Cope with IntersectVersionRanges, at least partially
141 convertDependency :: Cabal.Dependency -> [Dependency]
3e32a08d » trofi
2009-03-07 Some more -Wall fixes (import refinements + unused -> _unused)
142 convertDependency (Cabal.Dependency pname@(Cabal.PackageName _name) _)
8273e68c » kolmodin
2009-02-07 Update the CLI and start using cabal-install features
143 | pname `elem` coreLibs = [] -- no explicit dep on core libs
87d875b3 » kolmodin
2008-03-15 Wall police
144 convertDependency (Cabal.Dependency pname versionRange)
ace40ea5 » Duncan Coutts
2007-07-31 Cope with IntersectVersionRanges, at least partially
145 = case versionRange of
decf164c » kolmodin
2009-02-19 Bump Copyright header
146 -- versionRange && versionRange
ace40ea5 » Duncan Coutts
2007-07-31 Cope with IntersectVersionRanges, at least partially
147 (Cabal.IntersectVersionRanges v1 v2) -> [convert v1, convert v2]
decf164c » kolmodin
2009-02-19 Bump Copyright header
148 -- any other dep
ace40ea5 » Duncan Coutts
2007-07-31 Cope with IntersectVersionRanges, at least partially
149 v -> [convert v]
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
150
151 where
decf164c » kolmodin
2009-02-19 Bump Copyright header
152 -- XXX: not always true, we should look properly for deps in the overlay
153 -- to find the correct category
8273e68c » kolmodin
2009-02-07 Update the CLI and start using cabal-install features
154 ebuildName = "dev-haskell/" ++ map toLower (Cabal.display pname)
9448bb73 » kolmodin
2007-08-13 Rewritten overlayonly functionality
155
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
156 convert :: Cabal.VersionRange -> Dependency
157 convert Cabal.AnyVersion = AnyVersionOf ebuildName
d52e1405 » trofi
2008-08-24 hackport-basic-simplification-phase.patch
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
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
161 convert (Cabal.UnionVersionRanges (Cabal.ThisVersion v1) (Cabal.LaterVersion v2))
d52e1405 » trofi
2008-08-24 hackport-basic-simplification-phase.patch
162 | v1 == v2 = OrLaterVersionOf (cabalVtoHPv v1) ebuildName
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
163 convert (Cabal.UnionVersionRanges (Cabal.ThisVersion v1) (Cabal.EarlierVersion v2))
d52e1405 » trofi
2008-08-24 hackport-basic-simplification-phase.patch
164 | v1 == v2 = OrEarlierVersionOf (cabalVtoHPv v1) ebuildName
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
165 convert (Cabal.UnionVersionRanges r1 r2)
166 = DependEither (convert r1) (convert r2)
167
3726ec19 » trofi
2008-08-23 hackport-cabal2ebuild-string-to-int-representation.patch
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
8273e68c » kolmodin
2009-02-07 Update the CLI and start using cabal-install features
175 coreLibs :: [Cabal.PackageName]
176 coreLibs = map Cabal.PackageName
61f04b0b » Duncan Coutts
2008-01-14 Update list of core libs
177 ["array"
8022ddcf » der_eq@freenet.de
2005-09-21 Adding support for variable substitution in generated ebuilds
178 ,"base"
61f04b0b » Duncan Coutts
2008-01-14 Update list of core libs
179 --,"bytestring" --already has ebuild
180 ,"containers"
181 ,"directory"
182 --,"filepath" --already has ebuild
183 ,"ghc"
8022ddcf » der_eq@freenet.de
2005-09-21 Adding support for variable substitution in generated ebuilds
184 ,"haskell98"
2f85f14c » kolmodin
2008-07-08 Write comments about core packages
185 ,"hpc" --has ebuild, but only in the overlay
61f04b0b » Duncan Coutts
2008-01-14 Update list of core libs
186 ,"old-locale"
187 ,"old-time"
188 ,"packedstring"
189 ,"pretty"
190 ,"process"
191 ,"random"
2f85f14c » kolmodin
2008-07-08 Write comments about core packages
192 ,"readline" --has ebuild, but only in the overlay
61f04b0b » Duncan Coutts
2008-01-14 Update list of core libs
193 ,"rts"
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
194 ,"template-haskell"
2f85f14c » kolmodin
2008-07-08 Write comments about core packages
195 ,"unix" --has ebuild, but only in the overlay
61f04b0b » Duncan Coutts
2008-01-14 Update list of core libs
196 ]
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
197
198 showEBuild :: EBuild -> String
199 showEBuild ebuild =
decf164c » kolmodin
2009-02-19 Bump Copyright header
200 ss "# Copyright 1999-2009 Gentoo Foundation". nl.
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
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.
20179c4c » Duncan Coutts
2007-07-30 Set S= properly for packages with upper case names
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).
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
211 ss "DESCRIPTION=". quote (description ebuild). nl.
212 ss "HOMEPAGE=". quote (homepage ebuild). nl.
8022ddcf » der_eq@freenet.de
2005-09-21 Adding support for variable substitution in generated ebuilds
213 ss "SRC_URI=". quote (replaceVars (src_uri ebuild)).
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
214 (if null (src_uri ebuild) then ss "\t#Fixme: please fill in manually"
215 else id). nl.
5bcf377a » Duncan Coutts
2007-07-28 Update hackport's ebuild generation to current conventions.
216 nl.
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
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.
63b57b89 » der_eq@freenet.de
2007-07-28 Adapted HackPort to the new Hackage interface
221 ss "KEYWORDS=". quote' (sepBy " " $ keywords ebuild).nl.
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
222 ss "IUSE=". quote' (sepBy ", " $ iuse ebuild). nl.
223 nl.
224 ss "DEPEND=". quote' (sepBy "\n\t\t" $ map showDepend $ depend ebuild). nl.
20179c4c » Duncan Coutts
2007-07-30 Set S= properly for packages with upper case names
225 (case my_pn ebuild of
226 Nothing -> id
87d875b3 » kolmodin
2008-03-15 Wall police
227 Just _ -> nl. ss "S=". quote ("${WORKDIR}/${MY_P}"). nl)
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
228 $ []
8022ddcf » der_eq@freenet.de
2005-09-21 Adding support for variable substitution in generated ebuilds
229 where replaceVars = replaceCommonVars (name ebuild) (my_pn ebuild) (version ebuild)
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
230
87d875b3 » kolmodin
2008-03-15 Wall police
231 showDepend :: Dependency -> Package
232 showDepend (AnyVersionOf p) = p
3726ec19 » trofi
2008-08-23 hackport-cabal2ebuild-string-to-int-representation.patch
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
87d875b3 » kolmodin
2008-03-15 Wall police
238 showDepend (DependEither dep1 dep2) = showDepend dep1
239 ++ " || " ++ showDepend dep2
6ec3592d » Ivan.Miljenovic@gmail.com
2008-11-12 Hackport now uses Cabal-1.6
240 showDepend (DependIfUse useflag dep@(DependEither _ _))
87d875b3 » kolmodin
2008-03-15 Wall police
241 = useflag ++ "? " ++ showDepend dep
242 showDepend (DependIfUse useflag dep) = useflag ++ "? ( " ++ showDepend dep++ " )"
3726ec19 » trofi
2008-08-23 hackport-cabal2ebuild-string-to-int-representation.patch
243 showDepend (ThisMajorOf v p) = "=" ++ p ++ "-" ++ show v ++ "*"
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
244
87d875b3 » kolmodin
2008-03-15 Wall police
245 ss :: String -> String -> String
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
246 ss = showString
87d875b3 » kolmodin
2008-03-15 Wall police
247
248 sc :: Char -> String -> String
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
249 sc = showChar
87d875b3 » kolmodin
2008-03-15 Wall police
250
251 nl :: String -> String
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
252 nl = sc '\n'
253
87d875b3 » kolmodin
2008-03-15 Wall police
254 quote :: String -> String -> String
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
255 quote str = sc '"'. ss str. sc '"'
87d875b3 » kolmodin
2008-03-15 Wall police
256
257 quote' :: (String -> String) -> String -> String
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
258 quote' str = sc '"'. str. sc '"'
259
260 sepBy :: String -> [String] -> ShowS
87d875b3 » kolmodin
2008-03-15 Wall police
261 sepBy _ [] = id
262 sepBy _ [x] = ss x
aff37c25 » der_eq@freenet.de
2005-09-05 First release of HackPort, the Hackage tool for Portage
263 sepBy s (x:xs) = ss x. ss s. sepBy s xs
8022ddcf » der_eq@freenet.de
2005-09-21 Adding support for variable substitution in generated ebuilds
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
9448bb73 » kolmodin
2007-08-13 Rewritten overlayonly functionality
276 Maybe (String,String) -- ^ Just (pre,post) if string is found
8022ddcf » der_eq@freenet.de
2005-09-21 Adding support for variable substitution in generated ebuilds
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
87d875b3 » kolmodin
2008-03-15 Wall police
288 replaceMultiVars whole@((pname,cont):rest) str = case subStr cont str of
8022ddcf » der_eq@freenet.de
2005-09-21 Adding support for variable substitution in generated ebuilds
289 Nothing -> replaceMultiVars rest str
87d875b3 » kolmodin
2008-03-15 Wall police
290 Just (pre,post) -> (replaceMultiVars rest pre)++pname++(replaceMultiVars whole post)
8022ddcf » der_eq@freenet.de
2005-09-21 Adding support for variable substitution in generated ebuilds
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
d52e1405 » trofi
2008-08-24 hackport-basic-simplification-phase.patch
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
6ec3592d » Ivan.Miljenovic@gmail.com
2008-11-12 Hackport now uses Cabal-1.6
316 -- simplify_group_table p ol l e oe exact
d52e1405 » trofi
2008-08-24 hackport-basic-simplification-phase.patch
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.