module Debian.Debianize.CabalInfo
(
CabalInfo
, PackageInfo(PackageInfo, cabalName, devDeb, docDeb, profDeb)
, packageDescription
, debInfo
, debianNameMap
, epochMap
, packageInfo
, newCabalInfo
) where
#if !MIN_VERSION_base(4,8,0)
import Control.Applicative ((<$>))
import Data.Monoid (Monoid(..))
#endif
import Control.Lens
import Control.Monad.Catch (MonadMask)
import Control.Monad.State (execStateT)
import Control.Monad.Trans (MonadIO, liftIO)
import Data.Generics (Data, Typeable)
import Data.Map as Map (Map)
import Data.Text as Text (null, pack, strip)
import Debian.Debianize.BasicInfo (Flags)
import Debian.Debianize.DebInfo as D (control, copyright, DebInfo, makeDebInfo)
import Debian.Debianize.BinaryDebDescription (Canonical(canonical))
import Debian.Debianize.CopyrightDescription (defaultCopyrightDescription)
import Debian.Debianize.InputCabal (inputCabalization)
import Debian.Debianize.SourceDebDescription as S (homepage)
import Debian.Debianize.VersionSplits (VersionSplits)
import Debian.Orphans ()
import Debian.Relation (BinPkgName)
import Debian.Version (DebianVersion)
import Distribution.Package (PackageName)
import Distribution.PackageDescription as Cabal (PackageDescription(homepage))
import Prelude hiding (init, init, log, log, null)
import System.Unix.Mount (withProcAndSys)
data CabalInfo
= CabalInfo
{ _packageDescription :: PackageDescription
, _debInfo :: DebInfo
, _debianNameMap :: Map PackageName VersionSplits
, _epochMap :: Map PackageName Int
, _packageInfo :: Map PackageName PackageInfo
} deriving (Show, Data, Typeable)
data PackageInfo = PackageInfo { cabalName :: PackageName
, devDeb :: Maybe (BinPkgName, DebianVersion)
, profDeb :: Maybe (BinPkgName, DebianVersion)
, docDeb :: Maybe (BinPkgName, DebianVersion) } deriving (Eq, Ord, Show, Data, Typeable)
$(makeLenses ''CabalInfo)
instance Canonical CabalInfo where
canonical x = x {_debInfo = canonical (_debInfo x)}
newCabalInfo :: (MonadIO m, MonadMask m, Functor m) => Flags -> m (Either String CabalInfo)
newCabalInfo flags' =
withProcAndSys "/" $ inputCabalization flags' >>= either (return . Left) (\p -> Right <$> doPkgDesc p)
where
doPkgDesc pkgDesc = do
copyrt <- liftIO $ defaultCopyrightDescription pkgDesc
execStateT
(do (debInfo . copyright) .= Just copyrt
(debInfo . control . S.homepage) .= case strip (pack (Cabal.homepage pkgDesc)) of
x | Text.null x -> Nothing
x -> Just x)
(makeCabalInfo flags' pkgDesc)
makeCabalInfo :: Flags -> PackageDescription -> CabalInfo
makeCabalInfo fs pkgDesc =
CabalInfo
{ _packageDescription = pkgDesc
, _epochMap = mempty
, _packageInfo = mempty
, _debianNameMap = mempty
, _debInfo = makeDebInfo fs
}