Skip to content

Commit

Permalink
remove renundant UseDeps
Browse files Browse the repository at this point in the history
this fix is optimistic due it not check if package versions really
equal. And all code require some tuning
  • Loading branch information
qnikst committed May 5, 2012
1 parent 618e828 commit c0f5360
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
8 changes: 6 additions & 2 deletions Merge/Dependencies.hs
Expand Up @@ -98,12 +98,16 @@ resolveDependencies :: Portage.Overlay -> PackageDescription -> Maybe CompilerId
resolveDependencies overlay pkg mcompiler = resolveDependencies overlay pkg mcompiler =
edeps edeps
{ {
dep = Portage.simplify_deps ( dep edeps), dep = dep2,
rdep = Portage.simplify_deps (rdep edeps) rdep = rdep2
-- todo: if rdep includes cabal or ghc, make sure it's the same -- todo: if rdep includes cabal or ghc, make sure it's the same
-- version as in dep -- version as in dep
} }
where 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 compiler = maybe (fst GHCCore.defaultGHC) id mcompiler


hasBuildableExes p = any (buildable . buildInfo) . executables $ p hasBuildableExes p = any (buildable . buildInfo) . executables $ p
Expand Down
30 changes: 29 additions & 1 deletion Portage/Dependency.hs
@@ -1,6 +1,7 @@
module Portage.Dependency ( module Portage.Dependency (
Dependency(..), Dependency(..),
simplify_deps, simplify_deps,
simplifyUseDeps,
addDepUseFlag addDepUseFlag
) where ) where


Expand All @@ -13,7 +14,7 @@ import Portage.PackageId
import qualified Text.PrettyPrint as Disp import qualified Text.PrettyPrint as Disp
import Text.PrettyPrint ( (<>), hsep ) import Text.PrettyPrint ( (<>), hsep )


import Data.Maybe ( fromJust, catMaybes ) import Data.Maybe ( fromJust, catMaybes, mapMaybe )
import Data.List ( nub, groupBy, partition, sortBy ) import Data.List ( nub, groupBy, partition, sortBy )
import Data.Ord (comparing) import Data.Ord (comparing)


Expand Down Expand Up @@ -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 (ThisMajorOf v p u) n = ThisMajorOf v p (n:u)
addDepUseFlag (DependEither d) n = DependEither $ map (flip addDepUseFlag n) d addDepUseFlag (DependEither d) n = DependEither $ map (flip addDepUseFlag n) d
addDepUseFlag (DependIfUse u d) n = DependIfUse u (addDepUseFlag d n) 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.