{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE DeriveDataTypeable #-}
module Distribution.Simple.Program.Types (
    
    Program(..),
    ProgramSearchPath,
    ProgramSearchPathEntry(..),
    simpleProgram,
    
    ConfiguredProgram(..),
    programPath,
    suppressOverrideArgs,
    ProgArg,
    ProgramLocation(..),
    simpleConfiguredProgram,
  ) where
import Prelude ()
import Distribution.Compat.Prelude
import Distribution.PackageDescription
import Distribution.Simple.Program.Find
import Distribution.Version
import Distribution.Verbosity
import qualified Data.Map as Map
data Program = Program {
       
       Program -> String
programName :: String,
       
       
       
       
       
       
       
       
       
       
       
       Program
-> Verbosity -> ProgramSearchPath -> IO (Maybe (String, [String]))
programFindLocation :: Verbosity -> ProgramSearchPath
                              -> IO (Maybe (FilePath, [FilePath])),
       
       
       Program -> Verbosity -> String -> IO (Maybe Version)
programFindVersion :: Verbosity -> FilePath -> IO (Maybe Version),
       
       
       
       Program -> Verbosity -> ConfiguredProgram -> IO ConfiguredProgram
programPostConf :: Verbosity -> ConfiguredProgram -> IO ConfiguredProgram,
       
       
       
       Program
-> Maybe Version -> PackageDescription -> [String] -> [String]
programNormaliseArgs :: Maybe Version -> PackageDescription -> [String] -> [String]
     }
instance Show Program where
  show :: Program -> String
show (Program String
name Verbosity -> ProgramSearchPath -> IO (Maybe (String, [String]))
_ Verbosity -> String -> IO (Maybe Version)
_ Verbosity -> ConfiguredProgram -> IO ConfiguredProgram
_ Maybe Version -> PackageDescription -> [String] -> [String]
_) = String
"Program: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
name
type ProgArg = String
data ConfiguredProgram = ConfiguredProgram {
       
       ConfiguredProgram -> String
programId :: String,
       
       ConfiguredProgram -> Maybe Version
programVersion :: Maybe Version,
       
       
       
       ConfiguredProgram -> [String]
programDefaultArgs :: [String],
       
       
       
       ConfiguredProgram -> [String]
programOverrideArgs :: [String],
       
       
       
       ConfiguredProgram -> [(String, Maybe String)]
programOverrideEnv :: [(String, Maybe String)],
       
       
       
       ConfiguredProgram -> Map String String
programProperties :: Map.Map String String,
       
       ConfiguredProgram -> ProgramLocation
programLocation :: ProgramLocation,
       
       
       
       
       
       
       ConfiguredProgram -> [String]
programMonitorFiles :: [FilePath]
     }
  deriving (ConfiguredProgram -> ConfiguredProgram -> Bool
(ConfiguredProgram -> ConfiguredProgram -> Bool)
-> (ConfiguredProgram -> ConfiguredProgram -> Bool)
-> Eq ConfiguredProgram
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ConfiguredProgram -> ConfiguredProgram -> Bool
$c/= :: ConfiguredProgram -> ConfiguredProgram -> Bool
== :: ConfiguredProgram -> ConfiguredProgram -> Bool
$c== :: ConfiguredProgram -> ConfiguredProgram -> Bool
Eq, (forall x. ConfiguredProgram -> Rep ConfiguredProgram x)
-> (forall x. Rep ConfiguredProgram x -> ConfiguredProgram)
-> Generic ConfiguredProgram
forall x. Rep ConfiguredProgram x -> ConfiguredProgram
forall x. ConfiguredProgram -> Rep ConfiguredProgram x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ConfiguredProgram x -> ConfiguredProgram
$cfrom :: forall x. ConfiguredProgram -> Rep ConfiguredProgram x
Generic, ReadPrec [ConfiguredProgram]
ReadPrec ConfiguredProgram
Int -> ReadS ConfiguredProgram
ReadS [ConfiguredProgram]
(Int -> ReadS ConfiguredProgram)
-> ReadS [ConfiguredProgram]
-> ReadPrec ConfiguredProgram
-> ReadPrec [ConfiguredProgram]
-> Read ConfiguredProgram
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ConfiguredProgram]
$creadListPrec :: ReadPrec [ConfiguredProgram]
readPrec :: ReadPrec ConfiguredProgram
$creadPrec :: ReadPrec ConfiguredProgram
readList :: ReadS [ConfiguredProgram]
$creadList :: ReadS [ConfiguredProgram]
readsPrec :: Int -> ReadS ConfiguredProgram
$creadsPrec :: Int -> ReadS ConfiguredProgram
Read, Int -> ConfiguredProgram -> ShowS
[ConfiguredProgram] -> ShowS
ConfiguredProgram -> String
(Int -> ConfiguredProgram -> ShowS)
-> (ConfiguredProgram -> String)
-> ([ConfiguredProgram] -> ShowS)
-> Show ConfiguredProgram
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ConfiguredProgram] -> ShowS
$cshowList :: [ConfiguredProgram] -> ShowS
show :: ConfiguredProgram -> String
$cshow :: ConfiguredProgram -> String
showsPrec :: Int -> ConfiguredProgram -> ShowS
$cshowsPrec :: Int -> ConfiguredProgram -> ShowS
Show, Typeable)
instance Binary ConfiguredProgram
instance Structured ConfiguredProgram
data ProgramLocation
    = UserSpecified { ProgramLocation -> String
locationPath :: FilePath }
      
      
    | FoundOnSystem { locationPath :: FilePath }
      
      deriving (ProgramLocation -> ProgramLocation -> Bool
(ProgramLocation -> ProgramLocation -> Bool)
-> (ProgramLocation -> ProgramLocation -> Bool)
-> Eq ProgramLocation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ProgramLocation -> ProgramLocation -> Bool
$c/= :: ProgramLocation -> ProgramLocation -> Bool
== :: ProgramLocation -> ProgramLocation -> Bool
$c== :: ProgramLocation -> ProgramLocation -> Bool
Eq, (forall x. ProgramLocation -> Rep ProgramLocation x)
-> (forall x. Rep ProgramLocation x -> ProgramLocation)
-> Generic ProgramLocation
forall x. Rep ProgramLocation x -> ProgramLocation
forall x. ProgramLocation -> Rep ProgramLocation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ProgramLocation x -> ProgramLocation
$cfrom :: forall x. ProgramLocation -> Rep ProgramLocation x
Generic, ReadPrec [ProgramLocation]
ReadPrec ProgramLocation
Int -> ReadS ProgramLocation
ReadS [ProgramLocation]
(Int -> ReadS ProgramLocation)
-> ReadS [ProgramLocation]
-> ReadPrec ProgramLocation
-> ReadPrec [ProgramLocation]
-> Read ProgramLocation
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ProgramLocation]
$creadListPrec :: ReadPrec [ProgramLocation]
readPrec :: ReadPrec ProgramLocation
$creadPrec :: ReadPrec ProgramLocation
readList :: ReadS [ProgramLocation]
$creadList :: ReadS [ProgramLocation]
readsPrec :: Int -> ReadS ProgramLocation
$creadsPrec :: Int -> ReadS ProgramLocation
Read, Int -> ProgramLocation -> ShowS
[ProgramLocation] -> ShowS
ProgramLocation -> String
(Int -> ProgramLocation -> ShowS)
-> (ProgramLocation -> String)
-> ([ProgramLocation] -> ShowS)
-> Show ProgramLocation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ProgramLocation] -> ShowS
$cshowList :: [ProgramLocation] -> ShowS
show :: ProgramLocation -> String
$cshow :: ProgramLocation -> String
showsPrec :: Int -> ProgramLocation -> ShowS
$cshowsPrec :: Int -> ProgramLocation -> ShowS
Show, Typeable)
instance Binary ProgramLocation
instance Structured ProgramLocation
programPath :: ConfiguredProgram -> FilePath
programPath :: ConfiguredProgram -> String
programPath = ProgramLocation -> String
locationPath (ProgramLocation -> String)
-> (ConfiguredProgram -> ProgramLocation)
-> ConfiguredProgram
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConfiguredProgram -> ProgramLocation
programLocation
suppressOverrideArgs :: ConfiguredProgram -> ConfiguredProgram
suppressOverrideArgs :: ConfiguredProgram -> ConfiguredProgram
suppressOverrideArgs ConfiguredProgram
prog = ConfiguredProgram
prog { programOverrideArgs :: [String]
programOverrideArgs = [] }
simpleProgram :: String -> Program
simpleProgram :: String -> Program
simpleProgram String
name = Program :: String
-> (Verbosity
    -> ProgramSearchPath -> IO (Maybe (String, [String])))
