Permalink
Browse files

remove renundant UseDeps

this fix is optimistic due it not check if package versions really
equal. And all code require some tuning
  • Loading branch information...
1 parent 618e828 commit c0f53608ccd4ca5bd9ee6a7a1a8c1b6db1607ca6 @qnikst qnikst committed May 5, 2012
Showing with 35 additions and 3 deletions.
  1. +6 −2 Merge/Dependencies.hs
  2. +29 −1 Portage/Dependency.hs
View
8 Merge/Dependencies.hs
@@ -98,12 +98,16 @@ resolveDependencies :: Portage.Overlay -> PackageDescription -> Maybe CompilerId
resolveDependencies overlay pkg mcompiler =
edeps
{
- dep = Portage.simplify_deps ( dep edeps),
- rdep = Portage.simplify_deps (rdep edeps)
+ dep = dep2,
+ rdep = rdep2
-- todo: if rdep includes cabal or ghc, make sure it's the same
-- version as in dep
}
where
+ dep1 = Portage.simplify_deps ( dep edeps)
+ dep2 = Portage.simplifyUseDeps dep1 (dep1++rdep2)
+ rdep1 = Portage.simplify_deps (rdep edeps)
+ rdep2 = Portage.simplifyUseDeps rdep1 rdep1
compiler = maybe (fst GHCCore.defaultGHC) id mcompiler
hasBuildableExes p = any (buildable . buildInfo) . executables $ p
View
30 Portage/Dependency.hs
@@ -1,6 +1,7 @@
module Portage.Dependency (
Dependency(..),
simplify_deps,
+ simplifyUseDeps,
addDepUseFlag
) where
@@ -13,7 +14,7 @@ import Portage.PackageId
import qualified Text.PrettyPrint as Disp
import Text.PrettyPrint ( (<>), hsep )
-import Data.Maybe ( fromJust, catMaybes )
+import Data.Maybe ( fromJust, catMaybes, mapMaybe )
import Data.List ( nub, groupBy, partition, sortBy )
import Data.Ord (comparing)
@@ -189,3 +190,30 @@ addDepUseFlag (OrEarlierVersionOf v p u) n = OrEarlierVersionOf v p (n:u)
addDepUseFlag (ThisMajorOf v p u) n = ThisMajorOf v p (n:u)
addDepUseFlag (DependEither d) n = DependEither $ map (flip addDepUseFlag n) d
addDepUseFlag (DependIfUse u d) n = DependIfUse u (addDepUseFlag d n)
+
+--
+-- | remove all Use dependencies that overlap with normal dependencies
+simplifyUseDeps :: [Dependency] -- list where use deps is taken
+ -> [Dependency] -- list where common deps is taken
+ -> [Dependency] -- result deps
+simplifyUseDeps ds cs =
+ let (u,o) = partition isUseDep ds
+ c = mapMaybe getPackage cs
+ in (mapMaybe (intersectD c) u)++o
+
+intersectD :: [PackageName] -> Dependency -> Maybe Dependency
+intersectD fs (DependIfUse u d) = intersectD fs d >>= Just . DependIfUse u
+intersectD fs (DependEither ds) =
+ let ds' = mapMaybe (intersectD fs) ds
+ in if null ds' then Nothing else Just (DependEither ds')
+intersectD fs (AllOf ds) =
+ let ds' = mapMaybe (intersectD fs) ds
+ in if null ds' then Nothing else Just (AllOf ds')
+intersectD fs x =
+ let pkg = fromJust $ getPackage x -- this is unsafe but will save from error later
+ in if any (==pkg) fs then Nothing else Just x
+
+isUseDep :: Dependency -> Bool
+isUseDep (DependIfUse _ _) = True
+isUseDep _ = False
+--

0 comments on commit c0f5360

Please sign in to comment.