Skip to content

Commit

Permalink
Portage/Dependency/Normalize.hs: add pop_common into combine_use_guards
Browse files Browse the repository at this point in the history
It restores ability to simplify
    a?  ( b? ( d ) )
    !a? ( b? ( d ) )
down to
    b? ( d )

which makes lens ebuild generation better, than original .cabal file.

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
  • Loading branch information
Sergei Trofimovich committed Apr 4, 2014
1 parent c890857 commit 0a8268f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
32 changes: 16 additions & 16 deletions Portage/Dependency/Normalize.hs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ find_atom_concatenations = id
combine_use_guards :: Dependency -> Dependency
combine_use_guards d =
case d of
DependIfUse use td fd -> DependIfUse use (go td) (go fd)
DependIfUse use td fd -> pop_common $ DependIfUse use (go td) (go fd)
DependAllOf deps -> DependAllOf $ map go $ find_use_intersections deps
DependAnyOf deps -> DependAnyOf $ map go $ find_use_concatenations deps
Atom _pn _dr _dattr -> d
Expand All @@ -154,21 +154,21 @@ find_use_intersections = map merge_use_intersections . L.groupBy is_use_mergeabl
tfdeps ~(DependIfUse _u td fd) = (td, fd)
(tds, fds) = unzip $ map tfdeps ds

pop_common :: Dependency -> Dependency
-- depend
-- a? ( x ) !a? ( x )
-- gets translated to
-- x
pop_common (DependIfUse _u td fd)
| td == fd = fd
pop_common d'@(DependIfUse _u td fd) =
case td_ctx `L.intersect` fd_ctx of
[] -> d'
-- TODO: force simplification right there
common_ctx -> DependAllOf $ propagate_context' common_ctx d' : common_ctx
where td_ctx = lift_context' td
fd_ctx = lift_context' fd
pop_common x = x
pop_common :: Dependency -> Dependency
-- depend
-- a? ( x ) !a? ( x )
-- gets translated to
-- x
pop_common (DependIfUse _u td fd)
| td == fd = fd
pop_common d'@(DependIfUse _u td fd) =
case td_ctx `L.intersect` fd_ctx of
[] -> d'
-- TODO: force simplification right there
common_ctx -> DependAllOf $ propagate_context' common_ctx d' : common_ctx
where td_ctx = lift_context' td
fd_ctx = lift_context' fd
pop_common x = x

-- TODO
find_use_concatenations :: [Dependency] -> [Dependency]
Expand Down
9 changes: 9 additions & 0 deletions tests/normalize_deps.hs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ test_normalize_in_use_and_top = TestCase $ do
, "c? ( c/z )"
]
)
, -- pop simple common subdepend
-- a? ( b? ( d ) )
-- !a? ( b? ( d ) )
( d_all [ d_use "a" $ d_use "b" $ d_p "d"
, d_use "a" $ d_nuse "b" $ d_p "d"
]
, [ "b? ( c/d )"
]
)
]
forM_ deps $ \(d, expected) ->
let actual = P.dep2str 0 $ PN.normalize_depend d
Expand Down

0 comments on commit 0a8268f

Please sign in to comment.