{-# LANGUAGE DeriveGeneric #-}
module Distribution.Solver.Types.ConstraintSource
    ( ConstraintSource(..)
    , showConstraintSource
    ) where

import Distribution.Solver.Compat.Prelude
import Prelude ()

-- | Source of a 'PackageConstraint'.
data ConstraintSource =

  -- | Main config file, which is ~/.cabal/config by default.
  ConstraintSourceMainConfig FilePath

  -- | Local cabal.project file
  | ConstraintSourceProjectConfig FilePath

  -- | User config file, which is ./cabal.config by default.
  | ConstraintSourceUserConfig FilePath

  -- | Flag specified on the command line.
  | ConstraintSourceCommandlineFlag

  -- | Target specified by the user, e.g., @cabal install package-0.1.0.0@
  -- implies @package==0.1.0.0@.
  | ConstraintSourceUserTarget

  -- | Internal requirement to use installed versions of packages like ghc-prim.
  | ConstraintSourceNonUpgradeablePackage

  -- | Internal constraint used by @cabal freeze@.
  | ConstraintSourceFreeze

  -- | Constraint specified by a config file, a command line flag, or a user
  -- target, when a more specific source is not known.
  | ConstraintSourceConfigFlagOrTarget

  -- | The source of the constraint is not specified.
  | ConstraintSourceUnknown

  -- | An internal constraint due to compatibility issues with the Setup.hs
  -- command line interface requires a minimum lower bound on Cabal
  | ConstraintSetupCabalMinVersion

  -- | An internal constraint due to compatibility issues with the Setup.hs
  -- command line interface requires a maximum upper bound on Cabal
  | ConstraintSetupCabalMaxVersion
  deriving (ConstraintSource -> ConstraintSource -> Bool
(ConstraintSource -> ConstraintSource -> Bool)
-> (ConstraintSource -> ConstraintSource -> Bool)
-> Eq ConstraintSource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ConstraintSource -> ConstraintSource -> Bool
== :: ConstraintSource -> ConstraintSource -> Bool
$c/= :: ConstraintSource -> ConstraintSource -> Bool
/= :: ConstraintSource -> ConstraintSource -> Bool
Eq, Int -> ConstraintSource -> ShowS
[ConstraintSource] -> ShowS
ConstraintSource -> FilePath
(Int -> ConstraintSource -> ShowS)
-> (ConstraintSource -> FilePath)
-> ([ConstraintSource] -> ShowS)
-> Show ConstraintSource
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ConstraintSource -> ShowS
showsPrec :: Int -> ConstraintSource -> ShowS
$cshow :: ConstraintSource -> FilePath
show :: ConstraintSource -> FilePath
$cshowList :: [ConstraintSource] -> ShowS
showList :: [ConstraintSource] -> ShowS
Show, (forall x. ConstraintSource -> Rep ConstraintSource x)
-> (forall x. Rep ConstraintSource x -> ConstraintSource)
-> Generic ConstraintSource
forall x. Rep ConstraintSource x -> ConstraintSource
forall x. ConstraintSource -> Rep ConstraintSource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ConstraintSource -> Rep ConstraintSource x
from :: forall x. ConstraintSource -> Rep ConstraintSource x
$cto :: forall x. Rep ConstraintSource x -> ConstraintSource
to :: forall x. Rep ConstraintSource x -> ConstraintSource
Generic)

instance Binary ConstraintSource
instance Structured ConstraintSource

-- | Description of a 'ConstraintSource'.
showConstraintSource :: ConstraintSource -> String
showConstraintSource :: ConstraintSource -> FilePath
showConstraintSource (ConstraintSourceMainConfig FilePath
path) =
    FilePath
"main config " FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
path
showConstraintSource (ConstraintSourceProjectConfig FilePath
path) =
    FilePath
"project config " FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
path
showConstraintSource (ConstraintSourceUserConfig FilePath
path)= FilePath
"user config " FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
path
showConstraintSource ConstraintSource
ConstraintSourceCommandlineFlag = FilePath
"command line flag"
showConstraintSource ConstraintSource
ConstraintSourceUserTarget = FilePath
"user target"
showConstraintSource ConstraintSource
ConstraintSourceNonUpgradeablePackage =
    FilePath
"non-upgradeable package"
showConstraintSource ConstraintSource
ConstraintSourceFreeze = FilePath
"cabal freeze"
showConstraintSource ConstraintSource
ConstraintSourceConfigFlagOrTarget =
    FilePath
"config file, command line flag, or user target"
showConstraintSource ConstraintSource
ConstraintSourceUnknown = FilePath
"unknown source"
showConstraintSource ConstraintSource
ConstraintSetupCabalMinVersion =
    FilePath
"minimum version of Cabal used by Setup.hs"
showConstraintSource ConstraintSource
ConstraintSetupCabalMaxVersion =
    FilePath
"maximum version of Cabal used by Setup.hs"