{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}

module Distribution.Types.BuildType (
    BuildType(..),
    knownBuildTypes,
) where

import Prelude ()
import Distribution.Compat.Prelude

import Distribution.CabalSpecVersion (CabalSpecVersion (..))
import Distribution.Pretty
import Distribution.Parsec

import qualified Distribution.Compat.CharParsing as P
import qualified Text.PrettyPrint as Disp

-- | The type of build system used by this package.
data BuildType
  = Simple      -- ^ calls @Distribution.Simple.defaultMain@
  | Configure   -- ^ calls @Distribution.Simple.defaultMainWithHooks defaultUserHooks@,
                -- which invokes @configure@ to generate additional build
                -- information used by later phases.
  | Make        -- ^ calls @Distribution.Make.defaultMain@
  | Custom      -- ^ uses user-supplied @Setup.hs@ or @Setup.lhs@ (default)
                deriving (forall x. Rep BuildType x -> BuildType
forall x. BuildType -> Rep BuildType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BuildType x -> BuildType
$cfrom :: forall x. BuildType -> Rep BuildType x
Generic, Int -> BuildType -> ShowS
[BuildType] -> ShowS
BuildType -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BuildType] -> ShowS
$cshowList :: [BuildType] -> ShowS
show :: BuildType -> String
$cshow :: BuildType -> String
showsPrec :: Int -> BuildType -> ShowS
$cshowsPrec :: Int -> BuildType -> ShowS
Show, ReadPrec [BuildType]
ReadPrec BuildType
Int -> ReadS BuildType
ReadS [BuildType]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BuildType]
$creadListPrec :: ReadPrec [BuildType]
readPrec :: ReadPrec BuildType
$creadPrec :: ReadPrec BuildType
readList :: ReadS [BuildType]
$creadList :: ReadS [BuildType]
readsPrec :: Int -> ReadS BuildType
$creadsPrec :: Int -> ReadS BuildType
Read, BuildType -> BuildType -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BuildType -> BuildType -> Bool
$c/= :: BuildType -> BuildType -> Bool
== :: BuildType -> BuildType -> Bool
$c== :: BuildType -> BuildType -> Bool
Eq, Typeable, Typeable BuildType
BuildType -> DataType
BuildType -> Constr
(forall b. Data b => b -> b) -> BuildType -> BuildType
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) -> BuildType -> u
forall u. (forall d. Data d => d -> u) -> BuildType -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuildType -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuildType -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BuildType -> m BuildType
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuildType -> m BuildType
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuildType
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuildType -> c BuildType
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BuildType)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c BuildType)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuildType -> m BuildType
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuildType -> m BuildType
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuildType -> m BuildType
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuildType -> m BuildType
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BuildType -> m BuildType
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BuildType -> m BuildType
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BuildType -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BuildType -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> BuildType -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> BuildType -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuildType -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuildType -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuildType -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuildType -> r
gmapT :: (forall b. Data b => b -> b) -> BuildType -> BuildType
$cgmapT :: (forall b. Data b => b -> b) -> BuildType -> BuildType
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c BuildType)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c BuildType)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BuildType)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BuildType)
dataTypeOf :: BuildType -> DataType
$cdataTypeOf :: BuildType -> DataType
toConstr :: BuildType -> Constr
$ctoConstr :: BuildType -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuildType
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuildType
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuildType -> c BuildType
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuildType -> c BuildType
Data)

instance Binary BuildType
instance Structured BuildType
instance NFData BuildType where rnf :: BuildType -> ()
rnf = forall a. (Generic a, GNFData (Rep a)) => a -> ()
genericRnf

knownBuildTypes :: [BuildType]
knownBuildTypes :: [BuildType]
knownBuildTypes = [BuildType
Simple, BuildType
Configure, BuildType
Make, BuildType
Custom]

instance Pretty BuildType where
  pretty :: BuildType -> Doc
pretty = String -> Doc
Disp.text forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show

instance Parsec BuildType where
  parsec :: forall (m :: * -> *). CabalParsing m => m BuildType
parsec = do
    String
name <- forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m String
P.munch1 Char -> Bool
isAlphaNum
    case String
name of
      String
"Simple"    -> forall (m :: * -> *) a. Monad m => a -> m a
return BuildType
Simple
      String
"Configure" -> forall (m :: * -> *) a. Monad m => a -> m a
return BuildType
Configure
      String
"Custom"    -> forall (m :: * -> *) a. Monad m => a -> m a
return BuildType
Custom
      String
"Make"      -> forall (m :: * -> *) a. Monad m => a -> m a
return BuildType
Make
      String
"Default"   -> do
          CabalSpecVersion
v <- forall (m :: * -> *). CabalParsing m => m CabalSpecVersion
askCabalSpecVersion
          if CabalSpecVersion
v forall a. Ord a => a -> a -> Bool
<= CabalSpecVersion
CabalSpecV1_18 -- oldest version needing this, based on hackage-tests
          then do
              forall (m :: * -> *). CabalParsing m => PWarnType -> String -> m ()
parsecWarning PWarnType
PWTBuildTypeDefault String
"build-type: Default is parsed as Custom for legacy reasons. See https://github.com/haskell/cabal/issues/5020"
              forall (m :: * -> *) a. Monad m => a -> m a
return BuildType
Custom
          else forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"unknown build-type: '" forall a. [a] -> [a] -> [a]
++ String
name forall a. [a] -> [a] -> [a]
++ String
"'")
      String
_           -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"unknown build-type: '" forall a. [a] -> [a] -> [a]
++ String
name forall a. [a] -> [a] -> [a]
++ String
"'")