Distribution.Types.Flag

Cabal-3.4.0.0: A framework for packaging Haskell software

Safe Haskell | None
Language | Haskell2010

Distribution.Types.Flag

Contents

- Package flag
- Flag name
- Flag assignment
  - Legacy formats

Synopsis

- data PackageFlag = MkPackageFlag {
  - flagName :: FlagName
  - flagDescription :: String
  - flagDefault :: Bool
  - flagManual :: Bool
  }
- emptyFlag :: FlagName -> PackageFlag
- data FlagName
- mkFlagName :: String -> FlagName
- unFlagName :: FlagName -> String
- data FlagAssignment
- mkFlagAssignment :: [(FlagName, Bool)] -> FlagAssignment
- unFlagAssignment :: FlagAssignment -> [(FlagName, Bool)]
- lookupFlagAssignment :: FlagName -> FlagAssignment -> Maybe Bool
- insertFlagAssignment :: FlagName -> Bool -> FlagAssignment -> FlagAssignment
- diffFlagAssignment :: FlagAssignment -> FlagAssignment -> FlagAssignment
- findDuplicateFlagAssignments :: FlagAssignment -> [FlagName]
- nullFlagAssignment :: FlagAssignment -> Bool
- showFlagValue :: (FlagName, Bool) -> String
- dispFlagAssignment :: FlagAssignment -> Doc
- showFlagAssignment :: FlagAssignment -> String
- parsecFlagAssignment :: CabalParsing m => m FlagAssignment
- parsecFlagAssignmentNonEmpty :: CabalParsing m => m FlagAssignment
- legacyShowFlagAssignment :: FlagAssignment -> String
- legacyShowFlagAssignment' :: FlagAssignment -> [String]
- legacyParsecFlagAssignment :: CabalParsing m => m FlagAssignment

# Package flag

data PackageFlag Source #

A flag can represent a feature to be included, or a way of linking a target against its dependencies, or in fact whatever you can think of.

Constructors

MkPackageFlag |
Fields flagName :: FlagName flagDescription :: String flagDefault :: Bool flagManual :: Bool

#### Instances

Instances details