-> (Verbosity -> String -> IO (Maybe Version))
-> (Verbosity -> ConfiguredProgram -> IO ConfiguredProgram)
-> (Maybe Version -> PackageDescription -> [String] -> [String])
-> Program
Program {
    programName :: String
programName         = String
name,
    programFindLocation :: Verbosity -> ProgramSearchPath -> IO (Maybe (String, [String]))
programFindLocation = \Verbosity
v ProgramSearchPath
p -> Verbosity
-> ProgramSearchPath -> String -> IO (Maybe (String, [String]))
findProgramOnSearchPath Verbosity
v ProgramSearchPath
p String
name,
    programFindVersion :: Verbosity -> String -> IO (Maybe Version)
programFindVersion  = \Verbosity
_ String
_ -> Maybe Version -> IO (Maybe Version)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Version
forall a. Maybe a
Nothing,
    programPostConf :: Verbosity -> ConfiguredProgram -> IO ConfiguredProgram
programPostConf     = \Verbosity
_ ConfiguredProgram
p -> ConfiguredProgram -> IO ConfiguredProgram
forall (m :: * -> *) a. Monad m => a -> m a
return ConfiguredProgram
p,
    programNormaliseArgs :: Maybe Version -> PackageDescription -> [String] -> [String]
programNormaliseArgs   = \Maybe Version
_ PackageDescription
_ -> [String] -> [String]
forall a. a -> a
id
  }
simpleConfiguredProgram :: String -> ProgramLocation -> ConfiguredProgram
simpleConfiguredProgram :: String -> ProgramLocation -> ConfiguredProgram
simpleConfiguredProgram String
name ProgramLocation
loc = ConfiguredProgram :: String
-> Maybe Version
-> [String]
-> [String]
-> [(String, Maybe String)]
-> Map String String
-> ProgramLocation
-> [String]
-> ConfiguredProgram
ConfiguredProgram {
     programId :: String
programId           = String
name,
     programVersion :: Maybe Version
programVersion      = Maybe Version
forall a. Maybe a
Nothing,
     programDefaultArgs :: [String]
programDefaultArgs  = [],
     programOverrideArgs :: [String]
programOverrideArgs = [],
     programOverrideEnv :: [(String, Maybe String)]
programOverrideEnv  = [],
     programProperties :: Map String String
programProperties   = Map String String
forall k a. Map k a
Map.empty,
     programLocation :: ProgramLocation
programLocation     = ProgramLocation
loc,
     programMonitorFiles :: [String]
programMonitorFiles = [] 
  }