module Distribution.Simple.Program.Types (
Program(..),
ProgramSearchPath,
ProgramSearchPathEntry(..),
simpleProgram,
ConfiguredProgram(..),
programPath,
suppressOverrideArgs,
ProgArg,
ProgramLocation(..),
simpleConfiguredProgram,
) where
import Distribution.Simple.Program.Find
( ProgramSearchPath, ProgramSearchPathEntry(..)
, findProgramOnSearchPath )
import Distribution.Version
( Version )
import Distribution.Verbosity
( Verbosity )
data Program = Program {
programName :: String,
programFindLocation :: Verbosity -> ProgramSearchPath
-> IO (Maybe FilePath),
programFindVersion :: Verbosity -> FilePath -> IO (Maybe Version),
programPostConf :: Verbosity -> ConfiguredProgram -> IO ConfiguredProgram
}
type ProgArg = String
data ConfiguredProgram = ConfiguredProgram {
programId :: String,
programVersion :: Maybe Version,
programDefaultArgs :: [String],
programOverrideArgs :: [String],
programOverrideEnv :: [(String, Maybe String)],
programLocation :: ProgramLocation
} deriving (Read, Show, Eq)
data ProgramLocation
= UserSpecified { locationPath :: FilePath }
| FoundOnSystem { locationPath :: FilePath }
deriving (Read, Show, Eq)
programPath :: ConfiguredProgram -> FilePath
programPath = locationPath . programLocation
suppressOverrideArgs :: ConfiguredProgram -> ConfiguredProgram
suppressOverrideArgs prog = prog { programOverrideArgs = [] }
simpleProgram :: String -> Program
simpleProgram name = Program {
programName = name,
programFindLocation = \v p -> findProgramOnSearchPath v p name,
programFindVersion = \_ _ -> return Nothing,
programPostConf = \_ p -> return p
}
simpleConfiguredProgram :: String -> ProgramLocation -> ConfiguredProgram
simpleConfiguredProgram name loc = ConfiguredProgram {
programId = name,
programVersion = Nothing,
programDefaultArgs = [],
programOverrideArgs = [],
programOverrideEnv = [],
programLocation = loc
}