Eq PackageFlag # |
Instance details Defined in Distribution.Types.Flag Methods (==) :: PackageFlag -> PackageFlag -> Bool # (/=) :: PackageFlag -> PackageFlag -> Bool #
Data PackageFlag # |
Instance details Defined in Distribution.Types.Flag Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> PackageFlag -> c PackageFlag Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c PackageFlag Source # toConstr :: PackageFlag -> Constr Source # dataTypeOf :: PackageFlag -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c PackageFlag) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PackageFlag) Source # gmapT :: (forall b. Data b => b -> b) -> PackageFlag -> PackageFlag Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> PackageFlag -> r Source # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> PackageFlag -> r Source # gmapQ :: (forall d. Data d => d -> u) -> PackageFlag -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> PackageFlag -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> PackageFlag -> m PackageFlag Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> PackageFlag -> m PackageFlag Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> PackageFlag -> m PackageFlag Source #
Show PackageFlag # |
Instance details Defined in Distribution.Types.Flag Methods showsPrec :: Int -> PackageFlag -> ShowS Source # show :: PackageFlag -> String Source # showList :: [PackageFlag] -> ShowS Source #
Generic PackageFlag # |
Instance details Defined in Distribution.Types.Flag Associated Types type Rep PackageFlag :: Type -> Type Source # Methods from :: PackageFlag -> Rep PackageFlag x Source # to :: Rep PackageFlag x -> PackageFlag Source #
Binary PackageFlag # |
Instance details Defined in Distribution.Types.Flag Methods put :: PackageFlag -> Put Source # get :: Get PackageFlag Source # putList :: [PackageFlag] -> Put Source #
NFData PackageFlag # |
Instance details Defined in Distribution.Types.Flag Methods rnf :: PackageFlag -> () Source #
Structured PackageFlag # |
Instance details Defined in Distribution.Types.Flag Methods structure :: Proxy PackageFlag -> Structure Source # structureHash' :: Tagged PackageFlag MD5
type Rep PackageFlag # |
Instance details Defined in Distribution.Types.Flag type Rep PackageFlag = D1 ('MetaData "PackageFlag" "Distribution.Types.Flag" "Cabal-3.4.0.0" 'False) (C1 ('MetaCons "MkPackageFlag" 'PrefixI 'True) ((S1 ('MetaSel ('Just "flagName") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 FlagName) :*: S1 ('MetaSel ('Just "flagDescription") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String)) :*: (S1 ('MetaSel ('Just "flagDefault") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool) :*: S1 ('MetaSel ('Just "flagManual") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool))))

emptyFlag :: FlagName -> PackageFlag Source #

A `PackageFlag` initialized with default parameters.

# Flag name

data FlagName Source #

A `FlagName` is the name of a user-defined configuration flag

Use `mkFlagName` and `unFlagName` to convert from/to a `String`.

This type is opaque since `Cabal-2.0`

Since: Cabal-2.0.0.2

#### Instances

Instances details

Eq FlagName # |
Instance details Defined in Distribution.Types.Flag Methods (==) :: FlagName -> FlagName -> Bool # (/=) :: FlagName -> FlagName -> Bool #
Data FlagName # |
Instance details Defined in Distribution.Types.Flag Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> FlagName -> c FlagName Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c FlagName Source # toConstr :: FlagName -> Constr Source # dataTypeOf :: FlagName -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c FlagName) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c FlagName) Source # gmapT :: (forall b. Data b => b -> b) -> FlagName -> FlagName Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> FlagName -> r Source # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> FlagName -> r Source # gmapQ :: (forall d. Data d => d -> u) -> FlagName -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> FlagName -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> FlagName -> m FlagName Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> FlagName -> m FlagName Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> FlagName -> m FlagName Source #
Ord FlagName # |
Instance details Defined in Distribution.Types.Flag Methods compare :: FlagName -> FlagName -> Ordering # (<) :: FlagName -> FlagName -> Bool # (<=) :: FlagName -> FlagName -> Bool # (>) :: FlagName -> FlagName -> Bool # (>=) :: FlagName -> FlagName -> Bool # max :: FlagName -> FlagName -> FlagName # min :: FlagName -> FlagName -> FlagName #
Read FlagName # |
Instance details Defined in Distribution.Types.Flag Methods readsPrec :: Int -> ReadS FlagName Source # readList :: ReadS [FlagName] Source # readPrec :: ReadPrec FlagName Source # readListPrec :: ReadPrec [FlagName] Source #
Show FlagName # |
Instance details Defined in Distribution.Types.Flag Methods showsPrec :: Int -> FlagName -> ShowS Source # show :: FlagName -> String Source # showList :: [FlagName] -> ShowS Source #
IsString FlagName # | `mkFlagName` Since: Cabal-2.0.0.2
Instance details Defined in Distribution.Types.Flag Methods fromString :: String -> FlagName Source #
Generic FlagName # |
Instance details Defined in Distribution.Types.Flag Associated Types type Rep FlagName :: Type -> Type Source # Methods from :: FlagName -> Rep FlagName x Source # to :: Rep FlagName x -> FlagName Source #
Binary FlagName # |
Instance details Defined in Distribution.Types.Flag Methods put :: FlagName -> Put Source # get :: Get FlagName Source # putList :: [FlagName] -> Put Source #
NFData FlagName # |
Instance details Defined in Distribution.Types.Flag Methods rnf :: FlagName -> () Source #
Structured FlagName # |
Instance details Defined in Distribution.Types.Flag Methods structure :: Proxy FlagName -> Structure Source # structureHash' :: Tagged FlagName MD5
Pretty FlagName # |
Instance details Defined in Distribution.Types.Flag Methods pretty :: FlagName -> Doc Source # prettyVersioned :: CabalSpecVersion -> FlagName -> Doc Source #
Parsec FlagName # |
Instance details Defined in Distribution.Types.Flag Methods parsec :: CabalParsing m => m FlagName Source #
type Rep FlagName # |
Instance details Defined in Distribution.Types.Flag type Rep FlagName = D1 ('MetaData "FlagName" "Distribution.Types.Flag" "Cabal-3.4.0.0" 'True) (C1 ('MetaCons "FlagName" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ShortText)))

mkFlagName :: String -> FlagName Source #

Construct a `FlagName` from a `String`

`mkFlagName` is the inverse to `unFlagName`

Note: No validations are performed to ensure that the resulting `FlagName` is valid

Since: Cabal-2.0.0.2

unFlagName :: FlagName -> String Source #

Convert `FlagName` to `String`

Since: Cabal-2.0.0.2

# Flag assignment

data FlagAssignment Source #

A `FlagAssignment` is a total or partial mapping of `FlagName`s to `Bool` flag values. It represents the flags chosen by the user or discovered during configuration. For example `--flags=foo --flags=-bar` becomes `[("foo", True), ("bar", False)]`

TODO: Why we record the multiplicity of the flag?

#### Instances

Instances details

Eq FlagAssignment # |
Instance details Defined in Distribution.Types.Flag Methods (==) :: FlagAssignment -> FlagAssignment -> Bool # (/=) :: FlagAssignment -> FlagAssignment -> Bool #
Ord FlagAssignment # |
Instance details Defined in Distribution.Types.Flag Methods compare :: FlagAssignment -> FlagAssignment -> Ordering # (<) :: FlagAssignment -> FlagAssignment -> Bool # (<=) :: FlagAssignment -> FlagAssignment -> Bool # (>) :: FlagAssignment -> FlagAssignment -> Bool # (>=) :: FlagAssignment -> FlagAssignment -> Bool # max :: FlagAssignment -> FlagAssignment -> FlagAssignment # min :: FlagAssignment -> FlagAssignment -> FlagAssignment #
Read FlagAssignment # | Since: Cabal-2.2.0
Instance details Defined in Distribution.Types.Flag Methods readsPrec :: Int -> ReadS FlagAssignment Source # readList :: ReadS [FlagAssignment] Source # readPrec :: ReadPrec FlagAssignment Source # readListPrec :: ReadPrec [FlagAssignment] Source #
Show FlagAssignment # | Since: Cabal-2.2.0
Instance details Defined in Distribution.Types.Flag Methods showsPrec :: Int -> FlagAssignment -> ShowS Source # show :: FlagAssignment -> String Source # showList :: [FlagAssignment] -> ShowS Source #
Generic FlagAssignment # |
Instance details Defined in Distribution.Types.Flag Associated Types type Rep FlagAssignment :: Type -> Type Source # Methods from :: FlagAssignment -> Rep FlagAssignment x Source # to :: Rep FlagAssignment x -> FlagAssignment Source #
Semigroup FlagAssignment # |
Instance details Defined in Distribution.Types.Flag Methods (<>) :: FlagAssignment -> FlagAssignment -> FlagAssignment Source # sconcat :: NonEmpty FlagAssignment -> FlagAssignment Source # stimes :: Integral b => b -> FlagAssignment -> FlagAssignment Source #
Monoid FlagAssignment # |
Instance details Defined in Distribution.Types.Flag Methods mempty :: FlagAssignment Source # mappend :: FlagAssignment -> FlagAssignment -> FlagAssignment Source # mconcat :: [FlagAssignment] -> FlagAssignment Source #
Binary FlagAssignment # |
Instance details Defined in Distribution.Types.Flag Methods put :: FlagAssignment -> Put Source # get :: Get FlagAssignment Source # putList :: [FlagAssignment] -> Put Source #
NFData FlagAssignment # |
Instance details Defined in Distribution.Types.Flag Methods rnf :: FlagAssignment -> () Source #
Structured FlagAssignment # |
Instance details Defined in Distribution.Types.Flag Methods structure :: Proxy FlagAssignment -> Structure Source # structureHash' :: Tagged FlagAssignment MD5
Pretty FlagAssignment # | Since: Cabal-3.4.0.0
Instance details Defined in Distribution.Types.Flag Methods pretty :: FlagAssignment -> Doc Source # prettyVersioned :: CabalSpecVersion -> FlagAssignment -> Doc Source #
Parsec FlagAssignment # |
    >>> simpleParsec "" :: Maybe FlagAssignment
    Just (fromList [])
    >>> simpleParsec "+foo -bar" :: Maybe FlagAssignment
    Just (fromList [(FlagName "bar",(1,False)),(FlagName "foo",(1,True))])
    >>> simpleParsec "-none -any" :: Maybe FlagAssignment
    Just (fromList [(FlagName "any",(1,False)),(FlagName "none",(1,False))])
    >>> simpleParsec "+foo -foo +foo +foo" :: Maybe FlagAssignment
    Just (fromList [(FlagName "foo",(4,True))])
    >>> simpleParsec "+foo -bar baz" :: Maybe FlagAssignment
    Nothing
Since: Cabal-3.4.0.0
Instance details Defined in Distribution.Types.Flag Methods parsec :: CabalParsing m => m FlagAssignment Source #
type Rep FlagAssignment # |
Instance details Defined in Distribution.Types.Flag type Rep FlagAssignment = D1 ('MetaData "FlagAssignment" "Distribution.Types.Flag" "Cabal-3.4.0.0" 'True) (C1 ('MetaCons "FlagAssignment" 'PrefixI 'True) (S1 ('MetaSel ('Just "getFlagAssignment") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Map FlagName (Int, Bool)))))

mkFlagAssignment :: [(FlagName, Bool)] -> FlagAssignment Source #

Construct a `FlagAssignment` from a list of flag/value pairs.

If duplicate flags occur in the input list, the later entries in the list will take precedence.

Since: Cabal-2.2.0

unFlagAssignment :: FlagAssignment -> [(FlagName, Bool)] Source #

Deconstruct a `FlagAssignment` into a list of flag/value pairs.

     null (findDuplicateFlagAssignments fa) ==> (mkFlagAssignment . unFlagAssignment) fa == fa

Since: Cabal-2.2.0

lookupFlagAssignment :: FlagName -> FlagAssignment -> Maybe Bool Source #

Lookup the value for a flag

Returns `Nothing` if the flag isn't contained in the `FlagAssignment`.

Since: Cabal-2.2.0

insertFlagAssignment :: FlagName -> Bool -> FlagAssignment -> FlagAssignment Source #

Insert or update the boolean value of a flag.

If the flag is already present in the `FlagAssigment`, the value will be updated and the fact that multiple values have been provided for that flag will be recorded so that a warning can be generated later on.

Since: Cabal-2.2.0

diffFlagAssignment :: FlagAssignment -> FlagAssignment -> FlagAssignment Source #

Remove all flag-assignments from the first `FlagAssignment` that are contained in the second `FlagAssignment`

NB/TODO: This currently only removes flag assignments which also match the value assignment! We should review the code which uses this operation to figure out if this it's not enough to only compare the flagnames without the values.

Since: Cabal-2.2.0

findDuplicateFlagAssignments :: FlagAssignment -> [FlagName] Source #

Find the `FlagName`s that have been listed more than once.

Since: Cabal-2.2.0

nullFlagAssignment :: FlagAssignment -> Bool Source #

Test whether `FlagAssignment` is empty.

Since: Cabal-2.2.0

showFlagValue :: (FlagName, Bool) -> String Source #

String representation of a flag-value pair.

dispFlagAssignment :: FlagAssignment -> Doc Source #

Pretty-prints a flag assignment.

showFlagAssignment :: FlagAssignment -> String Source #

Show flag assignment.

Since: Cabal-3.4.0.0

parsecFlagAssignment :: CabalParsing m => m FlagAssignment Source #

Parses a flag assignment.

parsecFlagAssignmentNonEmpty :: CabalParsing m => m FlagAssignment Source #

Parse a non-empty flag assignment

The flags have to explicitly start with minus or plus.

Since: Cabal-3.4.0.0

## Legacy formats

legacyShowFlagAssignment :: FlagAssignment -> String Source #

We need this as far as we support custom setups older than 2.2.0.0

Since: Cabal-3.4.0.0

legacyShowFlagAssignment' :: FlagAssignment -> [String] Source #

Since: Cabal-3.4.0.0

legacyParsecFlagAssignment :: CabalParsing m => m FlagAssignment Source #

We need this as far as we support custom setups older than 2.2.0.0

Since: Cabal-3.4.0.0