Skip to content
Browse files

Add support of [profile?] autogenerated depends by qnikst

Merge branch 'build-with-use' from 'git://github.com/qnikst/hackport'

* branch 'build-with-use':
  removing trailing spaces
  Do not add profile? flag for binary only pkgs
  UseFlag handling
  Portage/Uses diplay for use list added
  Basic Use types support

Conflicts:
	Merge/Dependencies.hs
	Portage/Dependency.hs

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
  • Loading branch information...
2 parents d058ee8 + 85a0008 commit 620218baed7e817867e6388fb17ecfa900359002 @trofi trofi committed
Showing with 160 additions and 79 deletions.
  1. +8 −8 Cabal2Ebuild.hs
  2. +28 −24 Merge/Dependencies.hs
  3. +74 −47 Portage/Dependency.hs
  4. +50 −0 Portage/Use.hs
View
16 Cabal2Ebuild.hs
@@ -37,6 +37,7 @@ import Distribution.Text (display)
import Data.Char (toLower,isUpper)
import Portage.Dependency
+import Portage.Use
import qualified Portage.PackageId as Portage
import qualified Portage.EBuild as Portage
import qualified Portage.Resolve as Portage
@@ -82,13 +83,13 @@ convertDependency overlay category (Cabal.Dependency pname versionRange)
Nothing -> Portage.PackageName category (Portage.normalizeCabalPackageName pname)
convert :: Cabal.VersionRange -> [Dependency]
convert = Cabal.foldVersionRange'
- ( [AnyVersionOf pn] -- ^ @\"-any\"@ version
- )(\v -> [ThisVersionOf (fromCabalVersion v) pn] -- ^ @\"== v\"@
- )(\v -> [LaterVersionOf (fromCabalVersion v) pn] -- ^ @\"> v\"@
- )(\v -> [EarlierVersionOf (fromCabalVersion v) pn] -- ^ @\"< v\"@
- )(\v -> [OrLaterVersionOf (fromCabalVersion v) pn] -- ^ @\">= v\"@
- )(\v -> [OrEarlierVersionOf (fromCabalVersion v) pn] -- ^ @\"<= v\"@
- )(\v _ -> [ThisMajorOf (fromCabalVersion v) pn] -- ^ @\"== v.*\"@ wildcard. (incl lower, excl upper)
+ ( [AnyVersionOf pn []] -- ^ @\"-any\"@ version
+ )(\v -> [ThisVersionOf (fromCabalVersion v) pn []] -- ^ @\"== v\"@
+ )(\v -> [LaterVersionOf (fromCabalVersion v) pn []] -- ^ @\"> v\"@
+ )(\v -> [EarlierVersionOf (fromCabalVersion v) pn []] -- ^ @\"< v\"@
+ )(\v -> [OrLaterVersionOf (fromCabalVersion v) pn []] -- ^ @\">= v\"@
+ )(\v -> [OrEarlierVersionOf (fromCabalVersion v) pn []] -- ^ @\"<= v\"@
+ )(\v _ -> [ThisMajorOf (fromCabalVersion v) pn []] -- ^ @\"== v.*\"@ wildcard. (incl lower, excl upper)
)(\g1 g2 -> [DependEither (flatten g1 ++ flatten g2) ] -- ^ @\"_ || _\"@ union
)(\r1 r2 -> r1 ++ r2 -- ^ @\"_ && _\"@ intersection
)(\dp -> [AllOf dp ] -- ^ @\"(_)\"@ parentheses
@@ -98,7 +99,6 @@ convertDependency overlay category (Cabal.Dependency pname versionRange)
flatten [DependEither ds] = concatMap flatten ds
flatten other = [other]
-
coreLibs :: [Cabal.PackageName]
coreLibs = map Cabal.PackageName
["array"
View
52 Merge/Dependencies.hs
@@ -63,10 +63,11 @@ import qualified Distribution.Package as Cabal
import qualified Distribution.Version as Cabal
import Distribution.Compiler
-import qualified Portage.Version as Portage
-import qualified Portage.PackageId as Portage
import qualified Portage.Dependency as Portage
import qualified Portage.Overlay as Portage
+import qualified Portage.PackageId as Portage
+import qualified Portage.Use as Portage
+import qualified Portage.Version as Portage
import qualified Cabal2Ebuild as C2E
import qualified Portage.GHCCore as GHCCore
@@ -105,7 +106,9 @@ resolveDependencies overlay pkg mcompiler =
hasBuildableExes p = any (buildable . buildInfo) . executables $ p
treatAsLibrary = (not . hasBuildableExes) pkg || hasLibs pkg
- haskell_deps = haskellDependencies overlay pkg
+ haskell_deps
+ | treatAsLibrary = add_profile $ haskellDependencies overlay pkg
+ | otherwise = haskellDependencies overlay pkg
cabal_dep = cabalDependency overlay pkg compiler
ghc_dep = compilerIdToDependency compiler
extra_libs = findCLibs pkg
@@ -131,6 +134,7 @@ resolveDependencies overlay pkg mcompiler =
dep_e = [ "${RDEPEND}" ],
rdep = extra_libs ++ pkg_config
}
+ add_profile = map (flip Portage.addDepUseFlag (Portage.mkQUse "profile"))
---------------------------------------------------------------
@@ -139,8 +143,8 @@ resolveDependencies overlay pkg mcompiler =
haskellDependencies :: Portage.Overlay -> PackageDescription -> [Portage.Dependency]
haskellDependencies overlay pkg =
- Portage.simplify_deps
- $ C2E.convertDependencies overlay (Portage.Category "dev-haskell") (buildDepends pkg)
+ Portage.simplify_deps
+ $ C2E.convertDependencies overlay (Portage.Category "dev-haskell") (buildDepends pkg)
---------------------------------------------------------------
-- Cabal Dependency
@@ -173,7 +177,7 @@ cabalDependency overlay pkg (CompilerId GHC ghcVersion@(Cabal.Version versionNum
compilerIdToDependency :: CompilerId -> Portage.Dependency
compilerIdToDependency (CompilerId GHC versionNumbers) =
- Portage.OrLaterVersionOf (Portage.fromCabalVersion versionNumbers) (Portage.mkPackageName "dev-lang" "ghc")
+ Portage.OrLaterVersionOf (Portage.fromCabalVersion versionNumbers) (Portage.mkPackageName "dev-lang" "ghc") []
---------------------------------------------------------------
-- C Libraries
@@ -182,7 +186,7 @@ compilerIdToDependency (CompilerId GHC versionNumbers) =
findCLibs :: PackageDescription -> [Portage.Dependency]
findCLibs (PackageDescription { library = lib, executables = exes }) =
[ trace ("WARNING: This package depends on a C library we don't know the portage name for: " ++ p ++ ". Check the generated ebuild.")
- (Portage.AnyVersionOf (Portage.mkPackageName "unknown-c-lib" p))
+ (Portage.AnyVersionOf (Portage.mkPackageName "unknown-c-lib" p) [])
| p <- notFound
] ++
found
@@ -197,15 +201,15 @@ findCLibs (PackageDescription { library = lib, executables = exes }) =
staticTranslateExtraLib :: String -> Maybe Portage.Dependency
staticTranslateExtraLib lib = lookup lib m
where
- m = [ ("z", Portage.AnyVersionOf (Portage.mkPackageName "sys-libs" "zlib"))
- , ("bz2", Portage.AnyVersionOf (Portage.mkPackageName "sys-libs" "bzlib"))
- , ("mysqlclient", Portage.LaterVersionOf (Portage.Version [4,0] Nothing [] 0) (Portage.mkPackageName "virtual" "mysql"))
- , ("pq", Portage.LaterVersionOf (Portage.Version [7] Nothing [] 0) (Portage.mkPackageName "virtual" "postgresql-base"))
- , ("ev", Portage.AnyVersionOf (Portage.mkPackageName "dev-libs" "libev"))
- , ("expat", Portage.AnyVersionOf (Portage.mkPackageName "dev-libs" "expat"))
- , ("curl", Portage.AnyVersionOf (Portage.mkPackageName "net-misc" "curl"))
- , ("xml2", Portage.AnyVersionOf (Portage.mkPackageName "dev-libs" "libxml2"))
- , ("mecab", Portage.AnyVersionOf (Portage.mkPackageName "app-text" "mecab"))
+ m = [ ("z", Portage.AnyVersionOf (Portage.mkPackageName "sys-libs" "zlib") [])
+ , ("bz2", Portage.AnyVersionOf (Portage.mkPackageName "sys-libs" "bzlib") [])
+ , ("mysqlclient", Portage.LaterVersionOf (Portage.Version [4,0] Nothing [] 0) (Portage.mkPackageName "virtual" "mysql") [])
+ , ("pq", Portage.LaterVersionOf (Portage.Version [7] Nothing [] 0) (Portage.mkPackageName "virtual" "postgresql-base") [])
+ , ("ev", Portage.AnyVersionOf (Portage.mkPackageName "dev-libs" "libev") [])
+ , ("expat", Portage.AnyVersionOf (Portage.mkPackageName "dev-libs" "expat") [])
+ , ("curl", Portage.AnyVersionOf (Portage.mkPackageName "net-misc" "curl") [])
+ , ("xml2", Portage.AnyVersionOf (Portage.mkPackageName "dev-libs" "libxml2") [])
+ , ("mecab", Portage.AnyVersionOf (Portage.mkPackageName "app-text" "mecab") [])
]
---------------------------------------------------------------
@@ -217,7 +221,7 @@ buildToolsDependencies (PackageDescription { library = lib, executables = exes }
[ case pkg of
Just p -> p
Nothing -> trace ("WARNING: Unknown build tool '" ++ pn ++ "'. Check the generated ebuild.")
- (Portage.AnyVersionOf (Portage.mkPackageName "unknown-build-tool" pn))
+ (Portage.AnyVersionOf (Portage.mkPackageName "unknown-build-tool" pn) [])
| Cabal.Dependency (Cabal.PackageName pn) _range <- cabalDeps
, pkg <- return (lookup pn buildToolsTable)
]
@@ -229,12 +233,12 @@ buildToolsDependencies (PackageDescription { library = lib, executables = exes }
buildToolsTable :: [(String, Portage.Dependency)]
buildToolsTable =
- [ ("happy", Portage.AnyVersionOf (Portage.mkPackageName "dev-haskell" "happy"))
- , ("alex", Portage.AnyVersionOf (Portage.mkPackageName "dev-haskell" "alex"))
- , ("c2hs", Portage.AnyVersionOf (Portage.mkPackageName "dev-haskell" "c2hs"))
- , ("gtk2hsTypeGen", Portage.AnyVersionOf (Portage.mkPackageName "dev-haskell" "gtk2hs-buildtools"))
- , ("gtk2hsHookGenerator", Portage.AnyVersionOf (Portage.mkPackageName "dev-haskell" "gtk2hs-buildtools"))
- , ("gtk2hsC2hs", Portage.AnyVersionOf (Portage.mkPackageName "dev-haskell" "gtk2hs-buildtools"))
+ [ ("happy", Portage.AnyVersionOf (Portage.mkPackageName "dev-haskell" "happy") [])
+ , ("alex", Portage.AnyVersionOf (Portage.mkPackageName "dev-haskell" "alex") [])
+ , ("c2hs", Portage.AnyVersionOf (Portage.mkPackageName "dev-haskell" "c2hs") [])
+ , ("gtk2hsTypeGen", Portage.AnyVersionOf (Portage.mkPackageName "dev-haskell" "gtk2hs-buildtools") [])
+ , ("gtk2hsHookGenerator", Portage.AnyVersionOf (Portage.mkPackageName "dev-haskell" "gtk2hs-buildtools") [])
+ , ("gtk2hsC2hs", Portage.AnyVersionOf (Portage.mkPackageName "dev-haskell" "gtk2hs-buildtools") [])
]
-- tools that are provided by ghc or some other existing program
@@ -259,7 +263,7 @@ resolvePkgConfigs overlay cdeps =
[ case resolvePkgConfig overlay pkg of
Just d -> d
Nothing -> trace ("WARNING: Could not resolve pkg-config: " ++ pn ++ ". Check generated ebuild.")
- (Portage.AnyVersionOf (Portage.mkPackageName "unknown-pkg-config" pn))
+ (Portage.AnyVersionOf (Portage.mkPackageName "unknown-pkg-config" pn) [])
| pkg@(Cabal.Dependency (Cabal.PackageName pn) _range) <- cdeps ]
resolvePkgConfig :: Portage.Overlay -> Cabal.Dependency -> Maybe Portage.Dependency
View
121 Portage/Dependency.hs
@@ -1,9 +1,11 @@
module Portage.Dependency (
Dependency(..),
- simplify_deps
+ simplify_deps,
+ addDepUseFlag
) where
import Portage.Version
+import Portage.Use
import Distribution.Text ( display, Text(..) )
import Portage.PackageId
@@ -15,17 +17,15 @@ import Data.Maybe ( fromJust, catMaybes )
import Data.List ( nub, groupBy, partition, sortBy )
import Data.Ord (comparing)
-type UseFlag = String
-
-data Dependency = AnyVersionOf PackageName
- | ThisVersionOf Version PackageName -- ~package-version
- | LaterVersionOf Version PackageName -- >package-version
- | EarlierVersionOf Version PackageName -- <package-version
- | OrLaterVersionOf Version PackageName -- >=package-version
- | OrEarlierVersionOf Version PackageName -- <=package-version
- | DependEither [[Dependency]] -- || ( depend_group1 ..depend_groupN )
+data Dependency = AnyVersionOf PackageName [UseFlag]
+ | ThisVersionOf Version PackageName [UseFlag] -- ~package-version
+ | LaterVersionOf Version PackageName [UseFlag] -- >package-version
+ | EarlierVersionOf Version PackageName [UseFlag] -- <package-version
+ | OrLaterVersionOf Version PackageName [UseFlag] -- >=package-version
+ | OrEarlierVersionOf Version PackageName [UseFlag] -- <=package-version
+ | DependEither [[Dependency]] -- || ( depend_group1 ..depend_groupN )
| DependIfUse UseFlag Dependency -- use? ( depend )
- | ThisMajorOf Version PackageName -- =package-version*
+ | ThisMajorOf Version PackageName [UseFlag] -- =package-version*
| AllOf [Dependency] -- ( package-version* )
deriving (Eq,Show)
@@ -36,26 +36,27 @@ instance Text Dependency where
a <-> b = a <> Disp.char '-' <> b
showDepend :: Dependency -> Disp.Doc
-showDepend (AnyVersionOf p) = disp p
-showDepend (ThisVersionOf v p) = Disp.char '~' <> disp p <-> disp v { versionRevision = 0 }
-showDepend (LaterVersionOf v p) = Disp.char '>' <> disp p <-> disp v
-showDepend (EarlierVersionOf v p) = Disp.char '<' <> disp p <-> disp v
-showDepend (OrLaterVersionOf v p) = Disp.text ">=" <> disp p <-> disp v
-showDepend (OrEarlierVersionOf v p) = Disp.text "<=" <> disp p <-> disp v
+showDepend (AnyVersionOf p u) = disp p <> dispUses u
+showDepend (ThisVersionOf v p u) = Disp.char '~' <> disp p <-> disp v { versionRevision = 0 }<>dispUses u
+showDepend (LaterVersionOf v p u) = Disp.char '>' <> disp p <-> disp v <> dispUses u
+showDepend (EarlierVersionOf v p u) = Disp.char '<' <> disp p <-> disp v <> dispUses u
+showDepend (OrLaterVersionOf v p u) = Disp.text ">=" <> disp p <-> disp v <> dispUses u
+showDepend (OrEarlierVersionOf v p u) = Disp.text "<=" <> disp p <-> disp v <> dispUses u
showDepend (DependEither dep_groups0)
= Disp.text "|| " <> spaceParens dep_groups
where dep_groups = map (spaceParens . map disp) dep_groups0
spaceParens ds = Disp.parens (Disp.space <> Disp.hsep ds <> Disp.space)
showDepend (DependIfUse useflag dep@(DependEither _))
- = Disp.text useflag <> Disp.text "? " <> disp dep
+ = disp useflag <> Disp.text "? " <> disp dep
showDepend (DependIfUse useflag dep)
- = Disp.text useflag <> Disp.text "? " <> Disp.parens (disp dep)
-showDepend (ThisMajorOf v p) = Disp.char '=' <> disp p <-> disp v <> Disp.char '*'
+ = disp useflag <> Disp.text "? " <> Disp.parens (disp dep)
+showDepend (ThisMajorOf v p u) = Disp.char '=' <> disp p <-> disp v <> Disp.char '*' <> dispUses u
showDepend (AllOf dp ) = Disp.text "( " <> hsep (map showDepend dp) <> Disp.text " )"
{- Here goes code for dependencies simplification -}
simplify_group_table :: PackageName ->
+ [UseFlag] ->
Maybe Version ->
Maybe Version ->
Maybe Version ->
@@ -64,26 +65,26 @@ simplify_group_table :: PackageName ->
-- simplify_group_table p ol l e oe exact
-- 1) trivial cases:
-simplify_group_table p Nothing Nothing Nothing Nothing Nothing = error $ display p ++ ": unsolvable constraints"
-simplify_group_table p (Just v) Nothing Nothing Nothing Nothing = [OrLaterVersionOf v p]
-simplify_group_table p Nothing (Just v) Nothing Nothing Nothing = [LaterVersionOf v p]
-simplify_group_table p Nothing Nothing (Just v) Nothing Nothing = [EarlierVersionOf v p]
-simplify_group_table p Nothing Nothing Nothing (Just v) Nothing = [OrEarlierVersionOf v p]
-simplify_group_table p Nothing Nothing Nothing Nothing (Just v) = [ThisVersionOf v p]
+simplify_group_table p u Nothing Nothing Nothing Nothing Nothing = error $ display p ++ ": unsolvable constraints"
+simplify_group_table p u (Just v) Nothing Nothing Nothing Nothing = [OrLaterVersionOf v p u]
+simplify_group_table p u Nothing (Just v) Nothing Nothing Nothing = [LaterVersionOf v p u]
+simplify_group_table p u Nothing Nothing (Just v) Nothing Nothing = [EarlierVersionOf v p u]
+simplify_group_table p u Nothing Nothing Nothing (Just v) Nothing = [OrEarlierVersionOf v p u]
+simplify_group_table p u Nothing Nothing Nothing Nothing (Just v) = [ThisVersionOf v p u]
-- 2) simplification passes
-simplify_group_table p (Just (Version v1 _ _ _)) Nothing (Just (Version v2 _ _ _)) Nothing Nothing
+simplify_group_table p u (Just (Version v1 _ _ _)) Nothing (Just (Version v2 _ _ _)) Nothing Nothing
-- special case: >=a-v.N a<v.(N+1) => =a-v.N*
- | (init v1 == init v2) && (last v2 == last v1 + 1) = [ThisMajorOf (Version v1 Nothing [] 0) p]
- | otherwise = [OrLaterVersionOf (Version v1 Nothing [] 0) p, EarlierVersionOf (Version v2 Nothing [] 0) p]
+ | (init v1 == init v2) && (last v2 == last v1 + 1) = [ThisMajorOf (Version v1 Nothing [] 0) p u]
+ | otherwise = [OrLaterVersionOf (Version v1 Nothing [] 0) p u, EarlierVersionOf (Version v2 Nothing [] 0) p u]
-- TODO: simplify constraints of type: >=a-v1; > a-v2 and such
-- 3) otherwise sink:
-simplify_group_table p (Just v) l@(_) e@(_) oe@(_) exact@(_) = OrLaterVersionOf v p : simplify_group_table p Nothing l e oe exact
-simplify_group_table p ol@(Nothing) (Just v) e@(_) oe@(_) exact@(_) = LaterVersionOf v p : simplify_group_table p ol Nothing e oe exact
-simplify_group_table p ol@(Nothing) l@(Nothing) (Just v) oe@(_) exact@(_) = EarlierVersionOf v p : simplify_group_table p ol l Nothing oe exact
-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
+simplify_group_table p u (Just v) l@(_) e@(_) oe@(_) exact@(_) = OrLaterVersionOf v p u: simplify_group_table p u Nothing l e oe exact
+simplify_group_table p u ol@(Nothing) (Just v) e@(_) oe@(_) exact@(_) = LaterVersionOf v p u: simplify_group_table p u ol Nothing e oe exact
+simplify_group_table p u ol@(Nothing) l@(Nothing) (Just v) oe@(_) exact@(_) = EarlierVersionOf v p u: simplify_group_table p u ol l Nothing oe exact
+simplify_group_table p u ol@(Nothing) l@(Nothing) e@(Nothing) (Just v) exact@(_) = OrEarlierVersionOf v p u: simplify_group_table p u ol l e Nothing exact
-- already defined earlier
-- 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
@@ -91,9 +92,10 @@ simplify_group_table p ol@(Nothing) l@(Nothing) e@(Nothing) (Just v) exa
-- key idea: all constraints are enforcing constraints, so we can't get
-- more, than one interval.
simplify_group :: [Dependency] -> [Dependency]
-simplify_group [dep@(AnyVersionOf _package)] = [dep]
-simplify_group [dep@(ThisMajorOf _v _p)] = [dep]
+simplify_group [dep@(AnyVersionOf _package _u)] = [dep]
+simplify_group [dep@(ThisMajorOf _v _p _u)] = [dep]
simplify_group deps = simplify_group_table package
+ uses
min_or_later_v -- >=
min_later_v -- >
max_earlier_v -- <
@@ -101,6 +103,7 @@ simplify_group deps = simplify_group_table package
exact_this_v -- ==
where
package = fromJust.getPackage $ head deps
+ uses = fromJust.getUses $ head deps
max_earlier_v = safe_minimum $ map earlier_v deps
max_or_earlier_v = safe_minimum $ map or_earlier_v deps
min_later_v = safe_maximum $ map later_v deps
@@ -110,19 +113,19 @@ simplify_group deps = simplify_group_table package
[v] -> Just v
xs -> error $ "too many exact versions:" ++ show xs
--
- earlier_v (EarlierVersionOf v _p) = Just v
+ earlier_v (EarlierVersionOf v _p _u) = Just v
earlier_v _ = Nothing
- or_earlier_v (OrEarlierVersionOf v _p) = Just v
+ or_earlier_v (OrEarlierVersionOf v _p _u) = Just v
or_earlier_v _ = Nothing
- later_v (LaterVersionOf v _p) = Just v
+ later_v (LaterVersionOf v _p _u) = Just v
later_v _ = Nothing
- or_later_v (OrLaterVersionOf v _p) = Just v
+ or_later_v (OrLaterVersionOf v _p _u) = Just v
or_later_v _ = Nothing
- this_v (ThisVersionOf v _p) = Just v
+ this_v (ThisVersionOf v _p _u) = Just v
this_v _ = Nothing
--
safe_minimum xs = case catMaybes xs of
@@ -145,15 +148,39 @@ simplify_deps deps = (concatMap (simplify_group.nub) $
cmpMaybe _ _ = False
--
getPackage :: Dependency -> Maybe PackageName
-getPackage (AnyVersionOf package) = Just package
-getPackage (ThisVersionOf _version package) = Just package
-getPackage (LaterVersionOf _version package) = Just package
-getPackage (EarlierVersionOf _version package) = Just package
-getPackage (OrLaterVersionOf _version package) = Just package
-getPackage (OrEarlierVersionOf _version package) = Just package
+getPackage (AnyVersionOf package _uses) = Just package
+getPackage (ThisVersionOf _version package _uses) = Just package
+getPackage (LaterVersionOf _version package _uses) = Just package
+getPackage (EarlierVersionOf _version package _uses) = Just package
+getPackage (OrLaterVersionOf _version package _uses) = Just package
+getPackage (OrEarlierVersionOf _version package _uses) = Just package
getPackage (DependEither _dependency ) = Nothing
getPackage (DependIfUse _useFlag _Dependency) = Nothing
-getPackage (ThisMajorOf _version package) = Just package
+getPackage (ThisMajorOf _version package _uses) = Just package
+
+getUses :: Dependency -> Maybe [UseFlag]
+getUses (AnyVersionOf _p u) = Just u
+getUses (ThisVersionOf _v _p u) = Just u
+getUses (LaterVersionOf _v _p u) = Just u
+getUses (EarlierVersionOf _v _p u) = Just u
+getUses (OrLaterVersionOf _v _p u) = Just u
+getUses (OrEarlierVersionOf _v _p u) = Just u
+getUses (DependEither _d) = Nothing
+getUses (DependIfUse _u _d) = Nothing
+getUses (ThisMajorOf _v _p u) = Just u
+
--
getPackagePart :: Dependency -> PackageName
getPackagePart dep = fromJust (getPackage dep)
+
+--
+addDepUseFlag :: Dependency -> UseFlag -> Dependency
+addDepUseFlag (AnyVersionOf p u) n = AnyVersionOf p (n:u)
+addDepUseFlag (ThisVersionOf v p u) n = ThisVersionOf v p (n:u)
+addDepUseFlag (LaterVersionOf v p u) n = LaterVersionOf v p (n:u)
+addDepUseFlag (EarlierVersionOf v p u) n = EarlierVersionOf v p (n:u)
+addDepUseFlag (OrLaterVersionOf v p u) n = OrLaterVersionOf v p (n:u)
+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 (\d' -> map (flip addDepUseFlag n) d') d
+addDepUseFlag (DependIfUse u d) n = DependIfUse u (addDepUseFlag d n)
View
50 Portage/Use.hs
@@ -0,0 +1,50 @@
+module Portage.Use (
+ -- * main structures
+ UseFlag(..),
+ Use,
+ dispUses,
+ -- * helpers
+ mkUse,
+ mkNotUse,
+ mkQUse
+ ) where
+
+import qualified Text.PrettyPrint as Disp
+import Text.PrettyPrint ((<>))
+import Distribution.Text ( Text(..) )
+
+-- | Use variable modificator
+data UseFlag = UseFlag Use -- ^ no modificator
+ | E UseFlag -- ^ = modificator (Equiv mark)
+ | Q UseFlag -- ^ ? modificator (Question mark)
+ | X UseFlag -- ^ ! modificator (eXclamation mark)
+ | N UseFlag -- ^ - modificator
+ deriving (Eq,Show,Ord,Read)
+
+-- |
+mkUse :: Use -> UseFlag
+mkUse = UseFlag
+
+mkNotUse :: Use -> UseFlag
+mkNotUse = UseFlag
+
+mkQUse :: Use -> UseFlag
+mkQUse = Q . UseFlag
+
+
+instance Text UseFlag where
+ disp = showModificator
+
+showModificator :: UseFlag -> Disp.Doc
+showModificator (UseFlag u) = Disp.text u
+showModificator (X u) = Disp.char '!' <> disp u
+showModificator (Q u) = disp u <> Disp.char '?'
+showModificator (E u) = disp u <> Disp.char '='
+showModificator (N u) = Disp.char '-' <> disp u
+
+dispUses :: [UseFlag] -> Disp.Doc
+dispUses [] = Disp.empty
+dispUses us = Disp.brackets $ Disp.hcat $ (Disp.punctuate (Disp.text ", ")) $ map disp us
+
+type Use = String
+

0 comments on commit 620218b

Please sign in to comment.
Something went wrong with that request. Please try again.