module Debian.Debianize.BasicInfo
(
Flags(..)
, EnvSet(..)
, DebType(..)
, verbosity
, dryRun
, upgrade
, roundtrip
, validate
, compilerFlavor
, cabalFlagAssignments
, buildEnv
, flagOptions
) where
import Control.Lens
import Control.Monad.State (StateT)
import Control.Monad.Trans (MonadIO)
import Data.Char (toLower, toUpper)
import Data.Generics (Data, Typeable)
import Data.Set as Set (fromList, Set, union)
import Debian.Debianize.Prelude (read')
import Debian.Orphans ()
import Distribution.Compiler (CompilerFlavor(..))
#if MIN_VERSION_Cabal(2,0,0)
import Distribution.PackageDescription as Cabal (FlagName, mkFlagName)
#else
import Distribution.PackageDescription as Cabal (FlagName(FlagName))
#endif
import Prelude hiding (break, lines, log, null, readFile, sum)
import System.Console.GetOpt (ArgDescr(ReqArg, NoArg), OptDescr(Option))
import System.FilePath ((</>))
import Text.Read (readMaybe)
data Flags = Flags
{
_verbosity :: Int
, _dryRun :: Bool
, _upgrade :: Bool
, _roundtrip :: Bool
, _validate :: Bool
, _compilerFlavor :: CompilerFlavor
, _cabalFlagAssignments :: Set (FlagName, Bool)
, _buildEnv :: EnvSet
} deriving (Eq, Ord, Show, Data, Typeable)
data EnvSet = EnvSet
{ cleanOS :: FilePath
, dependOS :: FilePath
, buildOS :: FilePath
} deriving (Eq, Ord, Show, Data, Typeable)
data DebType = Dev | Prof | Doc deriving (Eq, Ord, Read, Show, Data, Typeable)
$(makeLenses ''Flags)
flagOptions :: MonadIO m => [OptDescr (StateT Flags m ())]
flagOptions =
[ Option "v" ["verbose"] (ReqArg (\ s -> verbosity .= (read' (\ s' -> error $ "verbose: " ++ show s') s :: Int)) "number")
"Change the amount of progress messages generated",
Option "n" ["dry-run", "compare"] (NoArg (dryRun .= True))
"Just compare the existing debianization to the one we would generate.",
Option "" ["upgrade"] (NoArg (upgrade .= True))
"Carefully upgrade an existing debianization",
Option "" ["roundtrip"] (NoArg (roundtrip .= True))
"Rountrip a debianization to normalize it",
Option "" ["ghc"] (NoArg (compilerFlavor .= GHC)) "Generate packages for GHC - same as --with-compiler GHC",
#if MIN_VERSION_Cabal(1,22,0)
Option "" ["ghcjs"] (NoArg (compilerFlavor .= GHCJS)) "Generate packages for GHCJS - same as --with-compiler GHCJS",
#endif
Option "" ["hugs"] (NoArg (compilerFlavor .= Hugs)) "Generate packages for Hugs - same as --with-compiler GHC",
Option "" ["with-compiler"] (ReqArg (\ s -> maybe (error $ "Invalid compiler id: " ++ show s)
(\ hc -> compilerFlavor .= hc)
(readMaybe (map toUpper s) :: Maybe CompilerFlavor)) "COMPILER")
(unlines [ "Generate packages for this CompilerFlavor" ]),
Option "f" ["flags"] (ReqArg (\ fs -> cabalFlagAssignments %= (Set.union (Set.fromList (flagList fs)))) "FLAGS")
(unlines [ "Flags to pass to the finalizePackageDescription function in"
, "Distribution.PackageDescription.Configuration when loading the cabal file."]),
Option "" ["buildenvdir"] (ReqArg (\ s -> buildEnv .= EnvSet {cleanOS = s </> "clean", dependOS = s </> "depend", buildOS = s </> "build"}) "PATH")
"Directory containing the three build environments, clean, depend, and build.",
Option "f" ["cabal-flags"] (ReqArg (\ s -> cabalFlagAssignments %= (Set.union (fromList (flagList s)))) "FLAG FLAG ...")
"Flags to pass to cabal configure with the --flags= option "
]
flagList :: String -> [(FlagName, Bool)]
flagList = map tagWithValue . words
#if MIN_VERSION_Cabal(2,0,0)
where tagWithValue ('-':name) = (mkFlagName (map toLower name), False)
tagWithValue name = (mkFlagName (map toLower name), True)
#else
where tagWithValue ('-':name) = (FlagName (map toLower name), False)
tagWithValue name = (FlagName (map toLower name), True)
#endif