{-# LANGUAGE DeriveDataTypeable, FlexibleInstances, MultiParamTypeClasses, TypeSynonymInstances #-}
module Debian.Debianize.VersionSplits
( DebBase(DebBase, unDebBase)
, VersionSplits(..)
, makePackage
, insertSplit
, cabalFromDebian
, cabalFromDebian'
, debianFromCabal
, packageRangesFromVersionSplits
, doSplits
) where
import Data.Generics (Data, Typeable)
import Data.Map as Map (elems, Map, mapMaybeWithKey)
import Data.Set as Set (fromList, Set, toList)
import Debian.Debianize.Interspersed (foldTriples, Interspersed(leftmost, pairs, foldInverted))
import Debian.Orphans ()
import qualified Debian.Relation as D (VersionReq(..))
import Debian.Version (DebianVersion, parseDebianVersion')
import Distribution.Package (PackageIdentifier(..), PackageName)
import Distribution.Package (mkPackageName)
import Distribution.Pretty (prettyShow)
import Distribution.Version (Version)
import Distribution.Version (anyVersion, earlierVersion, intersectVersionRanges, orLaterVersion, VersionRange)
import Prelude hiding (init, log, unlines)
newtype DebBase = DebBase {DebBase -> String
unDebBase :: String} deriving (DebBase -> DebBase -> Bool
(DebBase -> DebBase -> Bool)
-> (DebBase -> DebBase -> Bool) -> Eq DebBase
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DebBase -> DebBase -> Bool
== :: DebBase -> DebBase -> Bool
$c/= :: DebBase -> DebBase -> Bool
/= :: DebBase -> DebBase -> Bool
Eq, Eq DebBase
Eq DebBase =>
(DebBase -> DebBase -> Ordering)
-> (DebBase -> DebBase -> Bool)
-> (DebBase -> DebBase -> Bool)
-> (DebBase -> DebBase -> Bool)
-> (DebBase -> DebBase -> Bool)
-> (DebBase -> DebBase -> DebBase)
-> (DebBase -> DebBase -> DebBase)
-> Ord DebBase
DebBase -> DebBase -> Bool
DebBase -> DebBase -> Ordering
DebBase -> DebBase -> DebBase
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: DebBase -> DebBase -> Ordering
compare :: DebBase -> DebBase -> Ordering
$c< :: DebBase -> DebBase -> Bool
< :: DebBase -> DebBase -> Bool
$c<= :: DebBase -> DebBase -> Bool
<= :: DebBase -> DebBase -> Bool
$c> :: DebBase -> DebBase -> Bool
> :: DebBase -> DebBase -> Bool
$c>= :: DebBase -> DebBase -> Bool
>= :: DebBase -> DebBase -> Bool
$cmax :: DebBase -> DebBase -> DebBase
max :: DebBase -> DebBase -> DebBase
$cmin :: DebBase -> DebBase -> DebBase
min :: DebBase -> DebBase -> DebBase
Ord, ReadPrec [DebBase]
ReadPrec DebBase
Int -> ReadS DebBase
ReadS [DebBase]
(Int -> ReadS DebBase)
-> ReadS [DebBase]
-> ReadPrec DebBase
-> ReadPrec [DebBase]
-> Read DebBase
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS DebBase
readsPrec :: Int -> ReadS DebBase
$creadList :: ReadS [DebBase]
readList :: ReadS [DebBase]
$creadPrec :: ReadPrec DebBase
readPrec :: ReadPrec DebBase
$creadListPrec :: ReadPrec [DebBase]
readListPrec :: ReadPrec [DebBase]
Read, Int -> DebBase -> String -> String
[DebBase] -> String -> String
DebBase -> String
(Int -> DebBase -> String -> String)
-> (DebBase -> String)
-> ([DebBase] -> String -> String)
-> Show DebBase
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> DebBase -> String -> String
showsPrec :: Int -> DebBase -> String -> String
$cshow :: DebBase -> String
show :: DebBase -> String
$cshowList :: [DebBase] -> String -> String
showList :: [DebBase] -> String -> String
Show, Typeable DebBase
Typeable DebBase =>
(forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DebBase -> c DebBase)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DebBase)
-> (DebBase -> Constr)
-> (DebBase -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c DebBase))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c DebBase))
-> ((forall b. Data b => b -> b) -> DebBase -> DebBase)
-> (forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> DebBase -> r)
-> (forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> DebBase -> r)
-> (forall u. (forall d. Data d => d -> u) -> DebBase -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> DebBase -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> DebBase -> m DebBase)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DebBase -> m DebBase)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DebBase -> m DebBase)
-> Data DebBase
DebBase -> Constr
DebBase -> DataType
(forall b. Data b => b -> b) -> DebBase -> DebBase
forall a.
Typeable a =>
(forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> DebBase -> u
forall u. (forall d. Data d => d -> u) -> DebBase -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> DebBase -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> DebBase -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> DebBase -> m DebBase
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DebBase -> m DebBase
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DebBase
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DebBase -> c DebBase
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c DebBase)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c DebBase)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DebBase -> c DebBase
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DebBase -> c DebBase
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DebBase
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DebBase
$ctoConstr :: DebBase -> Constr
toConstr :: DebBase -> Constr
$cdataTypeOf :: DebBase -> DataType
dataTypeOf :: DebBase -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c DebBase)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c DebBase)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c DebBase)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c DebBase)
$cgmapT :: (forall b. Data b => b -> b) -> DebBase -> DebBase
gmapT :: (forall b. Data b => b -> b) -> DebBase -> DebBase
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> DebBase -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> DebBase -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> DebBase -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> DebBase -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> DebBase -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> DebBase -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> DebBase -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> DebBase -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> DebBase -> m DebBase
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> DebBase -> m DebBase
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DebBase -> m DebBase
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DebBase -> m DebBase
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DebBase -> m DebBase
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DebBase -> m DebBase
Data, Typeable)
data VersionSplits
= VersionSplits {
VersionSplits -> DebBase
oldestPackage :: DebBase
, VersionSplits -> [(Version, DebBase)]
splits :: [(Version, DebBase)]
} deriving (VersionSplits -> VersionSplits -> Bool
(VersionSplits -> VersionSplits -> Bool)
-> (VersionSplits -> VersionSplits -> Bool) -> Eq VersionSplits
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: VersionSplits -> VersionSplits -> Bool
== :: VersionSplits -> VersionSplits -> Bool
$c/= :: VersionSplits -> VersionSplits -> Bool
/= :: VersionSplits -> VersionSplits -> Bool
Eq, Eq VersionSplits
Eq VersionSplits =>
(VersionSplits -> VersionSplits -> Ordering)
-> (VersionSplits -> VersionSplits -> Bool)
-> (VersionSplits -> VersionSplits -> Bool)
-> (VersionSplits -> VersionSplits -> Bool)
-> (VersionSplits -> VersionSplits -> Bool)
-> (VersionSplits -> VersionSplits -> VersionSplits)
-> (VersionSplits -> VersionSplits -> VersionSplits)
-> Ord VersionSplits
VersionSplits -> VersionSplits -> Bool
VersionSplits -> VersionSplits -> Ordering
VersionSplits -> VersionSplits -> VersionSplits
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: VersionSplits -> VersionSplits -> Ordering
compare :: VersionSplits -> VersionSplits -> Ordering
$c< :: VersionSplits -> VersionSplits -> Bool
< :: VersionSplits -> VersionSplits -> Bool
$c<= :: VersionSplits -> VersionSplits -> Bool
<= :: VersionSplits -> VersionSplits -> Bool
$c> :: VersionSplits -> VersionSplits -> Bool
> :: VersionSplits -> VersionSplits -> Bool
$c>= :: VersionSplits -> VersionSplits -> Bool
>= :: VersionSplits -> VersionSplits -> Bool
$cmax :: VersionSplits -> VersionSplits -> VersionSplits
max :: VersionSplits -> VersionSplits -> VersionSplits
$cmin :: VersionSplits -> VersionSplits -> VersionSplits
min :: VersionSplits -> VersionSplits -> VersionSplits
Ord, Typeable VersionSplits
Typeable VersionSplits =>
(forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> VersionSplits -> c VersionSplits)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c VersionSplits)
-> (VersionSplits -> Constr)
-> (VersionSplits -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c VersionSplits))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c VersionSplits))
-> ((forall b. Data b => b -> b) -> VersionSplits -> VersionSplits)
-> (forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> VersionSplits -> r)
-> (forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> VersionSplits -> r)
-> (forall u. (forall d. Data d => d -> u) -> VersionSplits -> [u])
-> (forall u.
Int -> (forall d. Data d => d -> u) -> VersionSplits -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> VersionSplits -> m VersionSplits)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> VersionSplits -> m VersionSplits)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> VersionSplits -> m VersionSplits)
-> Data VersionSplits
VersionSplits -> Constr
VersionSplits -> DataType
(forall b. Data b => b -> b) -> VersionSplits -> VersionSplits
forall a.
Typeable a =>
(forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> VersionSplits -> u
forall u. (forall d. Data d => d -> u) -> VersionSplits -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> VersionSplits -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> VersionSplits -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> VersionSplits -> m VersionSplits
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> VersionSplits -> m VersionSplits
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c VersionSplits
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> VersionSplits -> c VersionSplits
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c VersionSplits)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c VersionSplits)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> VersionSplits -> c VersionSplits
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> VersionSplits -> c VersionSplits
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c VersionSplits
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c VersionSplits
$ctoConstr :: VersionSplits -> Constr
toConstr :: VersionSplits -> Constr
$cdataTypeOf :: VersionSplits -> DataType
dataTypeOf :: VersionSplits -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c VersionSplits)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c VersionSplits)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c VersionSplits)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c VersionSplits)
$cgmapT :: (forall b. Data b => b -> b) -> VersionSplits -> VersionSplits
gmapT :: (forall b. Data b => b -> b) -> VersionSplits -> VersionSplits
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> VersionSplits -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> VersionSplits -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> VersionSplits -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> VersionSplits -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> VersionSplits -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> VersionSplits -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> VersionSplits -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> VersionSplits -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> VersionSplits -> m VersionSplits
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> VersionSplits -> m VersionSplits
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> VersionSplits -> m VersionSplits
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> VersionSplits -> m VersionSplits
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> VersionSplits -> m VersionSplits
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> VersionSplits -> m VersionSplits
Data, Typeable)
instance Show VersionSplits where
show :: VersionSplits -> String
show VersionSplits
s = ((Version, DebBase) -> String -> String)
-> String -> [(Version, DebBase)] -> String
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\ (Version
v, DebBase
b) String
r -> (String
"insertSplit (" String -> String -> String
forall a. [a] -> [a] -> [a]
++ Version -> String
forall a. Show a => a -> String
show Version
v String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
") (" String -> String -> String
forall a. [a] -> [a] -> [a]
++ DebBase -> String
forall a. Show a => a -> String
show DebBase
b String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
") (" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
r String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
")")) (String
"makePackage (" String -> String -> String
forall a. [a] -> [a] -> [a]
++ DebBase -> String
forall a. Show a => a -> String
show (VersionSplits -> DebBase
oldestPackage VersionSplits
s) String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
")") (VersionSplits -> [(Version, DebBase)]
splits VersionSplits
s)
instance Interspersed VersionSplits DebBase Version where
leftmost :: VersionSplits -> DebBase
leftmost (VersionSplits {oldestPackage :: VersionSplits -> DebBase
oldestPackage = DebBase
p}) = DebBase
p
pairs :: VersionSplits -> [(Version, DebBase)]
pairs (VersionSplits {splits :: VersionSplits -> [(Version, DebBase)]
splits = [(Version, DebBase)]
xs}) = [(Version, DebBase)]
xs
makePackage :: DebBase -> VersionSplits
makePackage :: DebBase -> VersionSplits
makePackage DebBase
name = VersionSplits {oldestPackage :: DebBase
oldestPackage = DebBase
name, splits :: [(Version, DebBase)]
splits = []}
insertSplit :: Version
-> DebBase
-> VersionSplits
-> VersionSplits
insertSplit :: Version -> DebBase -> VersionSplits -> VersionSplits
insertSplit Version
ver DebBase
ltname sp :: VersionSplits
sp@(VersionSplits {}) =
case VersionSplits -> [(Version, DebBase)]
splits VersionSplits
sp of
(Version
ver', DebBase
_) : [(Version, DebBase)]
_ | Version
ver' Version -> Version -> Bool
forall a. Ord a => a -> a -> Bool
> Version
ver -> VersionSplits
sp {oldestPackage = ltname, splits = (ver, oldestPackage sp) : splits sp}
(Version
ver', DebBase
name) : [(Version, DebBase)]
_ | Version
ver' Version -> Version -> Bool
forall a. Eq a => a -> a -> Bool
== Version
ver Bool -> Bool -> Bool
&& DebBase
name DebBase -> DebBase -> Bool
forall a. Eq a => a -> a -> Bool
== DebBase
ltname -> VersionSplits
sp
[] -> VersionSplits
sp {oldestPackage = ltname, splits = [(ver, oldestPackage sp)]}
[(Version, DebBase)]
_ -> VersionSplits
sp {splits = reverse (insert (reverse (splits sp)))}
where
insert :: [(Version, DebBase)] -> [(Version, DebBase)]
insert ((Version
ver', DebBase
name') : [(Version, DebBase)]
more) =
if Version
ver' Version -> Version -> Bool
forall a. Ord a => a -> a -> Bool
< Version
ver
then (Version
ver, DebBase
name') (Version, DebBase) -> [(Version, DebBase)] -> [(Version, DebBase)]
forall a. a -> [a] -> [a]
: (Version
ver', DebBase
ltname) (Version, DebBase) -> [(Version, DebBase)] -> [(Version, DebBase)]
forall a. a -> [a] -> [a]
: [(Version, DebBase)]
more
else (Version
ver', DebBase
name') (Version, DebBase) -> [(Version, DebBase)] -> [(Version, DebBase)]
forall a. a -> [a] -> [a]
: [(Version, DebBase)] -> [(Version, DebBase)]
insert [(Version, DebBase)]
more
insert [] = [(Version
ver, VersionSplits -> DebBase
oldestPackage VersionSplits
sp)]
packageRangesFromVersionSplits :: VersionSplits -> [(DebBase, VersionRange)]
packageRangesFromVersionSplits :: VersionSplits -> [(DebBase, VersionRange)]
packageRangesFromVersionSplits VersionSplits
s =
(Maybe Version
-> DebBase
-> Maybe Version
-> [(DebBase, VersionRange)]
-> [(DebBase, VersionRange)])
-> [(DebBase, VersionRange)]
-> VersionSplits
-> [(DebBase, VersionRange)]
forall r.
(Maybe Version -> DebBase -> Maybe Version -> r -> r)
-> r -> VersionSplits -> r
forall t around between r.
Interspersed t around between =>
(Maybe between -> around -> Maybe between -> r -> r) -> r -> t -> r
foldInverted (\ Maybe Version
older DebBase
dname Maybe Version
newer [(DebBase, VersionRange)]
more ->
(DebBase
dname, VersionRange -> VersionRange -> VersionRange
intersectVersionRanges (VersionRange
-> (Version -> VersionRange) -> Maybe Version -> VersionRange
forall b a. b -> (a -> b) -> Maybe a -> b
maybe VersionRange
anyVersion Version -> VersionRange
orLaterVersion Maybe Version
older) (VersionRange
-> (Version -> VersionRange) -> Maybe Version -> VersionRange
forall b a. b -> (a -> b) -> Maybe a -> b
maybe VersionRange
anyVersion Version -> VersionRange
earlierVersion Maybe Version
newer)) (DebBase, VersionRange)
-> [(DebBase, VersionRange)] -> [(DebBase, VersionRange)]
forall a. a -> [a] -> [a]
: [(DebBase, VersionRange)]
more)
[]
VersionSplits
s
debianFromCabal :: VersionSplits -> PackageIdentifier -> DebBase
debianFromCabal :: VersionSplits -> PackageIdentifier -> DebBase
debianFromCabal VersionSplits
s PackageIdentifier
p =
VersionSplits -> Maybe VersionReq -> DebBase
doSplits VersionSplits
s (VersionReq -> Maybe VersionReq
forall a. a -> Maybe a
Just (DebianVersion -> VersionReq
D.EEQ DebianVersion
debVer))
where debVer :: DebianVersion
debVer = String -> DebianVersion
forall string. ParseDebianVersion string => string -> DebianVersion
parseDebianVersion' (Version -> String
forall a. Pretty a => a -> String
prettyShow (PackageIdentifier -> Version
pkgVersion PackageIdentifier
p))
cabalFromDebian' :: Map PackageName VersionSplits -> DebBase -> Version -> PackageIdentifier
cabalFromDebian' :: Map PackageName VersionSplits
-> DebBase -> Version -> PackageIdentifier
cabalFromDebian' Map PackageName VersionSplits
mp DebBase
base Version
ver =
PackageName -> Version -> PackageIdentifier
PackageIdentifier (Map PackageName VersionSplits
-> DebBase -> DebianVersion -> PackageName
cabalFromDebian Map PackageName VersionSplits
mp DebBase
base DebianVersion
dver) Version
ver
where dver :: DebianVersion
dver = String -> DebianVersion
forall string. ParseDebianVersion string => string -> DebianVersion
parseDebianVersion' (Version -> String
forall a. Pretty a => a -> String
prettyShow Version
ver)
cabalFromDebian :: Map PackageName VersionSplits -> DebBase -> DebianVersion -> PackageName
cabalFromDebian :: Map PackageName VersionSplits
-> DebBase -> DebianVersion -> PackageName
cabalFromDebian Map PackageName VersionSplits
mp base :: DebBase
base@(DebBase String
name) DebianVersion
ver =
case Set PackageName -> [PackageName]
forall a. Set a -> [a]
Set.toList Set PackageName
pset of
[PackageName
x] -> PackageName
x
[] -> String -> PackageName
mkPackageName String
name
[PackageName]
l -> String -> PackageName
forall a. HasCallStack => String -> a
error (String -> PackageName) -> String -> PackageName
forall a b. (a -> b) -> a -> b
$ String
"Error, multiple cabal package names associated with " String -> String -> String
forall a. [a] -> [a] -> [a]
++ DebBase -> String
forall a. Show a => a -> String
show DebBase
base String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
": " String -> String -> String
forall a. [a] -> [a] -> [a]
++ [PackageName] -> String
forall a. Show a => a -> String
show [PackageName]
l
where
pset :: Set PackageName
pset :: Set PackageName
pset = [PackageName] -> Set PackageName
forall a. Ord a => [a] -> Set a
Set.fromList ([PackageName] -> Set PackageName)
-> [PackageName] -> Set PackageName
forall a b. (a -> b) -> a -> b
$ Map PackageName PackageName -> [PackageName]
forall k a. Map k a -> [a]
Map.elems (Map PackageName PackageName -> [PackageName])
-> Map PackageName PackageName -> [PackageName]
forall a b. (a -> b) -> a -> b
$
(PackageName -> VersionSplits -> Maybe PackageName)
-> Map PackageName VersionSplits -> Map PackageName PackageName
forall k a b. (k -> a -> Maybe b) -> Map k a -> Map k b
Map.mapMaybeWithKey
(\ PackageName
p VersionSplits
s -> if VersionSplits -> Maybe VersionReq -> DebBase
doSplits VersionSplits
s (VersionReq -> Maybe VersionReq
forall a. a -> Maybe a
Just (DebianVersion -> VersionReq
D.EEQ DebianVersion
ver)) DebBase -> DebBase -> Bool
forall a. Eq a => a -> a -> Bool
== DebBase
base then PackageName -> Maybe PackageName
forall a. a -> Maybe a
Just PackageName
p else Maybe PackageName
forall a. Maybe a
Nothing)
Map PackageName VersionSplits
mp
doSplits :: VersionSplits -> Maybe D.VersionReq -> DebBase
doSplits :: VersionSplits -> Maybe VersionReq -> DebBase
doSplits VersionSplits
s Maybe VersionReq
version =
(DebBase -> Version -> DebBase -> DebBase -> DebBase)
-> DebBase -> VersionSplits -> DebBase
foldTriples' (\ DebBase
ltName Version
v DebBase
geName DebBase
_ ->
let split :: DebianVersion
split = String -> DebianVersion
forall string. ParseDebianVersion string => string -> DebianVersion
parseDebianVersion' (Version -> String
forall a. Pretty a => a -> String
prettyShow Version
v) in
case Maybe VersionReq
version of
Maybe VersionReq
Nothing -> DebBase
geName
Just (D.SLT DebianVersion
v') | DebianVersion
v' DebianVersion -> DebianVersion -> Bool
forall a. Ord a => a -> a -> Bool
<= DebianVersion
split -> DebBase
ltName
Just (D.EEQ DebianVersion
v') | DebianVersion
v' DebianVersion -> DebianVersion -> Bool
forall a. Ord a => a -> a -> Bool
< DebianVersion
split -> DebBase
ltName
Just (D.LTE DebianVersion
v') | DebianVersion
v' DebianVersion -> DebianVersion -> Bool
forall a. Ord a => a -> a -> Bool
< DebianVersion
split -> DebBase
ltName
Just (D.GRE DebianVersion
v') | DebianVersion
v' DebianVersion -> DebianVersion -> Bool
forall a. Ord a => a -> a -> Bool
< DebianVersion
split -> DebBase
ltName
Just (D.SGR DebianVersion
v') | DebianVersion
v' DebianVersion -> DebianVersion -> Bool
forall a. Ord a => a -> a -> Bool
< DebianVersion
split -> DebBase
ltName
Maybe VersionReq
_ -> DebBase
geName)
(VersionSplits -> DebBase
oldestPackage VersionSplits
s)
VersionSplits
s
where
foldTriples' :: (DebBase -> Version -> DebBase -> DebBase -> DebBase) -> DebBase -> VersionSplits -> DebBase
foldTriples' :: (DebBase -> Version -> DebBase -> DebBase -> DebBase)
-> DebBase -> VersionSplits -> DebBase
foldTriples' = (DebBase -> Version -> DebBase -> DebBase -> DebBase)
-> DebBase -> VersionSplits -> DebBase
forall r.
(DebBase -> Version -> DebBase -> r -> r)
-> r -> VersionSplits -> r
forall t around between r.
Interspersed t around between =>
(around -> between -> around -> r -> r) -> r -> t -> r
foldTriples