Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 473 lines (410 sloc) 22.808 kB
bd75ad0 @kolmodin first stab at DEPEND / RDEPEND tracking
kolmodin authored
1 module Merge
6b6ca6b @kolmodin Fix the broken 'hackport make-ebuild'
kolmodin authored
2 ( merge
3 , mergeGenericPackageDescription
4 ) where
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
5
0478a07 @trofi get rid of Control.Monad.Error completely
trofi authored
6 import Control.Monad
8135c0c @kolmodin Implement fetching and creation of digests for new ebuilds
kolmodin authored
7 import Control.Exception
24d83da @trofi Merge.hs: use bytestring API for file I/O to avoid crashes on UTF-8 s…
trofi authored
8 import qualified Data.ByteString.Lazy.Char8 as BL
7221e5a @qnikst correct cabal-flags support
qnikst authored
9 import Data.Function (on)
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
10 import Data.Maybe
da9c3c9 @qnikst cabal flags support
qnikst authored
11 import Data.Monoid
a9969bd @trofi Merge.hs: cleanup: qualify Data.List imported entities
trofi authored
12 import qualified Data.List as L
da1f598 @trofi Merge.hs: fix wrong dependency generation for shared depends
trofi authored
13 import qualified Data.Set as S
9e0c120 @trofi Portage/EBuild.hs: stop hardcoding current year
trofi authored
14 import qualified Data.Time.Clock as TC
6ac92b8 @trofi Merge.hs: resolve package ambiguity by picking newest
trofi authored
15 import Data.Version
682ac49 @trofi Merge.hs: get rid of selfdepends in dependency resolution
trofi authored
16
17 -- cabal
18 import qualified Distribution.Package as Cabal
19 import qualified Distribution.Version as Cabal
20 import qualified Distribution.PackageDescription as Cabal ( PackageDescription(..)
5003d9e @qnikst add correct flags on ebuild merge
qnikst authored
21 , Flag(..)
b9bef21 @qnikst support for nexted flags
qnikst authored
22 , FlagAssignment
34e7842 @kolmodin Set --flags=-cocoa when finalizing a PackageDescription
kolmodin authored
23 , FlagName(..)
682ac49 @trofi Merge.hs: get rid of selfdepends in dependency resolution
trofi authored
24 , GenericPackageDescription(..)
861db07 @kolmodin Move dependency resolution to its own file
kolmodin authored
25 )
3864663 @trofi Merge.hs: added debugging output for processed .cabal file
trofi authored
26 import qualified Distribution.PackageDescription.Parse as Cabal (showPackageDescription)
27
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
28 import Distribution.Text (display)
682ac49 @trofi Merge.hs: get rid of selfdepends in dependency resolution
trofi authored
29 import Distribution.Verbosity
30 import Distribution.Simple.Utils
31
32 -- cabal-install
33 import Distribution.Client.IndexUtils ( getSourcePackages )
34 import qualified Distribution.Client.PackageIndex as Index
35 import Distribution.Client.Types
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
36
682ac49 @trofi Merge.hs: get rid of selfdepends in dependency resolution
trofi authored
37 -- others
f309365 @kolmodin Reimplement 'hackport merge'
kolmodin authored
38 import System.Directory ( getCurrentDirectory
39 , setCurrentDirectory
40 , createDirectoryIfMissing
59858eb @trofi Added 'metadata.xml' autogeneration for packages where it does not ex…
trofi authored
41 , doesFileExist
f309365 @kolmodin Reimplement 'hackport merge'
kolmodin authored
42 )
3b0f5c5 @hasufell Merge.hs: update imports, rm obsolete ones
hasufell authored
43 import System.Process (system)
deff889 @trofi Some fixes for -Wall (name colisions, redundant imports)
trofi authored
44 import System.FilePath ((</>))
607d396 @trofi merge: don't refetch tarballs from internetz everytime.
trofi authored
45 import System.Exit
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
46
bb3fb1e @kolmodin Rename imports
kolmodin authored
47 import qualified Cabal2Ebuild as C2E
ebb2f1b @kolmodin Adapt Merge.hs and Main.hs to the EBuild move
kolmodin authored
48 import qualified Portage.EBuild as E
646638a @trofi Merge.hs: cleanup: moved existing metadat extraction to 'Portage/EMet…
trofi authored
49 import qualified Portage.EMeta as EM
f309365 @kolmodin Reimplement 'hackport merge'
kolmodin authored
50 import Error as E
51
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
52 import Network.URI
53
5befb12 @trofi Merge.hs: cleanup: factor out 'partition_depends' out to 'Portage/Cab…
trofi authored
54 import qualified Portage.Cabal as Portage
f309365 @kolmodin Reimplement 'hackport merge'
kolmodin authored
55 import qualified Portage.PackageId as Portage
56 import qualified Portage.Version as Portage
59858eb @trofi Added 'metadata.xml' autogeneration for packages where it does not ex…
trofi authored
57 import qualified Portage.Metadata as Portage
f309365 @kolmodin Reimplement 'hackport merge'
kolmodin authored
58 import qualified Portage.Overlay as Overlay
033ff9b @kolmodin move package resolving functions to Portage.Resolve
kolmodin authored
59 import qualified Portage.Resolve as Portage
da9c3c9 @qnikst cabal flags support
qnikst authored
60 import qualified Portage.Dependency as Portage
ed8673f @trofi Portage/Dependency/Types.hs: DependIfUse now holds both positive and …
trofi authored
61 import qualified Portage.Use as Portage
f309365 @kolmodin Reimplement 'hackport merge'
kolmodin authored
62
4f6ec6f @kolmodin guess-ghc-version: Integrate GHC guessing into 'hackport merge'
kolmodin authored
63 import qualified Portage.GHCCore as GHCCore
64
861db07 @kolmodin Move dependency resolution to its own file
kolmodin authored
65 import qualified Merge.Dependencies as Merge
66
30c4943 @trofi Main.hs: add support for forcing certain flags in .cabal file
trofi authored
67 import qualified Util as U
68
b4bc38b @trofi WIP: optimize large deps in bunches
trofi authored
69
deff889 @trofi Some fixes for -Wall (name colisions, redundant imports)
trofi authored
70 (<.>) :: String -> String -> String
f56d508 @kolmodin Cleanup in merge
kolmodin authored
71 a <.> b = a ++ '.':b
72
22e0fbc @kolmodin Add requests for 'hackport merge'
kolmodin authored
73 {-
74 Requested features:
077e155 @trofi Merge.hs: basic code to preserve KEYWORDS in current ebuilds
trofi authored
75 * Add files to git?
22e0fbc @kolmodin Add requests for 'hackport merge'
kolmodin authored
76 * Print diff with the next latest version?
77 -}
78
f309365 @kolmodin Reimplement 'hackport merge'
kolmodin authored
79 readPackageString :: [String]
80 -> Either HackPortError ( Maybe Portage.Category
81 , Cabal.PackageName
82 , Maybe Portage.Version
83 )
84 readPackageString args = do
85 packageString <-
86 case args of
7ab62d5 @kolmodin Tried hlint, nice.
kolmodin authored
87 [] -> Left (ArgumentError "Need an argument, [category/]package[-version]")
f309365 @kolmodin Reimplement 'hackport merge'
kolmodin authored
88 [pkg] -> return pkg
89 _ -> Left (ArgumentError ("Too many arguments: " ++ unwords args))
90 case Portage.parseFriendlyPackage packageString of
91 Just v@(_,_,Nothing) -> return v
92 -- we only allow versions we can convert into cabal versions
93 Just v@(_,_,Just (Portage.Version _ Nothing [] 0)) -> return v
94 _ -> Left (ArgumentError ("Could not parse [category/]package[-version]: " ++ packageString))
95
823b6ef @kolmodin Look into portage dir when resolving extra-libraries
kolmodin authored
96
97
f309365 @kolmodin Reimplement 'hackport merge'
kolmodin authored
98 -- | Given a list of available packages, and maybe a preferred version,
99 -- return the available package with that version. Latest version is chosen
100 -- if no preference.
ac5deac @trofi port to (bundled) Cabal-1.12
trofi authored
101 resolveVersion :: [SourcePackage] -> Maybe Cabal.Version -> Maybe SourcePackage
72172c6 @trofi Merge.hs: pick package version regardless to case sensivity
trofi authored
102 resolveVersion avails Nothing = Just $ L.maximumBy (comparing (Cabal.pkgVersion . packageInfoId)) avails
f309365 @kolmodin Reimplement 'hackport merge'
kolmodin authored
103 resolveVersion avails (Just ver) = listToMaybe (filter match avails)
104 where
682ac49 @trofi Merge.hs: get rid of selfdepends in dependency resolution
trofi authored
105 match avail = ver == Cabal.pkgVersion (packageInfoId avail)
f309365 @kolmodin Reimplement 'hackport merge'
kolmodin authored
106
d472209 @trofi Main.hs: cleanup: store cabal flags as 'Maybe String' instead of 'Str…
trofi authored
107 merge :: Verbosity -> Repo -> URI -> [String] -> FilePath -> Maybe String -> IO ()
30c4943 @trofi Main.hs: add support for forcing certain flags in .cabal file
trofi authored
108 merge verbosity repo _serverURI args overlayPath users_cabal_flags = do
f309365 @kolmodin Reimplement 'hackport merge'
kolmodin authored
109 (m_category, user_pName, m_version) <-
110 case readPackageString args of
111 Left err -> throwEx err
112 Right (c,p,m_v) ->
113 case m_v of
114 Nothing -> return (c,p,Nothing)
115 Just v -> case Portage.toCabalVersion v of
116 Nothing -> throwEx (ArgumentError "illegal version")
117 Just ver -> return (c,p,Just ver)
118
119 debug verbosity $ "Category: " ++ show m_category
120 debug verbosity $ "Package: " ++ show user_pName
121 debug verbosity $ "Version: " ++ show m_version
122
123 let (Cabal.PackageName user_pname_str) = user_pName
124
125 overlay <- Overlay.loadLazy overlayPath
861db07 @kolmodin Move dependency resolution to its own file
kolmodin authored
126 -- portage_path <- Host.portage_dir `fmap` Host.getInfo
127 -- portage <- Overlay.loadLazy portage_path
ac5deac @trofi port to (bundled) Cabal-1.12
trofi authored
128 index <- fmap packageIndex $ getSourcePackages verbosity [ repo ]
f309365 @kolmodin Reimplement 'hackport merge'
kolmodin authored
129
130 -- find all packages that maches the user specified package name
131 availablePkgs <-
ac5deac @trofi port to (bundled) Cabal-1.12
trofi authored
132 case map snd (Index.searchByName index user_pname_str) of
133 [] -> throwEx (PackageNotFound user_pname_str)
134 [pkg] -> return pkg
6ac92b8 @trofi Merge.hs: resolve package ambiguity by picking newest
trofi authored
135 pkgs -> do let cabal_pkg_to_pn pkg =
136 case Cabal.pkgName (packageInfoId pkg) of
137 Cabal.PackageName pn -> pn
138 names = map (cabal_pkg_to_pn . L.head) pkgs
139 notice verbosity $ "Ambiguous names: " ++ L.intercalate ", " names
140 forM_ pkgs $ \ps ->
141 do let p_name = (cabal_pkg_to_pn . L.head) ps
142 notice verbosity $ p_name ++ ": " ++ (L.intercalate ", " $ map (showVersion . Cabal.pkgVersion . packageInfoId) ps)
143 return $ concat pkgs
f309365 @kolmodin Reimplement 'hackport merge'
kolmodin authored
144
145 -- select a single package taking into account the user specified version
146 selectedPkg <-
147 case resolveVersion availablePkgs m_version of
148 Nothing -> do
149 putStrLn "No such version for that package, available versions:"
7ab62d5 @kolmodin Tried hlint, nice.
kolmodin authored
150 forM_ availablePkgs $ \ avail ->
f309365 @kolmodin Reimplement 'hackport merge'
kolmodin authored
151 putStrLn (display . packageInfoId $ avail)
152 throwEx (ArgumentError "no such version for that package")
153 Just avail -> return avail
154
155 -- print some info
156 info verbosity "Selecting package:"
157 forM_ availablePkgs $ \ avail -> do
158 let match_text | packageInfoId avail == packageInfoId selectedPkg = "* "
159 | otherwise = "- "
160 info verbosity $ match_text ++ (display . packageInfoId $ avail)
161
162 let cabal_pkgId = packageInfoId selectedPkg
682ac49 @trofi Merge.hs: get rid of selfdepends in dependency resolution
trofi authored
163 norm_pkgName = Cabal.packageName (Portage.normalizeCabalPackageId cabal_pkgId)
2d91ca9 @kolmodin bugfix: allow the syntax "hackport merge foo/bar"
kolmodin authored
164 cat <- maybe (Portage.resolveCategory verbosity overlay norm_pkgName) return m_category
30c4943 @trofi Main.hs: add support for forcing certain flags in .cabal file
trofi authored
165 mergeGenericPackageDescription verbosity overlayPath cat (packageDescription selectedPkg) True users_cabal_flags
f309365 @kolmodin Reimplement 'hackport merge'
kolmodin authored
166
fe211c5 @trofi Merge.hs: use previously used cabal flags if not set by user
trofi authored
167 first_just_of :: [Maybe a] -> Maybe a
3ff871a @trofi Merge.hs: cleanup 'first_just_of' down to 'msum' by Matvey B. Aksenov
trofi authored
168 first_just_of = msum
fe211c5 @trofi Merge.hs: use previously used cabal flags if not set by user
trofi authored
169
d472209 @trofi Main.hs: cleanup: store cabal flags as 'Maybe String' instead of 'Str…
trofi authored
170 mergeGenericPackageDescription :: Verbosity -> FilePath -> Portage.Category -> Cabal.GenericPackageDescription -> Bool -> Maybe String -> IO ()
30c4943 @trofi Main.hs: add support for forcing certain flags in .cabal file
trofi authored
171 mergeGenericPackageDescription verbosity overlayPath cat pkgGenericDesc fetch users_cabal_flags = do
caf3f8f @trofi merge: search DEPENDS in according categories instead of hardcoding d…
trofi authored
172 overlay <- Overlay.loadLazy overlayPath
682ac49 @trofi Merge.hs: get rid of selfdepends in dependency resolution
trofi authored
173 let merged_cabal_pkg_name = Cabal.pkgName (Cabal.package (Cabal.packageDescription pkgGenericDesc))
52a92a7 @trofi Merge.hs: move existing metadata reading out before ebuild generation
trofi authored
174 merged_PN = Portage.cabal_pn_to_PN merged_cabal_pkg_name
175 pkgdir = overlayPath </> Portage.unCategory cat </> merged_PN
176 existing_meta <- EM.findExistingMeta pkgdir
fe211c5 @trofi Merge.hs: use previously used cabal flags if not set by user
trofi authored
177 let requested_cabal_flags = first_just_of [users_cabal_flags, EM.cabal_flags existing_meta]
682ac49 @trofi Merge.hs: get rid of selfdepends in dependency resolution
trofi authored
178
d1def6b @trofi Portage/GHCCore.hs: take into account user specified cabal flags when…
trofi authored
179 -- accepts things, like: "cabal_flag:iuse_name", "+cabal_flag", "-cabal_flag"
180 read_fas :: Maybe String -> (Cabal.FlagAssignment, [(String, String)])
181 read_fas Nothing = ([], [])
182 read_fas (Just user_fas_s) = (user_fas, user_renames)
183 where user_fas = [ (cf, b)
184 | ((cf, _), Just b) <- cn_in_mb
185 ]
186 user_renames = [ (cfn, ein)
187 | ((Cabal.FlagName cfn, ein), Nothing) <- cn_in_mb
188 ]
189 cn_in_mb = map read_fa $ U.split (== ',') user_fas_s
190 read_fa :: String -> ((Cabal.FlagName, String), Maybe Bool)
191 read_fa [] = error $ "read_fas: empty flag?"
192 read_fa (op:flag) =
193 case op of
194 '+' -> (get_rename flag, Just True)
195 '-' -> (get_rename flag, Just False)
196 _ -> (get_rename (op:flag), Nothing)
197 where get_rename :: String -> (Cabal.FlagName, String)
198 get_rename s =
199 case U.split (== ':') s of
200 [cabal_flag_name] -> (Cabal.FlagName cabal_flag_name, cabal_flag_name)
201 [cabal_flag_name, iuse_name] -> (Cabal.FlagName cabal_flag_name, iuse_name)
202 _ -> error $ "get_rename: too many components" ++ show (s)
203
204 (user_specified_fas, cf_to_iuse_rename) = read_fas requested_cabal_flags
205
7e8d237 @trofi Merge.hs: cleanup: follow most of hlint suggestions
trofi authored
206 debug verbosity "searching for minimal suitable ghc version"
d1def6b @trofi Portage/GHCCore.hs: take into account user specified cabal flags when…
trofi authored
207 (compilerId, ghc_packages, pkgDesc0, _flags, pix) <- case GHCCore.minimumGHCVersionToBuildPackage pkgGenericDesc user_specified_fas of
9e09e18 @trofi Merge.hs: clarify error message when hackport fails to find suitable …
trofi authored
208 Just v -> return v
df2ad44 @trofi Merge.hs: cleanup: suggest user's category name instead of 'dev-haske…
trofi authored
209 Nothing -> let pn = display merged_cabal_pkg_name
210 cn = display cat
211 in error $ unlines [ "mergeGenericPackageDescription: failed to find suitable GHC for " ++ pn
9e09e18 @trofi Merge.hs: clarify error message when hackport fails to find suitable …
trofi authored
212 , " You can try to merge the package manually:"
df2ad44 @trofi Merge.hs: cleanup: suggest user's category name instead of 'dev-haske…
trofi authored
213 , " $ cabal unpack " ++ pn
214 , " $ cd " ++ pn ++ "*/"
215 , " # fix " ++ pn ++ ".cabal"
216 , " $ hackport make-ebuild " ++ cn ++ " " ++ pn ++ ".cabal"
9e09e18 @trofi Merge.hs: clarify error message when hackport fails to find suitable …
trofi authored
217 ]
4f6ec6f @kolmodin guess-ghc-version: Integrate GHC guessing into 'hackport merge'
kolmodin authored
218
5befb12 @trofi Merge.hs: cleanup: factor out 'partition_depends' out to 'Portage/Cab…
trofi authored
219 let (accepted_deps, skipped_deps) = Portage.partition_depends ghc_packages merged_cabal_pkg_name (Cabal.buildDepends pkgDesc0)
da9c3c9 @qnikst cabal flags support
qnikst authored
220 pkgDesc = pkgDesc0 { Cabal.buildDepends = accepted_deps }
bbc7444 @trofi Merge.hs: cleanup: renamed 'lflags' to 'make_fas'
trofi authored
221 cabal_flag_descs = Cabal.genPackageFlags pkgGenericDesc
222 all_flags = map Cabal.flagName cabal_flag_descs
223 make_fas :: [Cabal.Flag] -> [Cabal.FlagAssignment]
224 make_fas [] = [[]]
30c4943 @trofi Main.hs: add support for forcing certain flags in .cabal file
trofi authored
225 make_fas (f:rest) = [ (fn, is_enabled) : fas
bbc7444 @trofi Merge.hs: cleanup: renamed 'lflags' to 'make_fas'
trofi authored
226 | fas <- make_fas rest
30c4943 @trofi Main.hs: add support for forcing certain flags in .cabal file
trofi authored
227 , let fn = Cabal.flagName f
228 users_choice = lookup fn user_specified_fas
229 , is_enabled <- maybe [False, True]
230 (\b -> [b])
231 users_choice
bbc7444 @trofi Merge.hs: cleanup: renamed 'lflags' to 'make_fas'
trofi authored
232 ]
2200c56 @trofi Merge.hs: cleanup: compute complete flag set assignment only once
trofi authored
233 all_possible_flag_assignments :: [Cabal.FlagAssignment]
bbc7444 @trofi Merge.hs: cleanup: renamed 'lflags' to 'make_fas'
trofi authored
234 all_possible_flag_assignments = make_fas cabal_flag_descs
2200c56 @trofi Merge.hs: cleanup: compute complete flag set assignment only once
trofi authored
235
e5f547f @trofi Merge.hs: added pretty-printer for flag assignment set
trofi authored
236 pp_fa :: Cabal.FlagAssignment -> String
237 pp_fa fa = L.intercalate ", " [ (if b then '+' else '-') : f
238 | (Cabal.FlagName f, b) <- fa
239 ]
240
7f054dc @trofi Merge.hs: added support for USE flag renaming into hackport
trofi authored
241
242 cfn_to_iuse :: String -> String
243 cfn_to_iuse cfn =
244 case lookup cfn cf_to_iuse_rename of
245 Nothing -> cfn
246 Just ein -> ein
30c4943 @trofi Main.hs: add support for forcing certain flags in .cabal file
trofi authored
247
7221e5a @qnikst correct cabal-flags support
qnikst authored
248 -- key idea is to generate all possible list of flags
249 deps1 :: [(Cabal.FlagAssignment, Merge.EDep)]
f489739 @trofi Merge.hs: cleanup: rename 'genDeps' to 'cabal_to_emerge_dep'
trofi authored
250 deps1 = [ (f `updateFa` fr, cabal_to_emerge_dep pkgDesc_filtered_bdeps)
2200c56 @trofi Merge.hs: cleanup: compute complete flag set assignment only once
trofi authored
251 | f <- all_possible_flag_assignments
34191c2 @trofi Merge.hs: fix breakage on undesolved depends
trofi authored
252 , Right (pkgDesc1,fr) <- [GHCCore.finalizePackageDescription f
da9c3c9 @qnikst cabal flags support
qnikst authored
253 (GHCCore.dependencySatisfiable pix)
7e8d237 @trofi Merge.hs: cleanup: follow most of hlint suggestions
trofi authored
254 GHCCore.platform
da9c3c9 @qnikst cabal flags support
qnikst authored
255 compilerId
256 []
34191c2 @trofi Merge.hs: fix breakage on undesolved depends
trofi authored
257 pkgGenericDesc]
1f06520 @trofi Merge.hs: once again drop shipped and circular depends on themselves
trofi authored
258 -- drop circular deps and shipped deps
5befb12 @trofi Merge.hs: cleanup: factor out 'partition_depends' out to 'Portage/Cab…
trofi authored
259 , let (ad, _sd) = Portage.partition_depends ghc_packages merged_cabal_pkg_name (Cabal.buildDepends pkgDesc1)
11950af @trofi Merge/Dependencies.hs: add 'ghc' to list of known build tools
trofi authored
260 -- TODO: drop ghc libraries from tests depends as well
261 -- (see deepseq in hackport-0.3.5 as an example)
1f06520 @trofi Merge.hs: once again drop shipped and circular depends on themselves
trofi authored
262 , let pkgDesc_filtered_bdeps = pkgDesc1 { Cabal.buildDepends = ad }
da9c3c9 @qnikst cabal flags support
qnikst authored
263 ]
4fa5ab6 @trofi Merge.hs: trailing whitespace
trofi authored
264 where
7221e5a @qnikst correct cabal-flags support
qnikst authored
265 updateFa :: Cabal.FlagAssignment -> Cabal.FlagAssignment -> Cabal.FlagAssignment
266 updateFa [] _ = []
267 updateFa (x:xs) y = case lookup (fst x) y of
4c3b979 @trofi Merge.hs: added comment to suspicious code block
trofi authored
268 -- TODO: when does this code get triggered?
7e8d237 @trofi Merge.hs: cleanup: follow most of hlint suggestions
trofi authored
269 Nothing -> x : updateFa xs y
270 Just y' -> (fst x,y') : updateFa xs y
7221e5a @qnikst correct cabal-flags support
qnikst authored
271 -- then remove all flags that can't be changed
f728cce @trofi Merge.hs: cleanup: shortenet 'filter (\fa -> all (fa /=) common_fas)'…
trofi authored
272 successfully_resolved_flag_assignments = map fst deps1
273 common_fa = L.foldl1' L.intersect successfully_resolved_flag_assignments
274 common_flags = map fst common_fa
35aa5e4 @trofi Merge.hs: give nicer names to "all_flags'" and "all_flags''"
trofi authored
275 active_flags = all_flags L.\\ common_flags
276 active_flag_descs = filter (\x -> Cabal.flagName x `elem` active_flags) cabal_flag_descs
57a1e42 @trofi Merge.hs: cleanup: one more 'filter (`notElem` a)' -> 'L.\\ a'
trofi authored
277 irresolvable_flag_assignments = all_possible_flag_assignments L.\\ successfully_resolved_flag_assignments
8dfb540 @trofi Merge.hs: speedup calculation of dependency-irrelevant flags
trofi authored
278 -- flags, not guarding any dependency variation, like:
279 -- if flag(foo)
280 -- ghc-options: -O2
281 (irrelevant_flags, deps1') = L.foldl' drop_irrelevant ([], deps1) active_flags
282 where drop_irrelevant :: ([Cabal.FlagName], [(Cabal.FlagAssignment, Merge.EDep)]) -> Cabal.FlagName -> ([Cabal.FlagName], [(Cabal.FlagAssignment, Merge.EDep)])
283 drop_irrelevant (ifs, ds) f =
284 case fenabled_ds' == fdisabled_ds' of
285 True -> (f:ifs, fenabled_ds')
286 False -> ( ifs, ds)
287 where (fenabled_ds', fdisabled_ds') = ( L.sort $ map drop_f fenabled_ds
288 , L.sort $ map drop_f fdisabled_ds
289 )
290 drop_f :: (Cabal.FlagAssignment, Merge.EDep) -> (Cabal.FlagAssignment, Merge.EDep)
291 drop_f (fas, d) = (filter ((f /=) . fst) fas, d)
292 (fenabled_ds, fdisabled_ds) = L.partition is_fe ds
293 is_fe :: (Cabal.FlagAssignment, Merge.EDep) -> Bool
294 is_fe (fas, _d) =
295 case lookup f fas of
296 Just v -> v
297 -- should not happen
298 Nothing -> error $ unwords [ "ERROR: drop_irrelevant: searched for missing flag"
299 , show f
300 , "in assignment"
301 , show fas
302 ]
303
0c106c2 @trofi Merge.hs: fix typo in comment
trofi authored
304 -- and finally prettify all deps:
f728cce @trofi Merge.hs: cleanup: shortenet 'filter (\fa -> all (fa /=) common_fas)'…
trofi authored
305 leave_only_dynamic_fa :: Cabal.FlagAssignment -> Cabal.FlagAssignment
5f21e05 @trofi Merge.hs: fixed bug in irrelevant flag filtering
trofi authored
306 leave_only_dynamic_fa fa = filter (\(fn, _) -> all (fn /=) irrelevant_flags) $ fa L.\\ common_fa
cce9ee2 @trofi Merge.hs: cleanup: factor out flag cleaning to 'leave_only_dynamic_fa…
trofi authored
307
39fa74b @trofi Merge.hs: build balanced dependency tree instead of skewed
trofi authored
308 -- build roughly balanced complete dependency tree instead of skewed one
309 bimerge :: [Merge.EDep] -> Merge.EDep
310 bimerge deps = case go deps of
311 [] -> mempty
312 [r] -> r
313 _ -> error "bimerge: something bad happened"
314 where go deps' =
315 case deps' of
316 (d1:d2:ds) -> go (mappend d1 d2 : go ds)
317 _ -> deps'
318
b3c980e @trofi Merge.hs: cleanup: add type declaration to local definition
trofi authored
319 tdeps :: Merge.EDep
39fa74b @trofi Merge.hs: build balanced dependency tree instead of skewed
trofi authored
320 tdeps = bimerge $ map set_fa_to_ed deps1'
b4bc38b @trofi WIP: optimize large deps in bunches
trofi authored
321
322 set_fa_to_ed :: (Cabal.FlagAssignment, Merge.EDep) -> Merge.EDep
323 set_fa_to_ed (fa, ed) = ed { Merge.rdep = liftFlags (leave_only_dynamic_fa fa) $ Merge.rdep ed
324 , Merge.dep = liftFlags (leave_only_dynamic_fa fa) $ Merge.dep ed
325 }
7221e5a @qnikst correct cabal-flags support
qnikst authored
326
2e40aed @trofi WIP: got rid of Set in merger
trofi authored
327 liftFlags :: Cabal.FlagAssignment -> Portage.Dependency -> Portage.Dependency
ed8673f @trofi Portage/Dependency/Types.hs: DependIfUse now holds both positive and …
trofi authored
328 liftFlags fs e = let k = foldr (\(y,b) x -> Portage.mkUseDependency (b, Portage.Use . cfn_to_iuse . unFlagName $ y) . x)
c84a465 @trofi Merge.hs: cleanup: removed redundant type annotation
trofi authored
329 id fs
2e40aed @trofi WIP: got rid of Set in merger
trofi authored
330 in k e
b9bef21 @qnikst support for nexted flags
qnikst authored
331
f489739 @trofi Merge.hs: cleanup: rename 'genDeps' to 'cabal_to_emerge_dep'
trofi authored
332 cabal_to_emerge_dep :: Cabal.PackageDescription -> Merge.EDep
6347841 @trofi Portage/GHCCore.hs: drop unused defaultGHC
trofi authored
333 cabal_to_emerge_dep cabal_pkg = Merge.resolveDependencies overlay cabal_pkg compilerId ghc_packages merged_cabal_pkg_name
1de8047 @kolmodin Add build-tools deps as well, using a static table
kolmodin authored
334
3864663 @trofi Merge.hs: added debugging output for processed .cabal file
trofi authored
335 debug verbosity $ "buildDepends pkgDesc0 raw: " ++ Cabal.showPackageDescription pkgDesc0
8eb94b1 @trofi Merge.hs: use the same constraints for ghc's core package when resolv…
trofi authored
336 debug verbosity $ "buildDepends pkgDesc0: " ++ show (map display (Cabal.buildDepends pkgDesc0))
337 debug verbosity $ "buildDepends pkgDesc: " ++ show (map display (Cabal.buildDepends pkgDesc))
338
a59987e @trofi Merge.hs: shortened output of accepted/rejected/dropped depends
trofi authored
339 notice verbosity $ "Accepted depends: " ++ show (map display accepted_deps)
340 notice verbosity $ "Skipped depends: " ++ show (map display skipped_deps)
57a1e42 @trofi Merge.hs: cleanup: one more 'filter (`notElem` a)' -> 'L.\\ a'
trofi authored
341 notice verbosity $ "Dead flags: " ++ show (map pp_fa irresolvable_flag_assignments)
f728cce @trofi Merge.hs: cleanup: shortenet 'filter (\fa -> all (fa /=) common_fas)'…
trofi authored
342 notice verbosity $ "Dropped flags: " ++ show (map (unFlagName.fst) common_fa)
8dfb540 @trofi Merge.hs: speedup calculation of dependency-irrelevant flags
trofi authored
343 notice verbosity $ "Active flags: " ++ show (map unFlagName active_flags)
344 notice verbosity $ "Irrelevant flags: " ++ show (map unFlagName irrelevant_flags)
7221e5a @qnikst correct cabal-flags support
qnikst authored
345 -- mapM_ print tdeps
8eb94b1 @trofi Merge.hs: use the same constraints for ghc's core package when resolv…
trofi authored
346
347 forM_ ghc_packages $
682ac49 @trofi Merge.hs: get rid of selfdepends in dependency resolution
trofi authored
348 \(Cabal.PackageName name) -> info verbosity $ "Excluded packages (comes with ghc): " ++ name
861db07 @kolmodin Move dependency resolution to its own file
kolmodin authored
349
30c4943 @trofi Main.hs: add support for forcing certain flags in .cabal file
trofi authored
350 let pp_fn (Cabal.FlagName fn, True) = fn
351 pp_fn (Cabal.FlagName fn, False) = '-':fn
5003d9e @qnikst add correct flags on ebuild merge
qnikst authored
352
2420fd6 @trofi Merge.hs: autogenerate src_configure with explicitely enabled flags
trofi authored
353 -- appends 's' to each line except the last one
354 -- handy to build multiline shell expressions
355 icalate _s [] = []
356 icalate _s [x] = [x]
357 icalate s (x:xs) = (x ++ s) : icalate s xs
358
98b3ef8 @hasufell Add games ebuilds support
hasufell authored
359 gamesFlags :: [String]
c1d00d9 @trofi Merge.hs: fix 'games' configure cal generation
trofi authored
360 gamesFlags = ["--prefix=\"${GAMES_PREFIX}\""]
98b3ef8 @hasufell Add games ebuilds support
hasufell authored
361
362 addGamesFlags :: [String] -> [String]
363 addGamesFlags xs
c1d00d9 @trofi Merge.hs: fix 'games' configure cal generation
trofi authored
364 | Portage.is_games_cat cat = xs ++ gamesFlags
365 | otherwise = xs
98b3ef8 @hasufell Add games ebuilds support
hasufell authored
366
c1d00d9 @trofi Merge.hs: fix 'games' configure cal generation
trofi authored
367 build_configure_call :: [String] -> [String]
368 build_configure_call [] = []
369 build_configure_call conf_args = icalate " \\" $
370 "haskell-cabal_src_configure" :
371 map ('\t':) conf_args
372
373 -- returns list USE-parameters to './setup configure'
30c4943 @trofi Main.hs: add support for forcing certain flags in .cabal file
trofi authored
374 selected_flags :: ([Cabal.FlagName], Cabal.FlagAssignment) -> [String]
375 selected_flags ([], []) = []
c1d00d9 @trofi Merge.hs: fix 'games' configure cal generation
trofi authored
376 selected_flags (active_fns, users_fas) = map snd (L.sortBy (compare `on` fst) flag_pairs)
30c4943 @trofi Main.hs: add support for forcing certain flags in .cabal file
trofi authored
377 where flag_pairs :: [(String, String)]
378 flag_pairs = active_pairs ++ users_pairs
c1d00d9 @trofi Merge.hs: fix 'games' configure cal generation
trofi authored
379 active_pairs = map (\fn -> (fn, "$(cabal_flag " ++ cfn_to_iuse fn ++ " " ++ fn ++ ")")) $ map unFlagName active_fns
380 users_pairs = map (\fa -> ((unFlagName . fst) fa, "--flag=" ++ pp_fn fa)) users_fas
5dad010 @qnikst add default settings to use flags
qnikst authored
381 to_iuse x = let fn = unFlagName $ Cabal.flagName x
382 p = if Cabal.flagDefault x then "+" else ""
7f054dc @trofi Merge.hs: added support for USE flag renaming into hackport
trofi authored
383 in p ++ cfn_to_iuse fn
da9c3c9 @qnikst cabal flags support
qnikst authored
384
2e40aed @trofi WIP: got rid of Set in merger
trofi authored
385 ebuild = (\e -> e { E.depend = Merge.dep tdeps} )
386 . (\e -> e { E.depend_extra = S.toList $ Merge.dep_e tdeps } )
387 . (\e -> e { E.rdepend = Merge.rdep tdeps} )
388 . (\e -> e { E.rdepend_extra = S.toList $ Merge.rdep_e tdeps } )
c1d00d9 @trofi Merge.hs: fix 'games' configure cal generation
trofi authored
389 . (\e -> e { E.src_configure = build_configure_call $ addGamesFlags $ selected_flags (active_flags, user_specified_fas) } )
35aa5e4 @trofi Merge.hs: give nicer names to "all_flags'" and "all_flags''"
trofi authored
390 . (\e -> e { E.iuse = E.iuse e ++ map to_iuse active_flag_descs })
fe211c5 @trofi Merge.hs: use previously used cabal flags if not set by user
trofi authored
391 . ( case requested_cabal_flags of
d472209 @trofi Main.hs: cleanup: store cabal flags as 'Maybe String' instead of 'Str…
trofi authored
392 Nothing -> id
393 Just ucf -> (\e -> e { E.used_options = E.used_options e ++ [("flags", ucf)] }))
1bf9719 @hasufell Add package category to EBuild data type
hasufell authored
394 $ C2E.cabal2ebuild cat pkgDesc
f309365 @kolmodin Reimplement 'hackport merge'
kolmodin authored
395
52a92a7 @trofi Merge.hs: move existing metadata reading out before ebuild generation
trofi authored
396 mergeEbuild verbosity existing_meta pkgdir ebuild
6b6ca6b @kolmodin Fix the broken 'hackport make-ebuild'
kolmodin authored
397 when fetch $ do
682ac49 @trofi Merge.hs: get rid of selfdepends in dependency resolution
trofi authored
398 let cabal_pkgId = Cabal.packageId pkgDesc
399 norm_pkgName = Cabal.packageName (Portage.normalizeCabalPackageId cabal_pkgId)
a0a04f2 @trofi Merge.hs: run 'repoman full --include-dev' right after a merge
trofi authored
400 fetchDigestAndCheck
6b6ca6b @kolmodin Fix the broken 'hackport make-ebuild'
kolmodin authored
401 verbosity
402 (overlayPath </> display cat </> display norm_pkgName)
8135c0c @kolmodin Implement fetching and creation of digests for new ebuilds
kolmodin authored
403
a0a04f2 @trofi Merge.hs: run 'repoman full --include-dev' right after a merge
trofi authored
404 fetchDigestAndCheck :: Verbosity
405 -> FilePath -- ^ directory of ebuild
406 -> IO ()
407 fetchDigestAndCheck verbosity ebuildDir =
8135c0c @kolmodin Implement fetching and creation of digests for new ebuilds
kolmodin authored
408 withWorkingDirectory ebuildDir $ do
607d396 @trofi merge: don't refetch tarballs from internetz everytime.
trofi authored
409 notice verbosity "Recalculating digests (repoman manifest)..."
a0a04f2 @trofi Merge.hs: run 'repoman full --include-dev' right after a merge
trofi authored
410 rm <- system "repoman manifest"
411 when (rm /= ExitSuccess) $
607d396 @trofi merge: don't refetch tarballs from internetz everytime.
trofi authored
412 notice verbosity "repoman manifest failed horribly. Do something about it!"
a0a04f2 @trofi Merge.hs: run 'repoman full --include-dev' right after a merge
trofi authored
413 rf <- system "repoman full --include-dev"
414 when (rf /= ExitSuccess) $
415 notice verbosity "repoman full --include-dev found an error. Do something about it!"
4b2a1d2 @kolmodin Upgrade bundled cabal-install from 0.8.0 to 0.8.2
kolmodin authored
416 return ()
8135c0c @kolmodin Implement fetching and creation of digests for new ebuilds
kolmodin authored
417
418 withWorkingDirectory :: FilePath -> IO a -> IO a
419 withWorkingDirectory newDir action = do
420 oldDir <- getCurrentDirectory
421 bracket
422 (setCurrentDirectory newDir)
423 (\_ -> setCurrentDirectory oldDir)
424 (\_ -> action)
f309365 @kolmodin Reimplement 'hackport merge'
kolmodin authored
425
400f832 @trofi Merge.hs: on merge drop keywords down to unstable (~)
trofi authored
426 -- "amd64" -> "~amd64"
427 to_unstable :: String -> String
428 to_unstable kw =
429 case kw of
430 '~':_ -> kw
431 '-':_ -> kw
432 _ -> '~':kw
433
52a92a7 @trofi Merge.hs: move existing metadata reading out before ebuild generation
trofi authored
434 mergeEbuild :: Verbosity -> EM.EMeta -> FilePath -> E.EBuild -> IO ()
435 mergeEbuild verbosity existing_meta pkgdir ebuild = do
436 let edir = pkgdir
ebb2f1b @kolmodin Adapt Merge.hs and Main.hs to the EBuild move
kolmodin authored
437 elocal = E.name ebuild ++"-"++ E.version ebuild <.> "ebuild"
f309365 @kolmodin Reimplement 'hackport merge'
kolmodin authored
438 epath = edir </> elocal
59858eb @trofi Added 'metadata.xml' autogeneration for packages where it does not ex…
trofi authored
439 emeta = "metadata.xml"
440 mpath = edir </> emeta
24d83da @trofi Merge.hs: use bytestring API for file I/O to avoid crashes on UTF-8 s…
trofi authored
441 default_meta = BL.pack $ Portage.makeDefaultMetadata (E.long_desc ebuild)
f309365 @kolmodin Reimplement 'hackport merge'
kolmodin authored
442 createDirectoryIfMissing True edir
9e0c120 @trofi Portage/EBuild.hs: stop hardcoding current year
trofi authored
443 now <- TC.getCurrentTime
56ac9b6 @trofi Merge.hs: recover LICENSE from existing ebuilds if we have failed to …
trofi authored
444
646638a @trofi Merge.hs: cleanup: moved existing metadat extraction to 'Portage/EMet…
trofi authored
445 let (existing_keywords, existing_license) = (EM.keywords existing_meta, EM.license existing_meta)
56ac9b6 @trofi Merge.hs: recover LICENSE from existing ebuilds if we have failed to …
trofi authored
446 new_keywords = maybe (E.keywords ebuild) (map to_unstable) existing_keywords
447 new_license = either (\err -> maybe (Left err)
448 Right
449 existing_license)
450 Right
451 (E.license ebuild)
452 ebuild' = ebuild { E.keywords = new_keywords
453 , E.license = new_license
454 }
9e0c120 @trofi Portage/EBuild.hs: stop hardcoding current year
trofi authored
455 s_ebuild' = E.showEBuild now ebuild'
400f832 @trofi Merge.hs: on merge drop keywords down to unstable (~)
trofi authored
456
457 notice verbosity $ "Current keywords: " ++ show existing_keywords ++ " -> " ++ show new_keywords
56ac9b6 @trofi Merge.hs: recover LICENSE from existing ebuilds if we have failed to …
trofi authored
458 notice verbosity $ "Current license: " ++ show existing_license ++ " -> " ++ show new_license
400f832 @trofi Merge.hs: on merge drop keywords down to unstable (~)
trofi authored
459
59858eb @trofi Added 'metadata.xml' autogeneration for packages where it does not ex…
trofi authored
460 notice verbosity $ "Writing " ++ elocal
7e8d237 @trofi Merge.hs: cleanup: follow most of hlint suggestions
trofi authored
461 length s_ebuild' `seq` BL.writeFile epath (BL.pack s_ebuild')
59858eb @trofi Added 'metadata.xml' autogeneration for packages where it does not ex…
trofi authored
462
463 yet_meta <- doesFileExist mpath
7e8d237 @trofi Merge.hs: cleanup: follow most of hlint suggestions
trofi authored
464 if not yet_meta -- TODO: add --force-meta-rewrite to opts
59858eb @trofi Added 'metadata.xml' autogeneration for packages where it does not ex…
trofi authored
465 then do notice verbosity $ "Writing " ++ emeta
24d83da @trofi Merge.hs: use bytestring API for file I/O to avoid crashes on UTF-8 s…
trofi authored
466 BL.writeFile mpath default_meta
467 else do current_meta <- BL.readFile mpath
59858eb @trofi Added 'metadata.xml' autogeneration for packages where it does not ex…
trofi authored
468 when (current_meta /= default_meta) $
469 notice verbosity $ "Default and current " ++ emeta ++ " differ."
da9c3c9 @qnikst cabal flags support
qnikst authored
470
471 unFlagName :: Cabal.FlagName -> String
f37822c @trofi Merge.hs: cleanup: clean 'unFlagName' definition
trofi authored
472 unFlagName (Cabal.FlagName fname) = fname
Something went wrong with that request. Please try again.